Example #1
0
  @Bean
  public ShiroFilterFactoryBean shiroFilter() throws Exception {
    logger.debug("create shiro filter.");
    Map<String, Filter> filters = new HashMap<>();
    filters.put("authc", new CaptchaFormAuthenticationFilter());

    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setLoginUrl("/login");
    shiroFilterFactoryBean.setSuccessUrl("/home");
    shiroFilterFactoryBean.setUnauthorizedUrl("/unauthorized");
    shiroFilterFactoryBean.setFilters(filters);
    shiroFilterFactoryBean.setSecurityManager(securityManager());
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionSource().getObject());
    return shiroFilterFactoryBean;
  }
Example #2
0
 @Bean
 public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
   ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
   shiroFilterFactoryBean.setSecurityManager(securityManager);
   shiroFilterFactoryBean.setLoginUrl("/admin/login.html");
   shiroFilterFactoryBean.setSuccessUrl("/admin/home.html");
   shiroFilterFactoryBean.setUnauthorizedUrl("/admin/login.html");
   Map<String, Filter> filterMap = new HashMap<String, Filter>();
   filterMap.put("fromFilter", new FormAuthenticationFilter());
   shiroFilterFactoryBean.setFilters(filterMap);
   Map<String, String> filterChainDefinitionMap = new HashMap<String, String>();
   filterChainDefinitionMap.put("/admin/logout.html", "logout");
   filterChainDefinitionMap.put("/**", "fromFilter");
   shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
   return shiroFilterFactoryBean;
 }
 /** shiro的Web过滤器 */
 @Bean(name = "shiroFilter")
 public ShiroFilterFactoryBean getShiroFilterFactoryBean() {
   ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
   shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
   Map<String, String> filterChainDefinitionMap = Maps.newLinkedHashMap();
   shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
   shiroFilterFactoryBean.setLoginUrl("/login");
   shiroFilterFactoryBean.setSuccessUrl("/index");
   shiroFilterFactoryBean.setUnauthorizedUrl("/forbidden");
   filterChainDefinitionMap.put("/login", "authentication");
   filterChainDefinitionMap.put("/logout", "anon");
   filterChainDefinitionMap.put("/static/**", "anon");
   filterChainDefinitionMap.put("/**", "authentication");
   Map<String, Filter> filterMap = Maps.newHashMapWithExpectedSize(1);
   filterMap.put("authentication", getAuthenticationFilter());
   shiroFilterFactoryBean.setFilters(filterMap);
   return shiroFilterFactoryBean;
 }
 @Bean(name = "shiroFilter")
 public ShiroFilterFactoryBean shiroFilter() {
   ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
   shiroFilter.setLoginUrl("/login");
   shiroFilter.setSuccessUrl("/index");
   shiroFilter.setUnauthorizedUrl("/forbidden");
   Map<String, String> filterChainDefinitionMapping = new HashMap<String, String>();
   filterChainDefinitionMapping.put("/", "anon");
   filterChainDefinitionMapping.put("/home", "authc,roles[guest]");
   filterChainDefinitionMapping.put("/admin", "authc,roles[admin]");
   filterChainDefinitionMapping.put("/**", "securityFilter");
   shiroFilter.setFilterChainDefinitionMap(filterChainDefinitionMapping);
   shiroFilter.setSecurityManager(securityManager());
   Map<String, Filter> filters = new HashMap<String, Filter>();
   filters.put("anon", new AnonymousFilter());
   filters.put("authc", new FormAuthenticationFilter());
   filters.put("logout", new LogoutFilter());
   filters.put("roles", new RolesAuthorizationFilter());
   filters.put("user", new UserFilter());
   filters.put("securityFilter", new ShiroSecurityFilter());
   shiroFilter.setFilters(filters);
   System.out.println(shiroFilter.getFilters().size());
   return shiroFilter;
 }