Shiro 필터 설정 (ShiroFilterFactory Bean)

5021 단어 shiro
이 블 로 그 는 shiro 필터 의 설정 과 주의사항 을 기록 하 는 것 입 니 다.
    /**
     * Shiro     
     */
    @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        // Shiro       ,        
        shiroFilter.setSecurityManager(securityManager());
//        shiroFilter.setLoginUrl("");//      ,                                      ,       ,              web        ”/login.jsp”  。
//        shiroFilter.setSuccessUrl("");//          ,       ”/”。                 ,                  。     。
//        shiroFilter.setUnauthorizedUrl("");//           
//        shiroFilter.setFilterChainDefinitions("");//filterChainDefinitions          ,       

        //     
        //oauth2
        Map filters = new HashMap<>(16);
        filters.put("oauth2", new Oauth2Filter());
        shiroFilter.setFilters(filters);

        //     Web     ,Shiro           Filter  ,     [main]                  Filter    DefaultFilter      ,                
        /**
         * anon---------------org.apache.shiro.web.filter.authc.AnonymousFilter     ,        。
         * authc--------------org.apache.shiro.web.filter.authc.FormAuthenticationFilter       (  )    ,    
         * authcBasic---------org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter       httpBasic  
         * logout-------------org.apache.shiro.web.filter.authc.LogoutFilter
         * noSessionCreation--org.apache.shiro.web.filter.session.NoSessionCreationFilter
         * perms--------------org.apache.shiro.web.filter.authz.PermissionAuthorizationFilter        ,         ,           ,  /admins/user/**=perms["user:add:*,user:modify:*"],                   ,   isPermitedAll()  。
         * port---------------org.apache.shiro.web.filter.authz.PortFilter port[8081],    url     8081    schemal://serverName:8081?queryString,  schmal   http https ,serverName     host,8081 url   port   ,queryString     url  ?     。
         * rest---------------org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter        ,   /admins/user/**=perms[user:method] ,  method post,get,delete 。
         * roles--------------org.apache.shiro.web.filter.authz.RolesAuthorizationFilter        ,         ,           ,       ,  admins/user/**=roles["admin,guest"],          ,   hasAllRoles()  。
         * ssl----------------org.apache.shiro.web.filter.authz.SslFilter     ,     url  ,   https
         * user---------------org.apache.shiro.web.filter.authz.UserFilter             ,          
         */

        /**
         *              
         * anon,authc,authcBasic,user         
         * perms,port,rest,roles,ssl         
         *   user authc  :      rememberMe ,            user,     authc,  authc        
         * user            ,    Shiro                   ,  rememberMe    ,             rememberMe,        ,           user,   authc
         *
         *
         *      
         *  /admin=authc,roles[admin]                 ,   admin         '/admin'  
         *  /edit=authc,perms[admin:edit]             ,   admin:edit         '/edit'  
         *  /home=user                    ,      Shiro              '/home'  
         */


        /**
         *           (  URL Pattern        ,              )
         * /admins/**=anon               ,       ,            
         *  /admins/user/**=authc         ,         
         *  /admins/user/**=authcBasic    ,  httpBasic  
         *  /admins/user/**=ssl           ,     URL  ,   https
         *  /admins/user/**=perms[user:add:*]        ,         ,          , /admins/user/**=perms["user:add:*,user:modify:*"]。                    ,   isPermitedAll()  
         *  /admins/user/**=port[8081]     URL    8081 ,   schemal://serverName:8081?queryString。  schmal   http https ,serverName     Host,8081 Port  ,queryString     URL  ?     
         *  /admins/user/**=rest[user]        ,   /admins/user/**=perms[user:method],  method post,get,delete 
         *  /admins/user/**=roles[admin]        ,         ,          , :/admins/user/**=roles["admin,guest"]。                    ,   hasAllRoles()  
         *
         */


        //Shiro  URL ,URL             (           URL  ,         )
        //                
        Map filterMap = new LinkedHashMap<>();
        filterMap.put("/favicon.ico", "anon");
        filterMap.put("/webjars/**", "anon");
        filterMap.put("/web/**", "anon");
        filterMap.put("/login", "anon");

        //      oauth2  
        filterMap.put("/**", "oauth2");
        shiroFilter.setFilterChainDefinitionMap(filterMap);
        return shiroFilter;
    }

spring 에서 shiro logout 설정 방식
1. 보통의 자신의 logout 방법 을 실현 하고 Subject 를 찾 은 다음 logout.
2. shiro 에서 제공 하 는 logout filter 사용

좋은 웹페이지 즐겨찾기