三.配置集合

2017-09-05  本文已影响0人  蜗牛1991
@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;
    }

}
上一篇下一篇

猜你喜欢

热点阅读