spring集成shiro的配置信息

2021-04-11 21:29

阅读:493

标签:访问   auth   ati   process   com   real   frame   enc   tar   

一.依赖的引入

dependency>
      groupId>org.apache.shirogroupId>
      artifactId>shiro-coreartifactId>
      version>1.3.2version>
      exclusions>
        exclusion>
          groupId>org.slf4jgroupId>
          artifactId>slf4j-apiartifactId>
        exclusion>
      exclusions>
    dependency>
    dependency>
      groupId>org.apache.shirogroupId>
      artifactId>shiro-webartifactId>
      version>1.3.2version>
    dependency>
    dependency>
      groupId>org.apache.shirogroupId>
      artifactId>shiro-springartifactId>
      version>1.3.2version>
    dependency>
    dependency>
      groupId>org.apache.shirogroupId>
      artifactId>shiro-ehcacheartifactId>
      version>1.3.2version>
    dependency>

二.spring的主配置文件中的配置

1.配置自定义realm,class指的是自定义realm的全限定名;

   
    bean id="jdbcRealm" class="com.woniu.ssm.realms.ShiroRealm">bean>

2.配置缓存,需要从shiro缓存包中导入类,property引用resources中的ehcache文件

 
    bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/>
    bean>

3.配置shiro核心,可以在里面配置各种属性(注意引用的自定义realm要实现父类方法,不然会报错)

    
    bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        property name="cacheManager" ref="cacheManager"/>
        property name="realm" ref="jdbcRealm"/>
        
    bean>

4.配置shro的生命周期

   
    bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
    
    bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
          depends-on="lifecycleBeanPostProcessor"/>
    bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        property name="securityManager" ref="securityManager"/>
    bean>

5.配置过滤器

 
    bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        property name="securityManager" ref="securityManager"/>
        property name="loginUrl" value="/jsp/login.jsp"/>
        property name="successUrl" value="/jsp/success.jsp"/>
        property name="unauthorizedUrl" value="/jsp/unauthorized.jsp"/>
        
        property name="filterChainDefinitions">
            value>
                
                /jsp/login.jsp = anon
                /user/login = anon
                
                
                
                
                
                
                
                
                
                /** = authc
            value>
        property>
    bean>

三.web.xml文件中设置过滤器

 
  filter>
    filter-name>shiroFilterfilter-name>
    filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>
    init-param>
      param-name>targetFilterLifecycleparam-name>
      param-value>trueparam-value>
    init-param>
    
  filter>


  filter-mapping>
    filter-name>shiroFilterfilter-name>
    url-pattern>/*url-pattern>
  filter-mapping>

 

spring集成shiro的配置信息

标签:访问   auth   ati   process   com   real   frame   enc   tar   

原文地址:https://www.cnblogs.com/yyk520/p/13358151.html


评论


亲,登录后才可以留言!