View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.shiro.web.config;
20  
21  import org.apache.shiro.config.Ini;
22  import org.apache.shiro.config.IniSecurityManagerFactory;
23  import org.apache.shiro.web.filter.mgt.DefaultFilter;
24  import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
25  import org.junit.Test;
26  
27  import javax.servlet.Filter;
28  import java.util.Map;
29  
30  import static org.junit.Assert.assertNotNull;
31  import static org.junit.Assert.assertTrue;
32  
33  /**
34   * TODO - Class JavaDoc
35   *
36   * @since May 8, 2010 4:21:10 PM
37   */
38  public class WebIniSecurityManagerFactoryTest {
39  
40  
41      /**
42       * Test that ensures the WebIniSecurityManagerFactory will automatically add the default
43       * filters to the pool of beans before the INI configuration is interpreted.
44       */
45      @Test
46      public void testDefaultFiltersPresent() {
47          Ini ini = new Ini();
48          //just a normal configuration line in the MAIN section for any of the default filtes should work
49          //out of the box.  So, create the main section and just config one of them:
50          Ini.Section section = ini.addSection(IniSecurityManagerFactory.MAIN_SECTION_NAME);
51          section.put("authc.loginUrl", "/login.jsp");
52  
53          WebIniSecurityManagerFactory factory = new WebIniSecurityManagerFactory(ini);
54          org.apache.shiro.mgt.SecurityManager sm = factory.getInstance();
55          assertNotNull(sm);
56          assertTrue(sm instanceof DefaultWebSecurityManager);
57  
58          //now assert that all of the default filters exist:
59          Map<String, ?> beans = factory.getBeans();
60          for (DefaultFilter defaultFilter : DefaultFilter.values()) {
61              Filter filter = (Filter) beans.get(defaultFilter.name());
62              assertNotNull(filter);
63              assertTrue(defaultFilter.getFilterClass().isAssignableFrom(filter.getClass()));
64          }
65      }
66  }