美文网首页
三.配置集合

三.配置集合

作者: 蜗牛1991 | 来源:发表于2017-09-05 18:43 被阅读0次
@Configurationpublic class ShiroConfigurer {
    /**
     * 配置shiroFilter
     *
     * @param securityManager
     * @return
     */
    //配置主类
    @Bean
    public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        //设置不需验证url
        filterFactoryBean.setLoginUrl("/login");
        filterFactoryBean.setUnauthorizedUrl("/login");

        Map<String, Filter> filtersMap = new LinkedHashMap();
        filtersMap.put("cookie", cookieSsoFilter()); 
        shiroFilterFactoryBean.setFilters(filtersMap);
        Map<String, String> filterChainDefinitionMap = new LinkedHashMap();
        //设置拦截链,定义url访问权限
        filterChainDefinitionMap.put("/**", "cookie,session");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
        return shiroFilterFactoryBean;
    }
   //添加自定义拦截器
    @Bean(name = "cookie")
    public CookieSsoFilter cookieSsoFilter() {
        CookieSsoFilter cookieSsoFilter = new CookieSsoFilter();
        return cookieSsoFilter;
    }
   //配置securityManager
    @Bean
    public SecurityManager securityManager() {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(myShiroRealm() );
        securityManager.setSessionManager(sessionManager() );
        return securityManager;
    }
   //配置SessionManager
   @Bean
    public SessionManager sessionManager() {
        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
        sessionManager.setGlobalSessionTimeout(86400000L);//24小时
        sessionManager.setSessionDAO(sessionDAO);
        return sessionManager;
    }
    /配置sessionDAO
    @Bean
    public SessionDAO sessionDAO() {
       SessionDAO sessionDAO = new SessionDAO();
        return sessionDAO;
    }

}

相关文章

网友评论

      本文标题:三.配置集合

      本文链接:https://www.haomeiwen.com/subject/xskpjxtx.html