List of usage examples for org.apache.shiro.web.filter.mgt PathMatchingFilterChainResolver PathMatchingFilterChainResolver
public PathMatchingFilterChainResolver()
From source file:com.centfor.frame.shiro.FrameShiroFilterFactoryBean.java
License:Apache License
/** * This implementation:// ww w . j ava 2 s . co m * <ol> * <li>Ensures the required {@link #setSecurityManager(org.apache.shiro.mgt.SecurityManager) securityManager} * property has been set</li> * <li>{@link #createFilterChainManager() Creates} a {@link FilterChainManager} instance that reflects the * configured {@link #setFilters(java.util.Map) filters} and * {@link #setFilterChainDefinitionMap(java.util.Map) filter chain definitions}</li> * <li>Wraps the FilterChainManager with a suitable * {@link org.apache.shiro.web.filter.mgt.FilterChainResolver FilterChainResolver} since the Shiro Filter * implementations do not know of {@code FilterChainManager}s</li> * <li>Sets both the {@code SecurityManager} and {@code FilterChainResolver} instances on a new Shiro Filter * instance and returns that filter instance.</li> * </ol> * * @return a new Shiro Filter reflecting any configured filters and filter chain definitions. * @throws Exception if there is a problem creating the AbstractShiroFilter instance. */ protected AbstractShiroFilter createInstance() throws Exception { //log.debug("Creating Shiro Filter instance."); SecurityManager securityManager = getSecurityManager(); if (securityManager == null) { String msg = "SecurityManager property must be set."; throw new BeanInitializationException(msg); } if (!(securityManager instanceof WebSecurityManager)) { String msg = "The security manager does not implement the WebSecurityManager interface."; throw new BeanInitializationException(msg); } FilterChainManager manager = createFilterChainManager(); //Expose the constructed FilterChainManager by first wrapping it in a // FilterChainResolver implementation. The AbstractShiroFilter implementations // do not know about FilterChainManagers - only resolvers: PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver(); chainResolver.setFilterChainManager(manager); //Now create a concrete ShiroFilter instance and apply the acquired SecurityManager and built //FilterChainResolver. It doesn't matter that the instance is an anonymous inner class //here - we're just using it because it is a concrete AbstractShiroFilter instance that accepts //injection of the SecurityManager and FilterChainResolver: return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver); }
From source file:com.freedomotic.plugins.devices.restapiv3.auth.FDWebEnvironment.java
License:Open Source License
public FDWebEnvironment() { BasicHttpAuthenticationFilter authc = new CorsBasicHttpAuthenticationFilter(); LogoutFilter logout = new LogoutFilter(); logout.setRedirectUrl("http://www.freedomotic.com/"); FilterChainManager fcMan = new DefaultFilterChainManager(); fcMan.addFilter("authc", authc); fcMan.addFilter("logout", logout); fcMan.createChain("/auth/logout", "logout"); fcMan.createChain("/v3/**", "authc"); PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver(); resolver.setFilterChainManager(fcMan); setFilterChainResolver(resolver);/*from w w w .ja v a 2 s . c o m*/ setWebSecurityManager(RestAPIv3.defaultWebSecurityManager); }
From source file:com.oakeel.shiro.PtpIniWebEnvironment.java
@Override protected FilterChainResolver createFilterChainResolver() { // FilterChainResolver //1? FilterChainResolver PathMatchingFilterChainResolver filterChainResolver = new PathMatchingFilterChainResolver(); //2? FilterChainManager DefaultFilterChainManager filterChainManager = new DefaultFilterChainManager(); //3? Filter/*from w w w .j a v a 2 s . c om*/ DefaultFilter[] filters = DefaultFilter.values(); for (DefaultFilter filter : filters) { filterChainManager.addFilter(filter.name(), (Filter) ClassUtils.newInstance(filter.getFilterClass())); } //4? URL-Filter filterChainManager.addToChain("/log.xhtml", "authc"); filterChainManager.addToChain("/unauthorized.xhtml", "anon"); filterChainManager.addToChain("/**", "authc"); filterChainManager.addToChain("/**", "roles", "admin"); //5? Filter FormAuthenticationFilter authcFilter = (FormAuthenticationFilter) filterChainManager.getFilter("authc"); authcFilter.setLoginUrl("/login.jsp"); RolesAuthorizationFilter rolesFilter = (RolesAuthorizationFilter) filterChainManager.getFilter("roles"); rolesFilter.setUnauthorizedUrl("/unauthorized.jsp"); filterChainResolver.setFilterChainManager(filterChainManager); return filterChainResolver; }
From source file:io.bootique.shiro.web.MappedShiroFilterFactory.java
License:Apache License
protected FilterChainResolver createChainResolver(Map<String, Filter> chainFilters) { DefaultFilterChainManager chainManager = new DefaultFilterChainManager(); // load filters chainFilters.forEach((name, filter) -> chainManager.addFilter(name, filter)); if (urls != null) { urls.forEach((url, value) -> { LOGGER.info("Loading url chain {} -> {}", url, value); chainManager.createChain(url, value); });//from w ww . j a v a 2 s . com } PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver(); resolver.setFilterChainManager(chainManager); return resolver; }
From source file:myStuff.rest.shiro.ShiroHelper.java
License:Apache License
public static FilterChainResolver getFilterChainResolver() { if (filterChainResolver == null) { BasicHttpAuthenticationFilter authcBasic = new MyFilter(); authcBasic.setEnabled(true);/*ww w. ja v a2 s.c o m*/ FilterChainManager fcMan = new DefaultFilterChainManager(); fcMan.addFilter("authcBasic[permissive]", authcBasic); fcMan.createChain("/**", "authcBasic[permissive]"); PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver(); resolver.setFilterChainManager(fcMan); filterChainResolver = resolver; } return filterChainResolver; }
From source file:org.base.frame.shiro.FrameShiroFilterFactoryBean.java
License:Apache License
/** * This implementation:/*from www .ja va2s . c o m*/ * <ol> * <li>Ensures the required {@link #setSecurityManager(org.apache.shiro.mgt.SecurityManager) securityManager} * property has been set</li> * <li>{@link #createFilterChainManager() Creates} a {@link FilterChainManager} instance that reflects the * configured {@link #setFilters(java.util.Map) filters} and * {@link #setFilterChainDefinitionMap(java.util.Map) filter chain definitions}</li> * <li>Wraps the FilterChainManager with a suitable * {@link org.apache.shiro.web.filter.mgt.FilterChainResolver FilterChainResolver} since the Shiro Filter * implementations do not know of {@code FilterChainManager}s</li> * <li>Sets both the {@code SecurityManager} and {@code FilterChainResolver} instances on a new Shiro Filter * instance and returns that filter instance.</li> * </ol> * * @return a new Shiro Filter reflecting any configured filters and filter chain definitions. * @throws Exception if there is a problem creating the AbstractShiroFilter instance. */ protected AbstractShiroFilter createInstance() throws Exception { log.debug("Creating Shiro Filter instance."); SecurityManager securityManager = getSecurityManager(); if (securityManager == null) { String msg = "SecurityManager property must be set."; throw new BeanInitializationException(msg); } if (!(securityManager instanceof WebSecurityManager)) { String msg = "The security manager does not implement the WebSecurityManager interface."; throw new BeanInitializationException(msg); } FilterChainManager manager = createFilterChainManager(); //Expose the constructed FilterChainManager by first wrapping it in a // FilterChainResolver implementation. The AbstractShiroFilter implementations // do not know about FilterChainManagers - only resolvers: PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver(); chainResolver.setFilterChainManager(manager); //Now create a concrete ShiroFilter instance and apply the acquired SecurityManager and built //FilterChainResolver. It doesn't matter that the instance is an anonymous inner class //here - we're just using it because it is a concrete AbstractShiroFilter instance that accepts //injection of the SecurityManager and FilterChainResolver: return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver); }
From source file:zcu.xutil.misc.ShiroFilterFactory.java
License:Apache License
public AbstractShiroFilter getShiroFilter() { DefaultFilterChainManager manager = new DefaultFilterChainManager(); for (Filter filter : manager.getFilters().values()) applyGlobalPropertiesIfNecessary(filter); for (Map.Entry<String, Filter> entry : filters.entrySet()) { applyGlobalPropertiesIfNecessary(entry.getValue()); manager.addFilter(entry.getKey(), entry.getValue()); }/*www . j a va 2 s . c om*/ Ini ini = new Ini(); ini.load(definitions); Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS); if (CollectionUtils.isEmpty(section)) section = ini.getSection(Ini.DEFAULT_SECTION_NAME); for (Map.Entry<String, String> entry : section.entrySet()) manager.createChain(entry.getKey(), entry.getValue()); PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver(); chainResolver.setFilterChainManager(manager); return new XSFilter((WebSecurityManager) securityManager, chainResolver); }