Java Code Examples for org.apache.shiro.spring.web.ShiroFilterFactoryBean#setLoginUrl()
The following examples show how to use
org.apache.shiro.spring.web.ShiroFilterFactoryBean#setLoginUrl() .
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: ShiroConfiguration.java From White-Jotter with MIT License | 7 votes |
@Bean public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); shiroFilterFactoryBean.setLoginUrl("/nowhere"); Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>(); Map<String, Filter> customizedFilter = new HashMap<>(); // 自定义过滤器设置 1 customizedFilter.put("url", getURLPathMatchingFilter()); // 自定义过滤器设置 2,命名,需在设置过滤路径前 filterChainDefinitionMap.put("/api/authentication", "authc"); // 防鸡贼登录 filterChainDefinitionMap.put("/api/menu", "authc"); filterChainDefinitionMap.put("/api/admin/**", "authc"); filterChainDefinitionMap.put("/api/admin/**", "url"); // 自定义过滤器设置 3,设置过滤路径 shiroFilterFactoryBean.setFilters(customizedFilter); // 自定义过滤器设置 4,启用 shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; }
Example 2
Source File: ShiroConfig.java From mysiteforme with Apache License 2.0 | 6 votes |
@Bean(name = "shiroFilter") public ShiroFilterFactoryBean shiroFilterFactoryBean(@Qualifier("authRealm")AuthRealm authRealm){ ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean(); bean.setSecurityManager(securityManager(authRealm)); bean.setSuccessUrl("/index"); bean.setLoginUrl("/login"); Map<String,Filter> map = Maps.newHashMap(); map.put("authc",new CaptchaFormAuthenticationFilter()); bean.setFilters(map); //配置访问权限 LinkedHashMap<String, String> filterChainDefinitionMap = Maps.newLinkedHashMap(); filterChainDefinitionMap.put("/static/**","anon"); filterChainDefinitionMap.put("/showBlog/**","anon"); filterChainDefinitionMap.put("/blog/**","anon"); filterChainDefinitionMap.put("/login/main","anon"); filterChainDefinitionMap.put("/genCaptcha","anon"); filterChainDefinitionMap.put("/systemLogout","authc"); filterChainDefinitionMap.put("/**","authc"); bean.setFilterChainDefinitionMap(filterChainDefinitionMap); return bean; }
Example 3
Source File: ShiroConfiguration.java From spring-boot-quickstart with Apache License 2.0 | 6 votes |
@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 4
Source File: ApplicationConfiguration.java From java-platform with Apache License 2.0 | 6 votes |
@Bean(name = "shiroFilter") public ShiroFilterFactoryBean shiroFilter() { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); shiroFilterFactoryBean.setLoginUrl("/admin"); shiroFilterFactoryBean.setSuccessUrl("/admin"); shiroFilterFactoryBean.setUnauthorizedUrl("/error"); Map<String, Filter> filters = Application.getSecurityfilters(); AjaxAuthenticationFilter ajaxAuthenticationFilter = new AjaxAuthenticationFilter(); ajaxAuthenticationFilter.setRobotPrevention(new CaptchaRobotPrevention()); filters.put(DefaultFilter.authc.name(), ajaxAuthenticationFilter); shiroFilterFactoryBean.setFilters(filters); shiroFilterFactoryBean.setFilterChainDefinitionMap(Application.getSecurityFilterChainDefinitionMap()); return shiroFilterFactoryBean; }
Example 5
Source File: ShiroConfig.java From learnjavabug with MIT License | 6 votes |
@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 6
Source File: ShiroConfig.java From blog-sample with Apache License 2.0 | 6 votes |
/** * Filter工厂,设置过滤条件与跳转条件 */ @Bean public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) { ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean(); // Shiro的核心安全接口 bean.setSecurityManager(securityManager); // 设置登陆页 bean.setLoginUrl("/login"); // 自定义拦截规则 Map<String,String> map = new HashMap<>(16); map.put("/", "anon"); // 设置退出登陆 map.put("/logout", "logout"); // 对所有用户认证 map.put("/**", "authc"); bean.setFilterChainDefinitionMap(map); return bean; }
Example 7
Source File: ShiroConfig.java From EasyReport with Apache License 2.0 | 6 votes |
@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 8
Source File: ShiroConfig.java From mall with MIT License | 6 votes |
@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 9
Source File: ShiroAutoConfiguration.java From utils with Apache License 2.0 | 5 votes |
public ShiroFilterFactoryBean getShiroFilterFactoryBean(SecurityManager securityManager) throws Exception { ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean(); shiroFilter.setSecurityManager(securityManager); shiroFilter.setLoginUrl(shiroProperties.getLoginUrl()); shiroFilter.setSuccessUrl(shiroProperties.getSuccessUrl()); shiroFilter.setUnauthorizedUrl(shiroProperties.getUnauthorizedUrl()); Map<String, Filter> filterMap = new LinkedHashMap<String, Filter>(); filterMap.put("authm", authFilter()); Map<String, Filter> filterClasses = instantiateFilterClasses(shiroProperties.getFilters()); if (filterClasses != null) { filterMap.putAll(filterClasses); } if (shiroFilterCustomizer != null) { filterMap = shiroFilterCustomizer.customize(filterMap); } shiroFilter.setFilters(filterMap); Map<String, String> filterChains = new LinkedHashMap<String, String>(); if (jdbcPermissionDefinitionsLoader != null) { Map<String, String> permissionUrlMap = jdbcPermissionDefinitionsLoader.getObject(); filterChains.putAll(permissionUrlMap); } if (shiroProperties.getFilterChainDefinitions() != null) { filterChains.putAll(shiroProperties.getFilterChainDefinitions()); } shiroFilter.setFilterChainDefinitionMap(filterChains); return shiroFilter; }
Example 10
Source File: ShiroConfig.java From fastdep with Apache License 2.0 | 5 votes |
/** * 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 JavaQuarkBBS with Apache License 2.0 | 5 votes |
/** * 处理拦截资源文件问题。 * * @param securityManager * @return */ @Bean public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); // 设置 SecurityManager shiroFilterFactoryBean.setSecurityManager(securityManager); // 如果不设置默认会自动寻找Web工程根目录下的"/login.html"页面 shiroFilterFactoryBean.setLoginUrl("/login"); // 登录成功后要跳转的链接 shiroFilterFactoryBean.setSuccessUrl("/initPage"); //未授权界面 shiroFilterFactoryBean.setUnauthorizedUrl("/403"); //拦截器. Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); filterChainDefinitionMap.put("/favicon.png","anon");//解决弹出favicon.ico下载 filterChainDefinitionMap.put("/logout", "logout"); filterChainDefinitionMap.put("/css/**", "anon"); filterChainDefinitionMap.put("/js/**", "anon"); filterChainDefinitionMap.put("/img/**", "anon"); filterChainDefinitionMap.put("/font-awesome/**", "anon"); //自定义加载权限资源关系 List<Permission> list = permissionService.findAll(); for (Permission p : list) { if (!p.getPerurl().isEmpty()) { String permission = "perms[" + p.getPerurl() + "]"; filterChainDefinitionMap.put(p.getPerurl(), permission); } } //过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 filterChainDefinitionMap.put("/**", "authc"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; }
Example 12
Source File: ShiroConfig.java From scaffold-cloud with MIT License | 4 votes |
@Bean public ShiroFilterFactoryBean shiroFilter(DefaultWebSecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager()); Map<String, Filter> filters = new LinkedHashMap<>(); LogoutFilter logoutFilter = new LogoutFilter(); logoutFilter.setRedirectUrl("/home"); shiroFilterFactoryBean.setFilters(filters); Map<String, String> filterChainDefinitionManager = new LinkedHashMap<String, String>(); ResponseModel<List<SysMenuBO>> responseModel = sysMenuFeign.findAll(); List<SysMenuBO> menuList = responseModel.getData(); if (CollectionUtil.isNotEmpty(menuList)) { for (SysMenuBO menu : menuList) { if (StrUtil.isNotEmpty(menu.getUrl())) { ShiroService.formatUrl2Code(filterChainDefinitionManager, menu, PERMISSION_STRING); } } } filterChainDefinitionManager.put("/login", "anon"); filterChainDefinitionManager.put("/logout", "logout"); filterChainDefinitionManager.put("/login/check", "anon"); filterChainDefinitionManager.put("/static/**", "anon"); filterChainDefinitionManager.put("/notify/**", "anon"); filterChainDefinitionManager.put("/lang/**", "anon"); filterChainDefinitionManager.put("/*/login", "anon"); filterChainDefinitionManager.put("/*/logout", "logout"); filterChainDefinitionManager.put("/*/login/check", "anon"); filterChainDefinitionManager.put("/*/static/**", "anon"); filterChainDefinitionManager.put("/*/notify/**", "anon"); filterChainDefinitionManager.put("/*/lang/**", "anon"); filterChainDefinitionManager.put("/**", "anon"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionManager); shiroFilterFactoryBean.setLoginUrl("/login"); shiroFilterFactoryBean.setSuccessUrl("/index"); shiroFilterFactoryBean.setUnauthorizedUrl("/403"); return shiroFilterFactoryBean; }
Example 13
Source File: ShiroConfig.java From jeecg-boot-with-activiti with MIT License | 4 votes |
/** * Filter Chain定义说明 * * 1、一个URL可以配置多个Filter,使用逗号分隔 * 2、当设置多个过滤器时,全部验证通过,才视为通过 * 3、部分过滤器可指定参数,如perms,roles */ @Bean("shiroFilter") public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); // 拦截器 Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>(); if(oConvertUtils.isNotEmpty(excludeUrls)){ String[] permissionUrl = excludeUrls.split(","); for(String url : permissionUrl){ filterChainDefinitionMap.put(url,"anon"); } } //cas验证登录 filterChainDefinitionMap.put("/cas/client/validateLogin", "anon"); // 配置不会被拦截的链接 顺序判断 filterChainDefinitionMap.put("/sys/getCheckCode", "anon"); //登录验证码接口排除 filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除 filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除 filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除 filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串 filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码 filterChainDefinitionMap.put("/sys/phoneLogin", "anon");//手机登录 filterChainDefinitionMap.put("/sys/user/checkOnlyUser", "anon");//校验用户是否存在 filterChainDefinitionMap.put("/sys/user/register", "anon");//用户注册 filterChainDefinitionMap.put("/sys/user/querySysUser", "anon");//根据手机号获取用户信息 filterChainDefinitionMap.put("/sys/user/phoneVerification", "anon");//用户忘记密码验证手机号 filterChainDefinitionMap.put("/sys/user/passwordChange", "anon");//用户更改密码 filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码 filterChainDefinitionMap.put("/sys/common/view/**", "anon");//图片预览不限制token filterChainDefinitionMap.put("/sys/common/download/**", "anon");//文件下载不限制token filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览 filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件 filterChainDefinitionMap.put("/", "anon"); filterChainDefinitionMap.put("/doc.html", "anon"); filterChainDefinitionMap.put("/**/*.js", "anon"); filterChainDefinitionMap.put("/**/*.css", "anon"); filterChainDefinitionMap.put("/**/*.html", "anon"); filterChainDefinitionMap.put("/**/*.svg", "anon"); filterChainDefinitionMap.put("/**/*.pdf", "anon"); filterChainDefinitionMap.put("/**/*.jpg", "anon"); filterChainDefinitionMap.put("/**/*.png", "anon"); filterChainDefinitionMap.put("/**/*.ico", "anon"); // update-begin--Author:sunjianlei Date:20190813 for:排除字体格式的后缀 filterChainDefinitionMap.put("/**/*.ttf", "anon"); filterChainDefinitionMap.put("/**/*.woff", "anon"); // update-begin--Author:sunjianlei Date:20190813 for:排除字体格式的后缀 filterChainDefinitionMap.put("/druid/**", "anon"); filterChainDefinitionMap.put("/swagger-ui.html", "anon"); filterChainDefinitionMap.put("/swagger**/**", "anon"); filterChainDefinitionMap.put("/webjars/**", "anon"); filterChainDefinitionMap.put("/v2/**", "anon"); //性能监控 filterChainDefinitionMap.put("/actuator/metrics/**", "anon"); filterChainDefinitionMap.put("/actuator/httptrace/**", "anon"); filterChainDefinitionMap.put("/actuator/redis/**", "anon"); //测试示例 filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面 filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试 // TODO filterChainDefinitionMap.put("/test/**", "anon"); filterChainDefinitionMap.put("/flow/**", "anon"); //websocket排除 filterChainDefinitionMap.put("/websocket/**", "anon"); // 添加自己的过滤器并且取名为jwt Map<String, Filter> filterMap = new HashMap<String, Filter>(1); filterMap.put("jwt", new JwtFilter()); shiroFilterFactoryBean.setFilters(filterMap); // <!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 filterChainDefinitionMap.put("/**", "jwt"); // 未授权界面返回JSON shiroFilterFactoryBean.setUnauthorizedUrl("/sys/common/403"); shiroFilterFactoryBean.setLoginUrl("/sys/common/403"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; }
Example 14
Source File: ShiroConfig.java From jeecg-cloud with Apache License 2.0 | 4 votes |
/** * Filter Chain定义说明 * * 1、一个URL可以配置多个Filter,使用逗号分隔 * 2、当设置多个过滤器时,全部验证通过,才视为通过 * 3、部分过滤器可指定参数,如perms,roles */ @Bean("shiroFilter") public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); // 拦截器 Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>(); if(oConvertUtils.isNotEmpty(excludeUrls)){ String[] permissionUrl = excludeUrls.split(","); for(String url : permissionUrl){ filterChainDefinitionMap.put(url,"anon"); } } //cas验证登录 filterChainDefinitionMap.put("/cas/client/validateLogin", "anon"); // 配置不会被拦截的链接 顺序判断 filterChainDefinitionMap.put("/sys/randomImage/**", "anon"); //登录验证码接口排除 filterChainDefinitionMap.put("/sys/checkCaptcha", "anon"); //登录验证码接口排除 filterChainDefinitionMap.put("/sys/login", "anon"); //登录接口排除 filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除 filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除 filterChainDefinitionMap.put("/thirdLogin/**", "anon"); //第三方登录 filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串 filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码 filterChainDefinitionMap.put("/sys/phoneLogin", "anon");//手机登录 filterChainDefinitionMap.put("/sys/user/checkOnlyUser", "anon");//校验用户是否存在 filterChainDefinitionMap.put("/sys/user/register", "anon");//用户注册 filterChainDefinitionMap.put("/sys/user/querySysUser", "anon");//根据手机号获取用户信息 filterChainDefinitionMap.put("/sys/user/phoneVerification", "anon");//用户忘记密码验证手机号 filterChainDefinitionMap.put("/sys/user/passwordChange", "anon");//用户更改密码 filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码 filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览 filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件 filterChainDefinitionMap.put("/", "anon"); filterChainDefinitionMap.put("/doc.html", "anon"); filterChainDefinitionMap.put("/**/*.js", "anon"); filterChainDefinitionMap.put("/**/*.css", "anon"); filterChainDefinitionMap.put("/**/*.html", "anon"); filterChainDefinitionMap.put("/**/*.svg", "anon"); filterChainDefinitionMap.put("/**/*.pdf", "anon"); filterChainDefinitionMap.put("/**/*.jpg", "anon"); filterChainDefinitionMap.put("/**/*.png", "anon"); filterChainDefinitionMap.put("/**/*.ico", "anon"); // update-begin--Author:sunjianlei Date:20190813 for:排除字体格式的后缀 filterChainDefinitionMap.put("/**/*.ttf", "anon"); filterChainDefinitionMap.put("/**/*.woff", "anon"); filterChainDefinitionMap.put("/**/*.woff2", "anon"); // update-begin--Author:sunjianlei Date:20190813 for:排除字体格式的后缀 filterChainDefinitionMap.put("/druid/**", "anon"); filterChainDefinitionMap.put("/swagger-ui.html", "anon"); filterChainDefinitionMap.put("/swagger**/**", "anon"); filterChainDefinitionMap.put("/webjars/**", "anon"); filterChainDefinitionMap.put("/v2/**", "anon"); //性能监控 filterChainDefinitionMap.put("/actuator/metrics/**", "anon"); filterChainDefinitionMap.put("/actuator/httptrace/**", "anon"); filterChainDefinitionMap.put("/actuator/redis/**", "anon"); filterChainDefinitionMap.put("/actuator/**", "anon"); //大屏设计器排除 filterChainDefinitionMap.put("/big/screen/**", "anon"); //测试示例 filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面 filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试 //websocket排除 filterChainDefinitionMap.put("/websocket/**", "anon"); // 添加自己的过滤器并且取名为jwt Map<String, Filter> filterMap = new HashMap<String, Filter>(1); filterMap.put("jwt", new JwtFilter()); shiroFilterFactoryBean.setFilters(filterMap); // <!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 filterChainDefinitionMap.put("/**", "jwt"); // 未授权界面返回JSON shiroFilterFactoryBean.setUnauthorizedUrl("/sys/common/403"); shiroFilterFactoryBean.setLoginUrl("/sys/common/403"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; }
Example 15
Source File: ShiroConfig.java From SpringBoot-Base-System with GNU Lesser General Public License v3.0 | 4 votes |
/** * shiro拦截器 * * @time 2018年4月10日 下午5:10:12. * * @version V1.0 * @param securityManager * @param realm * @return ShiroFilterFactoryBean */ @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("/admin/login"); shiroFilter.setSuccessUrl("/admin/index"); shiroFilter.setUnauthorizedUrl("/assets/401.html"); Map<String, String> filterChainDefinitionMap = new HashMap<String, String>(); filterChainDefinitionMap.put("/assets/**", "anon"); filterChainDefinitionMap.put("/admin/regist", "anon");// 添加 filterChainDefinitionMap.put("/admin/login", "anon"); filterChainDefinitionMap.put("/isTrue", "anon"); // 验证码异步验证 // 个人信息 filterChainDefinitionMap.put("/admin/info/**", "anon"); // 自主还书 filterChainDefinitionMap.put("/admin/borrow/**", "anon"); filterChainDefinitionMap.put("/admin/user/index", "perms[system:user:index]"); filterChainDefinitionMap.put("/admin/user/add", "perms[system:user:add]"); filterChainDefinitionMap.put("/admin/user/edit*", "perms[system:user:edit]"); filterChainDefinitionMap.put("/admin/user/deleteBatch", "perms[system:user:deleteBatch]"); filterChainDefinitionMap.put("/admin/user/grant/**", "perms[system:user:grant]"); filterChainDefinitionMap.put("/admin/user/resume/**", "perms[system:user:resume]"); // 注册账号验证和添加账号验证 filterChainDefinitionMap.put("/admin/user/isExist/**", "anon"); filterChainDefinitionMap.put("/admin/user/isAvailable/**", "anon"); filterChainDefinitionMap.put("/admin/user/isAllTrue/**", "anon"); filterChainDefinitionMap.put("/admin/role/index", "perms[system:role:index]"); filterChainDefinitionMap.put("/admin/role/add", "perms[system:role:add]"); filterChainDefinitionMap.put("/admin/role/edit*", "perms[system:role:edit]"); filterChainDefinitionMap.put("/admin/role/deleteBatch", "perms[system:role:deleteBatch]"); filterChainDefinitionMap.put("/admin/role/grant/**", "perms[system:role:grant]"); filterChainDefinitionMap.put("/admin/resource/index", "perms[system:resource:index]"); filterChainDefinitionMap.put("/admin/resource/add", "perms[system:resource:add]"); filterChainDefinitionMap.put("/admin/resource/edit*", "perms[system:resource:edit]"); filterChainDefinitionMap.put("/admin/resource/deleteBatch", "perms[system:resource:deleteBatch]"); filterChainDefinitionMap.put("/druid/", "perms[system:resource:druid]");// druid filterChainDefinitionMap.put("/admin/memorandum/*", "perms[system:memorandum:memorandum]");// 系统记录,只使用一个拦截url // 添加过滤条件 filterChainDefinitionMap.put("/admin/books/book_management", "perms[system:books:book_management]"); filterChainDefinitionMap.put("/admin/**", "user"); // 默认所有均可依靠cookie,本项目隐藏bug,cookie太大,无法保存在浏览器本地 shiroFilter.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilter; }
Example 16
Source File: ShiroConfig.java From springboot-learn with MIT License | 4 votes |
@Bean("shiroFilter") public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean(); shiroFilter.setSecurityManager(securityManager); Map<String, Filter> filterMap = new LinkedHashMap<>(); filterMap.put("authc", new AuthorityFilter()); shiroFilter.setFilters(filterMap); shiroFilter.setLoginUrl("/index.html"); //设置不验证的url Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); // swagger filterChainDefinitionMap.put("/swagger-ui.html", "anon"); filterChainDefinitionMap.put("/webjars/**", "anon"); // druid filterChainDefinitionMap.put("/druid/**", "anon"); // 首页 filterChainDefinitionMap.put("/index", "anon"); filterChainDefinitionMap.put("/index.html", "anon"); // 登录 filterChainDefinitionMap.put("/login", "anon"); // 退出登录 filterChainDefinitionMap.put("/logout", "anon"); // 是否登录 filterChainDefinitionMap.put("/notLogin", "anon"); filterChainDefinitionMap.put("/isLogin", "anon"); // 未授权 filterChainDefinitionMap.put("/notAuthority", "anon"); // 静态资源文件 filterChainDefinitionMap.put("/static/**", "anon"); // ueditro富文本编辑器初始化 filterChainDefinitionMap.put("/ueditor/exec", "anon"); // 错误处理 filterChainDefinitionMap.put("/error/**", "anon"); // 代码生成 filterChainDefinitionMap.put("/generator/**", "anon"); filterChainDefinitionMap.put("/goodsCategory/**", "authc"); filterChainDefinitionMap.put("/user/**", "authc"); filterChainDefinitionMap.put("/role/**", "authc"); filterChainDefinitionMap.put("/permission/**", "authc"); // filterChainDefinitionMap.put("/**", "authc"); shiroFilter.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilter; }
Example 17
Source File: ShiroConfig.java From pybbs with GNU Affero General Public License v3.0 | 4 votes |
@Bean public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager securityManager) { log.info("开始配置shiroFilter..."); ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); Map<String, Filter> filterMap = shiroFilterFactoryBean.getFilters(); // filterMap.put("myShiroFilter", new MyShiroFilter()); shiroFilterFactoryBean.setFilters(filterMap); //拦截器. Map<String, String> map = new HashMap<>(); // 配置不会被拦截的链接 顺序判断 相关静态资源 map.put("/static/**", "anon"); //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 map.put("/admin/logout", "logout"); //<!-- 过滤链定义,从上向下顺序执行,一般将/**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了; //<!-- authc:所有url都必须认证通过才可以访问; user: 表示rememberMe后就可以访问 anon:所有url都都可以匿名访问--> map.put("/admin/permission/**", "authc"); map.put("/admin/role/**", "authc"); map.put("/admin/system/**", "authc"); map.put("/admin/admin_user/**", "authc"); map.put("/admin/index", "user"); map.put("/admin/comment/**", "user"); map.put("/admin/sensitive_word/**", "user"); map.put("/admin/tag/**", "user"); map.put("/admin/topic/**", "user"); map.put("/admin/user/**", "user"); // map.put("/adminlogin", "myShiroFilter"); // 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面 shiroFilterFactoryBean.setLoginUrl("/adminlogin"); // 登录成功后要跳转的链接 shiroFilterFactoryBean.setSuccessUrl("/admin/index"); //未授权界面; shiroFilterFactoryBean.setUnauthorizedUrl("/adminlogin"); shiroFilterFactoryBean.setFilterChainDefinitionMap(map); // Map<String, Filter> filters = new HashMap<>(); // shiroFilterFactoryBean.setFilters(filters); return shiroFilterFactoryBean; }
Example 18
Source File: ShiroConfiguration.java From spring-boot-seed with MIT License | 4 votes |
@Bean public ShiroFilterFactoryBean shiroFilter() { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); // 设置securityManager,其中注入了自定义的Realm shiroFilterFactoryBean.setSecurityManager(securityManager()); // 登陆url shiroFilterFactoryBean.setLoginUrl("/login"); // 成功登陆后打开的url shiroFilterFactoryBean.setSuccessUrl("/index"); // 授权失败跳转的页面 shiroFilterFactoryBean.setUnauthorizedUrl("/login"); Map<String, Filter> filtersMap = shiroFilterFactoryBean.getFilters(); // 添加过滤器,例如:验证码过滤器 KaptchaFilter shiroFilterFactoryBean.setFilters(filtersMap); // 权限过滤链 Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); /* * 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没有参数表示必须存在用户,当登入操作时不做检查 */ filterChainDefinitionMap.put("/login.jsp", "anon"); filterChainDefinitionMap.put("/test/checkAuthc", "authc"); filterChainDefinitionMap.put("/test/**", "anon"); // druid过滤 filterChainDefinitionMap.put("/druid", "anon"); // swagger过滤 filterChainDefinitionMap.put("/swagger", "anon"); filterChainDefinitionMap.put("/swagger/api/docs", "anon"); filterChainDefinitionMap.put("/swagger-ui.html", "anon"); filterChainDefinitionMap.put("/webjars/**", "anon"); filterChainDefinitionMap.put("/swagger-resources/**", "anon"); // 其他需要授权 filterChainDefinitionMap.put("/*", "authc"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); return shiroFilterFactoryBean; }
Example 19
Source File: ShiroConfiguration.java From mblog with GNU General Public License v3.0 | 4 votes |
/** * 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 |
/** * 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; }