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.SecurityUtils;
22  
23  /**
24   * Configuration for Shiro's root level servlet filter.
25   *
26   * @since 1.10.0
27   */
28  public class ShiroFilterConfiguration {
29  
30      private boolean filterOncePerRequest;
31  
32      private boolean staticSecurityManagerEnabled;
33  
34      /**
35       * Returns {@code true} if the filter should only execute once per request. If set to {@code false} the filter
36       * will execute each time it is invoked.
37       *
38       * @return {@code true} if this filter should only execute once per request.
39       */
40      public boolean isFilterOncePerRequest() {
41          return filterOncePerRequest;
42      }
43  
44      /**
45       * Sets whether the filter executes once per request or for every invocation of the filter. It is recommended
46       * to leave this disabled if you are using a {@link javax.servlet.RequestDispatcher RequestDispatcher} to forward
47       * or include request (JSP tags, programmatically, or via a framework).
48       *
49       * @param filterOncePerRequest Whether this filter executes once per request.
50       */
51      public void setFilterOncePerRequest(boolean filterOncePerRequest) {
52          this.filterOncePerRequest = filterOncePerRequest;
53      }
54  
55      /**
56       * Returns {@code true} if the constructed {@link SecurityManager SecurityManager} associated with the filter
57       * should be bound to static memory (via
58       * {@code SecurityUtils.}{@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}),
59       * {@code false} otherwise.
60       * <p/>
61       * The default value is {@code false}.
62       * <p/>
63       *
64       * @return {@code true} if the constructed {@link SecurityManager SecurityManager} associated with the filter should be bound
65       * to static memory (via {@code SecurityUtils.}{@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager)
66       * setSecurityManager}),
67       * {@code false} otherwise.
68       * @see <a href="https://issues.apache.org/jira/browse/SHIRO-287">SHIRO-287</a>
69       */
70      public boolean isStaticSecurityManagerEnabled() {
71          return staticSecurityManagerEnabled;
72      }
73  
74      /**
75       * Sets if the constructed {@link SecurityManager SecurityManager} associated with the filter should be bound
76       * to static memory (via {@code SecurityUtils.}
77       *      {@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}).
78       * <p/>
79       * The default value is {@code false}.
80       *
81       * @param staticSecurityManagerEnabled if the constructed {@link SecurityManager SecurityManager} associated with the filter
82       *                        should be bound to static memory (via
83       *                        {@code SecurityUtils.}
84       *                        {@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}).
85       * @see <a href="https://issues.apache.org/jira/browse/SHIRO-287">SHIRO-287</a>
86       */
87      public ShiroFilterConfiguration setStaticSecurityManagerEnabled(boolean staticSecurityManagerEnabled) {
88          this.staticSecurityManagerEnabled = staticSecurityManagerEnabled;
89          return this;
90      }
91  }