use of javax.servlet.Filter in project springBoot-learn-demo by nbfujx.
the class ShiroConfig method shiroFilterFactoryBean.
/**
* ShiroFilterFactoryBean,是个factorybean,为了生成ShiroFilter。
* 它主要保持了三项数据,securityManager,filters,filterChainDefinitionManager。
*/
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean() {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager());
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
shiroFilterFactoryBean.setFilters(filters);
Map<String, String> filterChainDefinitionManager = new LinkedHashMap<String, String>();
filterChainDefinitionManager.put("/login", "anon");
filterChainDefinitionManager.put("/logout", "anon");
// "authc,perms[sysUser:*]");
filterChainDefinitionManager.put("/test/*", "authc,perms");
// filterChainDefinitionManager.put("/sysMenu/*", "authc,perms");//"authc,perms[sysUser:*]");
// filterChainDefinitionManager.put("/*", "anon");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionManager);
shiroFilterFactoryBean.setLoginUrl("/notAuthc");
// shiroFilterFactoryBean.setUnauthorizedUrl("/notAuthz");
return shiroFilterFactoryBean;
}
use of javax.servlet.Filter in project shiro by apache.
the class WebIniSecurityManagerFactoryTest method testDefaultFiltersPresent.
/**
* Test that ensures the WebIniSecurityManagerFactory will automatically add the default
* filters to the pool of beans before the INI configuration is interpreted.
*/
@Test
public void testDefaultFiltersPresent() {
Ini ini = new Ini();
// just a normal configuration line in the MAIN section for any of the default filtes should work
// out of the box. So, create the main section and just config one of them:
Ini.Section section = ini.addSection(IniSecurityManagerFactory.MAIN_SECTION_NAME);
section.put("authc.loginUrl", "/login.jsp");
WebIniSecurityManagerFactory factory = new WebIniSecurityManagerFactory(ini);
org.apache.shiro.mgt.SecurityManager sm = factory.getInstance();
assertNotNull(sm);
assertTrue(sm instanceof DefaultWebSecurityManager);
// now assert that all of the default filters exist:
Map<String, ?> beans = factory.getBeans();
for (DefaultFilter defaultFilter : DefaultFilter.values()) {
Filter filter = (Filter) beans.get(defaultFilter.name());
assertNotNull(filter);
assertTrue(defaultFilter.getFilterClass().isAssignableFrom(filter.getClass()));
}
}
use of javax.servlet.Filter in project shiro by apache.
the class DefaultFilterChainManager method addToChain.
public void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) {
if (!StringUtils.hasText(chainName)) {
throw new IllegalArgumentException("chainName cannot be null or empty.");
}
Filter filter = getFilter(filterName);
if (filter == null) {
throw new IllegalArgumentException("There is no filter with name '" + filterName + "' to apply to chain [" + chainName + "] in the pool of available Filters. Ensure a " + "filter with that name/path has first been registered with the addFilter method(s).");
}
applyChainConfig(chainName, filter, chainSpecificFilterConfig);
NamedFilterList chain = ensureChain(chainName);
chain.add(filter);
}
use of javax.servlet.Filter in project shiro by apache.
the class IniFilterChainResolverFactory method registerFilters.
protected void registerFilters(Map<String, Filter> filters, FilterChainManager manager) {
if (!CollectionUtils.isEmpty(filters)) {
// only call filter.init if there is a FilterConfig available
boolean init = getFilterConfig() != null;
for (Map.Entry<String, Filter> entry : filters.entrySet()) {
String name = entry.getKey();
Filter filter = entry.getValue();
manager.addFilter(name, filter, init);
}
}
}
use of javax.servlet.Filter in project shiro by apache.
the class WebIniSecurityManagerFactory method createDefaults.
@SuppressWarnings({ "unchecked" })
@Override
protected Map<String, ?> createDefaults(Ini ini, Ini.Section mainSection) {
Map defaults = super.createDefaults(ini, mainSection);
// add the default filters:
Map<String, Filter> defaultFilters = DefaultFilter.createInstanceMap(null);
defaults.putAll(defaultFilters);
return defaults;
}
Aggregations