use of org.apache.shiro.web.filter.mgt.DefaultFilter 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 org.apache.shiro.web.filter.mgt.DefaultFilter in project shiro by apache.
the class DefaultFiltersTest method checkDefaultFilters.
@Test
public void checkDefaultFilters() throws Exception {
EnumSet<DefaultFilter> defaultFilters = EnumSet.allOf(DefaultFilter.class);
for (Field field : ShiroWebModule.class.getFields()) {
if (Modifier.isStatic(field.getModifiers()) && Key.class.isAssignableFrom(field.getType())) {
Class<? extends Filter> filterType = ((Key) field.get(null)).getTypeLiteral().getRawType();
boolean found = false;
for (DefaultFilter filter : defaultFilters) {
if (filterType.equals(filter.getFilterClass())) {
found = true;
defaultFilters.remove(filter);
break;
}
}
if (!found) {
fail("Guice ShiroWebModule containts a default filter that Shiro proper does not. (" + filterType.getName() + ")");
}
}
}
if (!defaultFilters.isEmpty()) {
fail("Guice ShiroWebModule is missing one or more filters. " + defaultFilters);
}
}
Aggregations