Search in sources :

Example 11 with ShiroFilterFactoryBean

use of org.apache.shiro.spring.web.ShiroFilterFactoryBean in project moon by gentoo111.

the class ShiroConfig method shirFilter.

@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    // 拦截器.
    Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
    filterChainDefinitionMap.put("/css/**", "anon");
    filterChainDefinitionMap.put("/fonts/**", "anon");
    filterChainDefinitionMap.put("/img/**", "anon");
    filterChainDefinitionMap.put("/js/**", "anon");
    filterChainDefinitionMap.put("/sys/login/**", "anon");
    filterChainDefinitionMap.put("/files/*", "anon");
    filterChainDefinitionMap.put("/logout", "logout");
    filterChainDefinitionMap.put("/**", "authc");
    shiroFilterFactoryBean.setLoginUrl("/login.html");
    shiroFilterFactoryBean.setSuccessUrl("/index.html");
    LogoutFilter logoutFilter = new LogoutFilter();
    logoutFilter.setRedirectUrl("/login.html");
    RestfulFilter restfulFilter = new RestfulFilter();
    shiroFilterFactoryBean.getFilters().put("authc", restfulFilter);
    shiroFilterFactoryBean.getFilters().put("logout", logoutFilter);
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
Also used : ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) LogoutFilter(com.moon.admin.common.filter.LogoutFilter) LinkedHashMap(java.util.LinkedHashMap) RestfulFilter(com.moon.admin.common.filter.RestfulFilter) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with ShiroFilterFactoryBean

use of org.apache.shiro.spring.web.ShiroFilterFactoryBean in project spring-boot-examples by ityouknow.

the class ShiroConfig method shirFilter.

@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    System.out.println("ShiroConfiguration.shirFilter()");
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    // 拦截器.
    Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
    // 配置不会被拦截的链接 顺序判断
    filterChainDefinitionMap.put("/static/**", "anon");
    // 配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了
    filterChainDefinitionMap.put("/logout", "logout");
    // <!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
    // <!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
    filterChainDefinitionMap.put("/**", "authc");
    // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
    shiroFilterFactoryBean.setLoginUrl("/login");
    // 登录成功后要跳转的链接
    shiroFilterFactoryBean.setSuccessUrl("/index");
    // 未授权界面;
    shiroFilterFactoryBean.setUnauthorizedUrl("/403");
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
Also used : ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) LinkedHashMap(java.util.LinkedHashMap) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)12 Bean (org.springframework.context.annotation.Bean)10 LinkedHashMap (java.util.LinkedHashMap)8 Filter (javax.servlet.Filter)2 KickoutSessionFilter (com.cdeledu.core.shiro.filter.KickoutSessionFilter)1 LoginFilter (com.cdeledu.core.shiro.filter.LoginFilter)1 PermissionFilter (com.cdeledu.core.shiro.filter.PermissionFilter)1 RoleFilter (com.cdeledu.core.shiro.filter.RoleFilter)1 UserSessionFilter (com.cdeledu.core.shiro.filter.UserSessionFilter)1 LogoutFilter (com.moon.admin.common.filter.LogoutFilter)1 RestfulFilter (com.moon.admin.common.filter.RestfulFilter)1 HashMap (java.util.HashMap)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 MethodInvokingFactoryBean (org.springframework.beans.factory.config.MethodInvokingFactoryBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 EhCacheManagerFactoryBean (org.springframework.cache.ehcache.EhCacheManagerFactoryBean)1