Search in sources :

Example 1 with RolesAuthorizationFilter

use of org.apache.shiro.web.filter.authz.RolesAuthorizationFilter in project shiro by apache.

the class SimpleNamedFilterListTest method testListMethods.

/**
 * Exists mainly to increase code coverage as the SimpleNamedFilterList
 * implementation is a direct pass through.
 */
@Test
public void testListMethods() {
    FilterChain mock = createNiceMock(FilterChain.class);
    Filter filter = createNiceMock(Filter.class);
    NamedFilterList list = new SimpleNamedFilterList("test");
    list.add(filter);
    FilterChain chain = list.proxy(mock);
    assertNotNull(chain);
    assertNotSame(mock, chain);
    Filter singleFilter = new SslFilter();
    List<? extends Filter> multipleFilters = CollectionUtils.asList(new PortFilter(), new UserFilter());
    list.add(0, singleFilter);
    assertEquals(2, list.size());
    assertTrue(list.get(0) instanceof SslFilter);
    assertTrue(Arrays.equals(list.toArray(), new Object[] { singleFilter, filter }));
    list.addAll(multipleFilters);
    assertEquals(4, list.size());
    assertTrue(list.get(2) instanceof PortFilter);
    assertTrue(list.get(3) instanceof UserFilter);
    list.addAll(0, CollectionUtils.asList(new PermissionsAuthorizationFilter(), new RolesAuthorizationFilter()));
    assertEquals(6, list.size());
    assertTrue(list.get(0) instanceof PermissionsAuthorizationFilter);
    assertTrue(list.get(1) instanceof RolesAuthorizationFilter);
    assertEquals(2, list.indexOf(singleFilter));
    assertEquals(multipleFilters, list.subList(4, list.size()));
    assertTrue(list.contains(singleFilter));
    assertTrue(list.containsAll(multipleFilters));
    assertFalse(list.isEmpty());
    list.clear();
    assertTrue(list.isEmpty());
    list.add(singleFilter);
    Iterator i = list.iterator();
    assertTrue(i.hasNext());
    assertEquals(i.next(), singleFilter);
    ListIterator li = list.listIterator();
    assertTrue(li.hasNext());
    assertEquals(li.next(), singleFilter);
    li = list.listIterator(0);
    assertTrue(li.hasNext());
    assertEquals(li.next(), singleFilter);
    list.set(0, singleFilter);
    assertEquals(list.get(0), singleFilter);
    Filter[] filters = new Filter[list.size()];
    filters = list.toArray(filters);
    assertEquals(1, filters.length);
    assertEquals(filters[0], singleFilter);
    assertEquals(0, list.lastIndexOf(singleFilter));
    list.remove(singleFilter);
    assertTrue(list.isEmpty());
    list.add(singleFilter);
    list.remove(0);
    assertTrue(list.isEmpty());
    list.add(singleFilter);
    list.addAll(multipleFilters);
    assertEquals(3, list.size());
    list.removeAll(multipleFilters);
    assertEquals(1, list.size());
    assertEquals(list.get(0), singleFilter);
    list.addAll(multipleFilters);
    assertEquals(3, list.size());
    list.retainAll(multipleFilters);
    assertEquals(2, list.size());
    // noinspection unchecked
    assertEquals(new ArrayList(list), multipleFilters);
}
Also used : SslFilter(org.apache.shiro.web.filter.authz.SslFilter) FilterChain(javax.servlet.FilterChain) UserFilter(org.apache.shiro.web.filter.authc.UserFilter) PermissionsAuthorizationFilter(org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter) SslFilter(org.apache.shiro.web.filter.authz.SslFilter) PortFilter(org.apache.shiro.web.filter.authz.PortFilter) UserFilter(org.apache.shiro.web.filter.authc.UserFilter) Filter(javax.servlet.Filter) RolesAuthorizationFilter(org.apache.shiro.web.filter.authz.RolesAuthorizationFilter) RolesAuthorizationFilter(org.apache.shiro.web.filter.authz.RolesAuthorizationFilter) PermissionsAuthorizationFilter(org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter) PortFilter(org.apache.shiro.web.filter.authz.PortFilter) Test(org.junit.Test)

Aggregations

Filter (javax.servlet.Filter)1 FilterChain (javax.servlet.FilterChain)1 UserFilter (org.apache.shiro.web.filter.authc.UserFilter)1 PermissionsAuthorizationFilter (org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter)1 PortFilter (org.apache.shiro.web.filter.authz.PortFilter)1 RolesAuthorizationFilter (org.apache.shiro.web.filter.authz.RolesAuthorizationFilter)1 SslFilter (org.apache.shiro.web.filter.authz.SslFilter)1 Test (org.junit.Test)1