Java Code Examples for org.apache.shiro.spring.web.ShiroFilterFactoryBean#setSuccessUrl()

The following examples show how to use org.apache.shiro.spring.web.ShiroFilterFactoryBean#setSuccessUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShiroConfig.java    From Spring-Boot-Book with Apache License 2.0 6 votes vote down vote up
@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    //shirFilter
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    //拦截器.
    Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
    // 配置不需要权限的资源
    filterChainDefinitionMap.put("/static/**", "anon");
    filterChainDefinitionMap.put("/index", "anon");
    //配置退出过滤器,退出代码Shiro已经替我们实现
    filterChainDefinitionMap.put("/logout", "logout");
    //过滤链定义,从上向下顺序执行,/**放在最下边;
    //<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
    filterChainDefinitionMap.put("/**", "authc");
    // 如果不设置默认会自动寻找Web工程根目录下的"/login"页面
    shiroFilterFactoryBean.setLoginUrl("/login");
    // 登录成功后要跳转的链接
    shiroFilterFactoryBean.setSuccessUrl("/index");
    //未授权界面;
    shiroFilterFactoryBean.setUnauthorizedUrl("/403");
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
 
Example 2
Source File: ShiroConfig.java    From OneBlog with GNU General Public License v3.0 6 votes vote down vote up
/**
 * ShiroFilterFactoryBean 处理拦截资源文件问题。
 * 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
 * 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager
 * Filter Chain定义说明
 * 1、一个URL可以配置多个Filter,使用逗号分隔
 * 2、当设置多个过滤器时,全部验证通过,才视为通过
 * 3、部分过滤器可指定参数,如perms,roles
 */
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    // 必须设置 SecurityManager
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
    shiroFilterFactoryBean.setLoginUrl(shiroProperties.getLoginUrl());
    // 登录成功后要跳转的链接
    shiroFilterFactoryBean.setSuccessUrl(shiroProperties.getSuccessUrl());
    // 未授权界面;
    shiroFilterFactoryBean.setUnauthorizedUrl(shiroProperties.getUnauthorizedUrl());
    // 配置数据库中的resource
    Map<String, String> filterChainDefinitionMap = shiroService.loadFilterChainDefinitions();
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
 
Example 3
Source File: ShiroConfig.java    From EasyReport with Apache License 2.0 6 votes vote down vote up
@Bean
public ShiroFilterFactoryBean shiroFilter() {
    final ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(securityManager());
    shiroFilterFactoryBean.setLoginUrl("/member/login");
    shiroFilterFactoryBean.setSuccessUrl("/home/index");
    shiroFilterFactoryBean.setUnauthorizedUrl("/error/401");

    final Map<String, Filter> filters = Maps.newHashMap();
    filters.put("authc", this.authcFilter());
    filters.put("membership", this.membershipFilter());
    shiroFilterFactoryBean.setFilters(filters);

    final Map<String, String> chains = Maps.newLinkedHashMap();
    chains.put("/member/logout", "logout");
    chains.put("/", this.configProperties.getShiro().getFilters());
    chains.put("/home/**", this.configProperties.getShiro().getFilters());
    chains.put("/views/**", this.configProperties.getShiro().getFilters());
    chains.put("/rest/**", this.configProperties.getShiro().getFilters());
    chains.put("/**", "anon");
    shiroFilterFactoryBean.setFilterChainDefinitionMap(chains);

    return shiroFilterFactoryBean;
}
 
Example 4
Source File: ShiroConfiguration.java    From easyweb with Apache License 2.0 6 votes vote down vote up
@Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean getShiroFilterFactoryBean(
            DefaultWebSecurityManager securityManager,
            FormAuthenticationFilter formAuthenticationFilter) {

        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        // 必须设置 SecurityManager
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
        shiroFilterFactoryBean.setLoginUrl("/oss/login");
        // 登录成功后要跳转的连接
        shiroFilterFactoryBean.setSuccessUrl("/admin/index");
        shiroFilterFactoryBean.setUnauthorizedUrl("/403");
        Map map = new HashMap<>();
//        map.put("authc",formAuthenticationFilter);
        shiroFilterFactoryBean.setFilters(map);
        loadShiroFilterChain(shiroFilterFactoryBean);
        return shiroFilterFactoryBean;
    }
 
Example 5
Source File: ShiroCasWebFilterConfiguration.java    From shiro-cas-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Bean
  @Override
  protected ShiroFilterFactoryBean shiroFilterFactoryBean() {

ShiroFilterFactoryBean filterFactoryBean = new ShiroCasFilterFactoryBean();
      
      //登录地址:会话不存在时访问的地址
		filterFactoryBean.setLoginUrl(CasUrlUtils.constructLoginRedirectUrl(casProperties, serverProperties.getServlet().getContextPath(), casProperties.getServerCallbackUrl()));
		//系统主页:登录成功后跳转路径
		filterFactoryBean.setSuccessUrl(bizProperties.getSuccessUrl());
		//异常页面:无权限时的跳转路径
		filterFactoryBean.setUnauthorizedUrl(bizProperties.getUnauthorizedUrl());
    
		//必须设置 SecurityManager
	filterFactoryBean.setSecurityManager(securityManager);
	//拦截规则
	filterFactoryBean.setFilterChainDefinitionMap(shiroFilterChainDefinition.getFilterChainMap());
    
	return filterFactoryBean;
      
  }
 
Example 6
Source File: ShiroConfig.java    From springboot-shiro with MIT License 6 votes vote down vote up
/**
 * ShiroFilterFactoryBean 处理拦截资源文件问题。
 * 注意:单独一个ShiroFilterFactoryBean配置是或报错的,因为在
 * 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager
 * Filter Chain定义说明
 * 1、一个URL可以配置多个Filter,使用逗号分隔
 * 2、当设置多个过滤器时,全部验证通过,才视为通过
 * 3、部分过滤器可指定参数,如perms,roles
 */
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    // 必须设置 SecurityManager
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
    shiroFilterFactoryBean.setLoginUrl("/passport/login/");
    // 登录成功后要跳转的链接
    shiroFilterFactoryBean.setSuccessUrl("/index");
    // 未授权界面;
    shiroFilterFactoryBean.setUnauthorizedUrl("/error/403");
    // 配置数据库中的resource
    Map<String, String> filterChainDefinitionMap = shiroService.loadFilterChainDefinitions();
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
 
Example 7
Source File: ShiroConfig.java    From learnjavabug with MIT License 6 votes vote down vote up
@Bean
ShiroFilterFactoryBean shiroFilterFactoryBean() {
    ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
    bean.setSecurityManager(securityManager());
    bean.setLoginUrl("/login");
    bean.setSuccessUrl("/index");
    bean.setUnauthorizedUrl("/unauthorizedurl");
    Map<String, String> map = new LinkedHashMap();
    map.put("/login", "anon");
    map.put("/aaaaa/**", "anon");
    map.put("/bypass", "authc");
    map.put("/bypass.*", "authc");
    map.put("/bypass/**", "authc");
    map.put("/**", "authc");
    bean.setFilterChainDefinitionMap(map);
    return bean;
}
 
Example 8
Source File: ShiroConfiguration.java    From spring-boot-quickstart with Apache License 2.0 6 votes vote down vote up
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean
            .setSecurityManager(securityManager);
    shiroFilterFactoryBean.setLoginUrl("/login");
    shiroFilterFactoryBean.setSuccessUrl("/");
    filterChainDefinitionMap.put("/login", "authc");
    filterChainDefinitionMap.put("/logout", "logout");
    filterChainDefinitionMap.put("/static/**", "anon");
    filterChainDefinitionMap.put("/api/**", "anon");
    filterChainDefinitionMap.put("/register/**", "anon");
    filterChainDefinitionMap.put("/admin/**", "roles[admin]");
    filterChainDefinitionMap.put("/**", "user");

    shiroFilterFactoryBean
            .setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}
 
Example 9
Source File: ShiroConfig.java    From dts-shop with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
	ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
	shiroFilterFactoryBean.setSecurityManager(securityManager);
	Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
	filterChainDefinitionMap.put("/admin/auth/login", "anon");
	filterChainDefinitionMap.put("/admin/auth/401", "anon");
	filterChainDefinitionMap.put("/admin/auth/index", "anon");
	filterChainDefinitionMap.put("/admin/auth/403", "anon");

	filterChainDefinitionMap.put("/admin/**", "authc");
	shiroFilterFactoryBean.setLoginUrl("/admin/auth/401");
	shiroFilterFactoryBean.setSuccessUrl("/admin/auth/index");
	shiroFilterFactoryBean.setUnauthorizedUrl("/admin/auth/403");
	shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
	return shiroFilterFactoryBean;
}
 
Example 10
Source File: ShiroConfig.java    From fastdep with Apache License 2.0 5 votes vote down vote up
/**
 * shiroFilter
 *
 * @param securityManager securityManager bean
 * @param jwtUtil         jwt util bean
 * @return shiroFilter
 */
@Bean("shiroFilter")
@ConditionalOnMissingBean(ShiroFilter.class)
public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager, JwtUtil jwtUtil) {
    FastDepShiroJwtProperties fastDepShiroJwtProperties = jwtUtil.fastDepShiroJwtProperties;
    ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
    // define your filter and name it as jwt
    Map<String, Filter> filterMap = new HashMap<>(1);
    filterMap.put("jwt", new JwtFilter(jwtUtil));
    factoryBean.setFilters(filterMap);
    factoryBean.setSecurityManager(securityManager);
    /*
     * difine custom URL rule
     * http://shiro.apache.org/web.html#urls-
     */
    Map<String, FastDepShiroJwtProperties.ShiroRole> filter = fastDepShiroJwtProperties.getFilter();
    if (filter.size() > 0) {
        LinkedHashMap<String, String> filterRuleMap = filter.values().stream().
                collect(Collectors.toMap(FastDepShiroJwtProperties.ShiroRole::getPath,
                        FastDepShiroJwtProperties.ShiroRole::getRole, (key1, key2) -> key2, LinkedHashMap::new));
        // 401 and 404 page does not forward to our filter
        factoryBean.setFilterChainDefinitionMap(filterRuleMap);
    }
    if (fastDepShiroJwtProperties.getFilterChainDefinitions() != null) {
        factoryBean.setFilterChainDefinitions(fastDepShiroJwtProperties.getFilterChainDefinitions());
    }
    factoryBean.setLoginUrl(fastDepShiroJwtProperties.getLoginUrl());
    factoryBean.setSuccessUrl(fastDepShiroJwtProperties.getSuccessUrl());
    factoryBean.setUnauthorizedUrl(fastDepShiroJwtProperties.getUnauthorizedUrl());
    jwtUtil.fastDepShiroJwtAuthorization.shiroFilterFactoryBean(factoryBean);
    return factoryBean;
}
 
Example 11
Source File: ShiroConfig.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager){
	ShiroFilterFactoryBean factoryBean = new MyShiroFilterFactoryBean();
	factoryBean.setSecurityManager(securityManager);
	factoryBean.setLoginUrl("/restlogin");
	factoryBean.setSuccessUrl("/user");
	factoryBean.setUnauthorizedUrl("/403");

	loadShiroFilterChain(factoryBean);
	return factoryBean;
}
 
Example 12
Source File: ShiroConfig.java    From learnjavabug with MIT License 5 votes vote down vote up
@Bean
ShiroFilterFactoryBean shiroFilterFactoryBean() {
    ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
    bean.setSecurityManager(securityManager());
    bean.setLoginUrl("/login");
    bean.setSuccessUrl("/index");
    bean.setUnauthorizedUrl("/unauthorizedurl");
    Map<String, String> map = new LinkedHashMap();
    map.put("/login", "anon");
    map.put("/bypass", "authc");
    bean.setFilterChainDefinitionMap(map);
    return bean;
}
 
Example 13
Source File: ShiroAuthConfig.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Bean("shiroFilter")
public ShiroFilterFactoryBean factory(@Qualifier("securityManager") SecurityManager securityManager) {
    ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
    // 添加自己的过滤器并且取名为jwt
    Map<String, Filter> filterMap = new HashMap<>();

    // 必须设置 SecurityManager
    factoryBean.setSecurityManager(securityManager);
    //设置我们自定义的JWT过滤器
    filterMap.put("jwt", new JwtFilter());
    filterMap.put("resourceCheckFilter", new ResourceCheckFilter());
    factoryBean.setLoginUrl("/admin/login");
    factoryBean.setSuccessUrl("/index");
    factoryBean.setFilters(filterMap);
    // 设置无权限时跳转的 url;
    factoryBean.setUnauthorizedUrl("/403");
    LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
    // 访问 /unauthorized/** 不通过JWTFilter
    filterChainDefinitionMap.put("/favicon.ico", "anon");
    filterChainDefinitionMap.put("/css/**", "anon");
    filterChainDefinitionMap.put("/js/**", "anon");
    filterChainDefinitionMap.put("/media/**", "anon");
    filterChainDefinitionMap.put("/", "anon");
    // 所有请求通过我们自己的JWT Filter
    filterChainDefinitionMap.put("/**", "jwt");
    factoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return factoryBean;
}
 
Example 14
Source File: ShiroAutoConfiguration.java    From shiro-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean(name = "shiroFilter")
@DependsOn("securityManager")
@ConditionalOnMissingBean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultSecurityManager securityManager, Realm realm) {
	securityManager.setRealm(realm);

	ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
	shiroFilter.setSecurityManager(securityManager);
	shiroFilter.setLoginUrl(properties.getLoginUrl());
	shiroFilter.setSuccessUrl(properties.getSuccessUrl());
	shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl());
	shiroFilter.setFilterChainDefinitionMap(properties.getFilterChainDefinitionMap());
	return shiroFilter;
}
 
Example 15
Source File: ShiroConfig.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
    log.info("Shiro过滤器开始处理");
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(securityManager);

    // 配置登录页
    shiroFilterFactoryBean.setLoginUrl("/login");
    // 登录成功后跳转页面
    shiroFilterFactoryBean.setSuccessUrl("/index");
    //未授权界面
    shiroFilterFactoryBean.setUnauthorizedUrl("/403");

    //拦截器
    Map<String, String> filterMap = new LinkedHashMap<>();

    //anon:所有url都都可以匿名访问
    Set<String> urlSet = new HashSet<>(ignoreAuthUrlProperties.getIgnoreAuthUrl());
    urlSet.stream().forEach(temp -> filterMap.put(temp, "anon"));

    //用户未登录不进行跳转,返回错误信息
    Map<String, Filter> filters = shiroFilterFactoryBean.getFilters();
    filters.put("authc", new MyFormAuthenticationFilter());

    //配置退出 过滤器
    filterMap.put("/logout", "logout");

    //authc:所有url都必须认证通过才可以访问
    filterMap.put("/**", "authc");

    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterMap);
    return shiroFilterFactoryBean;
}
 
Example 16
Source File: ShiroConfiguration.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean() {
    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
    shiroFilterFactoryBean.setLoginUrl("/login.html");
    shiroFilterFactoryBean.setSuccessUrl("/home.html");
    shiroFilterFactoryBean.setUnauthorizedUrl("/403.html");

    filterChainDefinitionMap.put("/login.html", "anon");
    filterChainDefinitionMap.put("/v1/api0/image/captcha", "anon"); // 匿名用户可访问
    filterChainDefinitionMap.put("/view/**", "perms");                  // Url权限过滤
    filterChainDefinitionMap.put("/v1/api0/security/login", "anon");    // 登陆用户
    filterChainDefinitionMap.put("/v1/api0/security/logout", "anon");    // 登陆用户
    filterChainDefinitionMap.put("/v1/api0/user*//*", "user");       // 登陆用户
    //>>>>>>
    filterChainDefinitionMap.put("/v1/api0/orgcate*//**//**//**//*", "user");       // 登陆用户
    filterChainDefinitionMap.put("/v1/api0/resource*//**//**//**//*", "user");       // 登陆用户
    filterChainDefinitionMap.put("/v1/api0/role*//**//**//**//*", "user");
    //<<<<<<
    //filterChainDefinitionMap.put("/v1/api0/**/**", "user,perms");       // 登陆用户
    filterChainDefinitionMap.put("/v1/api0/**/**", "user");       // 登陆用户
    filterChainDefinitionMap.put("/home.html", "authc");                // 登陆用户
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

    Map<String, Filter> filters = new HashMap<>();
    filters.put("anon", new AnonymousFilter());
    filters.put("user", new UserFilter());
    filters.put("authc", new FormAuthenticationFilter());
    filters.put("perms", new ShiroPermissionsFilter()); // 自定义权限过滤
    shiroFilterFactoryBean.setFilters(filters);

    return shiroFilterFactoryBean;
}
 
Example 17
Source File: ShiroAutoConfiguration.java    From spring-boot-shiro with Apache License 2.0 5 votes vote down vote up
public ShiroFilterFactoryBean getShiroFilterFactoryBean(SecurityManager securityManager) throws Exception {
    ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
    shiroFilter.setSecurityManager(securityManager);
    shiroFilter.setLoginUrl(properties.getLoginUrl());
    shiroFilter.setSuccessUrl(properties.getSuccessUrl());
    shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl());

    Map<String, Filter> filterMap = new LinkedHashMap<String, Filter>();
    filterMap.put("authc", formSignInFilter());

    Map<String, Filter> filterClasses = instantiateFilterClasses(properties.getFilters());
    if (filterClasses != null) {
        filterMap.putAll(filterClasses);
    }

    if (shiroFilterCustomizer != null) {
        filterMap = shiroFilterCustomizer.customize(filterMap);
    }

    shiroFilter.setFilters(filterMap);

    Map<String, String> filterChains = new LinkedHashMap<>();
    if (jdbcPermissionDefinitionsLoader != null) {
        Map<String, String> permissionUrlMap = jdbcPermissionDefinitionsLoader.getObject();
        filterChains.putAll(permissionUrlMap);
    }
    if (properties.getFilterChainDefinitions() != null) {
        filterChains.putAll(properties.getFilterChainDefinitions());
    }
    shiroFilter.setFilterChainDefinitionMap(filterChains);
    return shiroFilter;
}
 
Example 18
Source File: ShiroConfig.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
@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("/admin/verificationCode", "anon");
        filterChainDefinitionMap.put("/admin/doLogin", "anon");
        //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了, 主要属性:redirectUrl:退出成功后重定向的地址(/)
//        filterChainDefinitionMap.put("/admin/logout", "logout");

        //<!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
        //<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
        filterChainDefinitionMap.put("/admin/**", "authc");

        filterChainDefinitionMap.put("/**", "anon");

        // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
        shiroFilterFactoryBean.setLoginUrl("/admin/login");
        // 登录成功后要跳转的链接
        shiroFilterFactoryBean.setSuccessUrl("/admin/index");

        //未授权界面;
        shiroFilterFactoryBean.setUnauthorizedUrl("/403");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
        return shiroFilterFactoryBean;
    }
 
Example 19
Source File: ShiroConfiguration.java    From mblog with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Shiro的过滤器链
 */
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
    ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
    shiroFilter.setSecurityManager(securityManager);
    shiroFilter.setLoginUrl("/login");
    shiroFilter.setSuccessUrl("/");
    shiroFilter.setUnauthorizedUrl("/error/reject.html");

    HashMap<String, Filter> filters = new HashMap<>();
    filters.put("authc", new AuthenticatedFilter());
    shiroFilter.setFilters(filters);

    /**
     * 配置shiro拦截器链
     *
     * anon  不需要认证
     * authc 需要认证
     * user  验证通过或RememberMe登录的都可以
     *
     * 顺序从上到下,优先级依次降低
     *
     */
    Map<String, String> hashMap = new LinkedHashMap<>();
    hashMap.put("/dist/**", "anon");
    hashMap.put("/theme/**", "anon");
    hashMap.put("/storage/**", "anon");
    hashMap.put("/login", "anon");
    hashMap.put("/user/**", "authc");
    hashMap.put("/settings/**", "authc");
    hashMap.put("/post/editing", "authc");
    hashMap.put("/post/submit", "authc");
    hashMap.put("/post/delete/*", "authc");
    hashMap.put("/post/upload", "authc");

    hashMap.put("/admin/channel/list", "authc,perms[channel:list]");
    hashMap.put("/admin/channel/update", "authc,perms[channel:update]");
    hashMap.put("/admin/channel/delete", "authc,perms[channel:delete]");

    hashMap.put("/admin/post/list", "authc,perms[post:list]");
    hashMap.put("/admin/post/update", "authc,perms[post:update]");
    hashMap.put("/admin/post/delete", "authc,perms[post:delete]");

    hashMap.put("/admin/comment/list", "authc,perms[comment:list]");
    hashMap.put("/admin/comment/delete", "authc,perms[comment:delete]");

    hashMap.put("/admin/user/list", "authc,perms[user:list]");
    hashMap.put("/admin/user/update_role", "authc,perms[user:role]");
    hashMap.put("/admin/user/pwd", "authc,perms[user:pwd]");
    hashMap.put("/admin/user/open", "authc,perms[user:open]");
    hashMap.put("/admin/user/close", "authc,perms[user:close]");

    hashMap.put("/admin/options/index", "authc,perms[options:index]");
    hashMap.put("/admin/options/update", "authc,perms[options:update]");

    hashMap.put("/admin/role/list", "authc,perms[role:list]");
    hashMap.put("/admin/role/update", "authc,perms[role:update]");
    hashMap.put("/admin/role/delete", "authc,perms[role:delete]");

    hashMap.put("/admin/theme/*", "authc,perms[theme:index]");

    hashMap.put("/admin", "authc,perms[admin]");
    hashMap.put("/admin/*", "authc,perms[admin]");

    shiroFilter.setFilterChainDefinitionMap(hashMap);
    return shiroFilter;
}
 
Example 20
Source File: ShiroConfig.java    From SpringBootBucket with MIT License 4 votes vote down vote up
/**
 * ShiroFilterFactoryBean 处理拦截资源文件问题。
 * 注意:单独一个ShiroFilterFactoryBean配置是或报错的,以为在
 * 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager Filter Chain定义说明
 * 1、一个URL可以配置多个Filter,使用逗号分隔
 * 2、当设置多个过滤器时,全部验证通过,才视为通过
 * 3、部分过滤器可指定参数,如perms,roles
 */
@Bean
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {

    ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
    // 必须设置 SecurityManager
    shiroFilterFactoryBean.setSecurityManager(securityManager);
    //验证码过滤器
    Map<String, Filter> filtersMap = shiroFilterFactoryBean.getFilters();
    KaptchaFilter kaptchaFilter = new KaptchaFilter();
    filtersMap.put("kaptchaFilter", kaptchaFilter);
    //实现自己规则roles,这是为了实现or的效果
    //RoleFilter roleFilter = new RoleFilter();
    //filtersMap.put("roles", roleFilter);
    shiroFilterFactoryBean.setFilters(filtersMap);
    // 拦截器
    //rest:比如/admins/user/**=rest[user],根据请求的方法,相当于/admins/user/**=perms[user:method] ,其中method为post,get,delete等。
    //port:比如/admins/user/**=port[8081],当请求的url的端口不是8081是跳转到schemal://serverName:8081?queryString,其中schmal是协议http或https等,serverName是你访问的host,8081是url配置里port的端口,queryString是你访问的url里的?后面的参数。
    //perms:比如/admins/user/**=perms[user:add:*],perms参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,比如/admins/user/**=perms["user:add:*,user:modify:*"],当有多个参数时必须每个参数都通过才通过,想当于isPermitedAll()方法。
    //roles:比如/admins/user/**=roles[admin],参数可以写多个,多个时必须加上引号,并且参数之间用逗号分割,当有多个参数时,比如/admins/user/**=roles["admin,guest"],每个参数通过才算通过,相当于hasAllRoles()方法。//要实现or的效果看http://zgzty.blog.163.com/blog/static/83831226201302983358670/
    //anon:比如/admins/**=anon 没有参数,表示可以匿名使用。
    //authc:比如/admins/user/**=authc表示需要认证才能使用,没有参数
    //authcBasic:比如/admins/user/**=authcBasic没有参数表示httpBasic认证
    //ssl:比如/admins/user/**=ssl没有参数,表示安全的url请求,协议为https
    //user:比如/admins/user/**=user没有参数表示必须存在用户,当登入操作时不做检查
    Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
    // 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
    filterChainDefinitionMap.put("/logout", "logout");
    //配置记住我或认证通过可以访问的地址
    filterChainDefinitionMap.put("/index", "user");
    filterChainDefinitionMap.put("/", "user");
    filterChainDefinitionMap.put("/login", "kaptchaFilter");
    // <!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
    //这段是配合 actuator框架使用的,配置相应的角色才能访问
    // filterChainDefinitionMap.put("/health", "roles[aix]");//服务器健康状况页面
    // filterChainDefinitionMap.put("/info", "roles[aix]");//服务器信息页面
    // filterChainDefinitionMap.put("/env", "roles[aix]");//应用程序的环境变量
    // filterChainDefinitionMap.put("/metrics", "roles[aix]");
    // filterChainDefinitionMap.put("/configprops", "roles[aix]");
    //开放的静态资源
    filterChainDefinitionMap.put("/favicon.ico", "anon");//网站图标
    filterChainDefinitionMap.put("/static/**", "anon");//配置static文件下资源能被访问的,这是个例子
    filterChainDefinitionMap.put("/kaptcha.jpg", "anon");//图片验证码(kaptcha框架)

    filterChainDefinitionMap.put("/api/v1/**", "anon");//API接口

    // swagger接口文档
    filterChainDefinitionMap.put("/v2/api-docs", "anon");
    filterChainDefinitionMap.put("/webjars/**", "anon");
    filterChainDefinitionMap.put("/swagger-resources/**", "anon");
    filterChainDefinitionMap.put("/swagger-ui.html", "anon");
    filterChainDefinitionMap.put("/doc.html", "anon");

    // 其他的
    filterChainDefinitionMap.put("/**", "authc");

    // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
    shiroFilterFactoryBean.setLoginUrl("/login");
    // 登录成功后要跳转的链接
    shiroFilterFactoryBean.setSuccessUrl("/index");
    // 未授权界面,不生效(详情原因看MyExceptionResolver)
    shiroFilterFactoryBean.setUnauthorizedUrl("/errorView/403_error.html");
    shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    return shiroFilterFactoryBean;
}