shiro在springmvc里面的集成使用【转】

为什么80%的码农都做不了架构师?>>>   hot3.png

  1.   
  2.          commons-collections  
  3.          commons-collections  
  4.          3.2.1  
  5.        
  6.   
  7.        
  8.          net.sf.ehcache  
  9.          ehcache-core  
  10.          2.6.9  
  11.        
  12.   
  13.        
  14.          org.apache.shiro  
  15.          shiro-spring  
  16.          1.2.3  
  17.        
  18.   
  19.        
  20.          org.apache.shiro  
  21.          shiro-ehcache  
  22.          1.2.3  
  23.        
  24.   
  25.        
  26.          org.apache.shiro  
  27.          shiro-quartz  
  28.          1.2.3  
  29.        

 

如果项目是hibernate的,以前的时候ehcache可能不是单例的,因为shiro里面也使用到了ehcache做缓存,和hibernate的ehcache缓存配置有冲突,所以需要对hibernate的ehcache部分做些调整,调整如下:

 

Xml代码  收藏代码

  1.          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
  2.          
  3.          
  4.              
  5.                org.hibernate.dialect.MySQLDialect  
  6.                true  
  7.                update  
  8.                  
  9.                  
  10.                    org.hibernate.cache.SingletonEhCacheRegionFactory  
  11.                  
  12.                net.sf.ehcache.hibernate.SingletonEhCacheProvider  
  13.                true  
  14.                true  
  15.                true  
  16.                WEB-INF/classes/ehcache.xml  
  17.                org.springframework.orm.hibernate4.SpringSessionContext  
  18.              
  19.          
  20.          
  21.              
  22.                com.xxx.entity  
  23.              
  24.          
  25.      

 

上面红色的文字部分是需要调整的内容。

 

 

既然用到了ehcache,ehcahce.xml文件里面的配置内容如下:

 

Xml代码  收藏代码

  1.   
  2.   
  3.       
  4.   
  5.     
  6.                   timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />  
  7.     
  8.            maxElementsInMemory="5000" eternal="true" overflowToDisk="true" />  
  9.     
  10.            maxElementsInMemory="10000" eternal="false" timeToLiveSeconds="120"  
  11.            overflowToDisk="true" />  
  12.       
  13.     
  14.            maxEntriesLocalHeap="2000"  
  15.            eternal="false"  
  16.            timeToIdleSeconds="3600"  
  17.            timeToLiveSeconds="0"  
  18.            overflowToDisk="false"  
  19.            statistics="true">  
  20.       
  21.   
  22.     
  23.            maxEntriesLocalHeap="2000"  
  24.            eternal="false"  
  25.            timeToIdleSeconds="3600"  
  26.            timeToLiveSeconds="0"  
  27.            overflowToDisk="false"  
  28.            statistics="true">  
  29.       
  30.   
  31.     
  32.            maxEntriesLocalHeap="2000"  
  33.            eternal="false"  
  34.            timeToIdleSeconds="3600"  
  35.            timeToLiveSeconds="0"  
  36.            overflowToDisk="false"  
  37.            statistics="true">  
  38.       
  39.   
  40.     
  41.            maxEntriesLocalHeap="2000"  
  42.            eternal="false"  
  43.            timeToIdleSeconds="3600"  
  44.            timeToLiveSeconds="0"  
  45.            overflowToDisk="false"  
  46.            statistics="true">  
  47.       
  48.   

 

 

然后是web.xml文件里面加过滤器,注意要写在springmvc的filter前面

 

Xml代码  收藏代码

  1.   
  2.   
  3.   
  4.     shiroFilter  
  5.     org.springframework.web.filter.DelegatingFilterProxy  
  6.     true  
  7.       
  8.         targetFilterLifecycle  
  9.         true  
  10.       
  11.   
  12.   
  13.   
  14.   
  15.   
  16.   
  17.     shiroFilter  
  18.     /*  
  19.   

 

 

然后就是shiro相关的spring配置参数文件了

Xml代码  收藏代码

  1.   
  2.        xmlns:util="http://www.springframework.org/schema/util"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xsi:schemaLocation="  
  5.        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">  
  7.   
  8.       
  9.       
  10.           
  11.       
  12.   
  13.       
  14.       
  15.   
  16.       
  17.     
  18.           class="com.shinowit.framework.security.credentials.RetryLimitSimpleCredentialsMatcher">  
  19.           
  20.           
  21.       
  22.   
  23.   
  24.       
  25.           
  26.       
  27.   
  28.       
  29.       
  30.           
  31.           
  32.           
  33.           
  34.           
  35.           
  36.           
  37.           
  38.       
  39.   
  40.       
  41.       
  42.   
  43.       
  44.       
  45.           
  46.           
  47.           
  48.       
  49.   
  50.       
  51.           
  52.           
  53.           
  54.           
  55.       
  56.   
  57.       
  58.       
  59.         
  60.                   value="#{T(org.apache.shiro.codec.Base64).decode('4AvVhmFLUs0KTA3Kprsdag==')}"/>  
  61.           
  62.       
  63.   
  64.       
  65.       
  66.           
  67.           
  68.       
  69.   
  70.       
  71.       
  72.           
  73.           
  74.       
  75.   
  76.       
  77.       
  78.           
  79.           
  80.           
  81.           
  82.           
  83.           
  84.           
  85.       
  86.   
  87.       
  88.       
  89.           
  90.           
  91.           
  92.           
  93.       
  94.   
  95.       
  96.       
  97.           
  98.           
  99.       
  100.   
  101.       
  102.       
  103.   
  104.       
  105.       
  106.           
  107.           
  108.           
  109.           
  110.               
  111.                   
  112.                       
  113.                   
  114.               
  115.               
  116.           
  117.           
  118.               
  119.                 /index.jsp = anon  
  120.                 /validcode.jsp = anon  
  121.                 /login/ = anon  
  122.                 /static/** = anon  
  123.                 /js/** = anon  
  124.                 /img/** = anon  
  125.                 /unauthorized.jsp = anon  
  126.                 #/login/checklogin = authc  
  127.                 /login/checklogin = anon  
  128.                 /login/logoutlogout = logout  
  129.                 /** = user  
  130.               
  131.           
  132.       
  133.   
  134.       
  135.       
  136.   
  137.   
  138.   

 哦,对了,里面那个fuck那个url是用来改密码的,因为数据库里面的密码是加密的,不这么整总也不可能知道对的md5值是多少。

 

但愿没有忘记什么内容,挺墨迹的,不过能跑起来以后后边关于权限和安全的处理就简单多了,写写注解或者标签就搞定了,很爽。

 

核心技术:Maven,Springmvc mybatis shiro, Druid, Restful, 

Dubbo, ZooKeeper,Redis,FastDFS,ActiveMQ,Nginx 
1.     项目核心代码结构截图

shiro在springmvc里面的集成使用【转】_第1张图片

   项目模块依赖

shiro在springmvc里面的集成使用【转】_第2张图片

 

特别提醒:开发人员在开发的时候可以将自己的业务REST服务化或者Dubbo服务化

2.    项目依赖介绍

   2.1 后台管理系统、Rest服务系统、Scheculer定时调度系统依赖如下图:

 

shiro在springmvc里面的集成使用【转】_第3张图片

       2.2 Dubbo独立服务项目依赖如下图:

 shiro在springmvc里面的集成使用【转】_第4张图片

3.  项目功能部分截图:

shiro在springmvc里面的集成使用【转】_第5张图片

 

shiro在springmvc里面的集成使用【转】_第6张图片

 

shiro在springmvc里面的集成使用【转】_第7张图片

 

shiro在springmvc里面的集成使用【转】_第8张图片

 

shiro在springmvc里面的集成使用【转】_第9张图片

 

shiro在springmvc里面的集成使用【转】_第10张图片

 

shiro在springmvc里面的集成使用【转】_第11张图片
 

zookeeper、dubbo服务启动 

shiro在springmvc里面的集成使用【转】_第12张图片

shiro在springmvc里面的集成使用【转】_第13张图片

dubbo管台 

shiro在springmvc里面的集成使用【转】_第14张图片

shiro在springmvc里面的集成使用【转】_第15张图片

 

shiro在springmvc里面的集成使用【转】_第16张图片

 

shiro在springmvc里面的集成使用【转】_第17张图片

 

shiro在springmvc里面的集成使用【转】_第18张图片

 

shiro在springmvc里面的集成使用【转】_第19张图片

 

shiro在springmvc里面的集成使用【转】_第20张图片

 REST服务平台

shiro在springmvc里面的集成使用【转】_第21张图片

 

shiro在springmvc里面的集成使用【转】_第22张图片

 

shiro在springmvc里面的集成使用【转】_第23张图片

 

shiro在springmvc里面的集成使用【转】_第24张图片

转载于:https://my.oschina.net/grthrj/blog/751350

你可能感兴趣的:(java,大数据,运维)