001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.web.config;
020
021import org.apache.shiro.SecurityUtils;
022
023/**
024 * Configuration for Shiro's root level servlet filter.
025 *
026 * @since 1.10.0
027 */
028public class ShiroFilterConfiguration {
029
030    private boolean filterOncePerRequest;
031
032    private boolean staticSecurityManagerEnabled;
033
034    /**
035     * Returns {@code true} if the filter should only execute once per request. If set to {@code false} the filter
036     * will execute each time it is invoked.
037     *
038     * @return {@code true} if this filter should only execute once per request.
039     */
040    public boolean isFilterOncePerRequest() {
041        return filterOncePerRequest;
042    }
043
044    /**
045     * Sets whether the filter executes once per request or for every invocation of the filter. It is recommended
046     * to leave this disabled if you are using a {@link javax.servlet.RequestDispatcher RequestDispatcher} to forward
047     * or include request (JSP tags, programmatically, or via a framework).
048     *
049     * @param filterOncePerRequest Whether this filter executes once per request.
050     */
051    public void setFilterOncePerRequest(boolean filterOncePerRequest) {
052        this.filterOncePerRequest = filterOncePerRequest;
053    }
054
055    /**
056     * Returns {@code true} if the constructed {@link SecurityManager SecurityManager} associated with the filter
057     * should be bound to static memory (via
058     * {@code SecurityUtils.}{@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}),
059     * {@code false} otherwise.
060     * <p/>
061     * The default value is {@code false}.
062     * <p/>
063     *
064     * @return {@code true} if the constructed {@link SecurityManager SecurityManager} associated with the filter should be bound
065     * to static memory (via {@code SecurityUtils.}{@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager)
066     * setSecurityManager}),
067     * {@code false} otherwise.
068     * @see <a href="https://issues.apache.org/jira/browse/SHIRO-287">SHIRO-287</a>
069     */
070    public boolean isStaticSecurityManagerEnabled() {
071        return staticSecurityManagerEnabled;
072    }
073
074    /**
075     * Sets if the constructed {@link SecurityManager SecurityManager} associated with the filter should be bound
076     * to static memory (via {@code SecurityUtils.}
077     *      {@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}).
078     * <p/>
079     * The default value is {@code false}.
080     *
081     * @param staticSecurityManagerEnabled if the constructed {@link SecurityManager SecurityManager} associated with the filter
082     *                        should be bound to static memory (via
083     *                        {@code SecurityUtils.}
084     *                        {@link SecurityUtils#setSecurityManager(org.apache.shiro.mgt.SecurityManager) setSecurityManager}).
085     * @see <a href="https://issues.apache.org/jira/browse/SHIRO-287">SHIRO-287</a>
086     */
087    public ShiroFilterConfiguration setStaticSecurityManagerEnabled(boolean staticSecurityManagerEnabled) {
088        this.staticSecurityManagerEnabled = staticSecurityManagerEnabled;
089        return this;
090    }
091}