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.mgt.SecurityManager;
24  import org.apache.shiro.web.filter.mgt.DefaultFilter;
25  import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
26  
27  import javax.servlet.Filter;
28  import java.util.Map;
29  
30  /**
31   * Differs from the parent class only in the {@link #createDefaultInstance()} method, to
32   * ensure a web-capable {@code SecurityManager} instance is created by default.
33   *
34   * @since 1.0
35   */
36  public class WebIniSecurityManagerFactory extends IniSecurityManagerFactory {
37  
38      /**
39       * Creates a new {@code WebIniSecurityManagerFactory} instance which will construct web-capable
40       * {@code SecurityManager} instances.
41       */
42      public WebIniSecurityManagerFactory() {
43          super();
44      }
45  
46      /**
47       * Creates a new {@code WebIniSecurityManagerFactory} instance which will construct web-capable
48       * {@code SecurityManager} instances.  Uses the given {@link Ini} instance to construct the instance.
49       *
50       * @param config the Ini configuration that will be used to construct new web-capable {@code SecurityManager}
51       *               instances.
52       */
53      public WebIniSecurityManagerFactory(Ini config) {
54          super(config);
55      }
56  
57      /**
58       * Simply returns <code>new {@link DefaultWebSecurityManager}();</code> to ensure a web-capable
59       * {@code SecurityManager} is available by default.
60       *
61       * @return a new web-capable {@code SecurityManager} instance.
62       */
63      @Override
64      protected SecurityManager createDefaultInstance() {
65          return new DefaultWebSecurityManager();
66      }
67  
68      @SuppressWarnings({"unchecked"})
69      @Override
70      protected Map<String, ?> createDefaults(Ini ini, Ini.Section mainSection) {
71          Map defaults = super.createDefaults(ini, mainSection);
72          //add the default filters:
73          Map<String, Filter> defaultFilters = DefaultFilter.createInstanceMap(null);
74          defaults.putAll(defaultFilters);
75          return defaults;
76      }
77  }