You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by ad...@apache.org on 2010/05/26 20:34:49 UTC
svn commit: r948527 [34/38] - in /incubator/shiro:
branches/shiro-root-1.0.x/ branches/shiro-root-1.0.x/all/
branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/
branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/aop/
branches/shir...
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java Wed May 26 18:34:28 2010
@@ -1,271 +1,271 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import org.apache.shiro.config.ConfigurationException;
-import org.apache.shiro.util.CollectionUtils;
-import org.apache.shiro.util.Nameable;
-import org.apache.shiro.util.StringUtils;
-import org.apache.shiro.web.filter.PathConfigProcessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.shiro.util.StringUtils.split;
-
-/**
- * Default {@link FilterChainManager} implementation maintaining a map of {@link Filter Filter} instances
- * (key: filter name, value: Filter) as well as a map of {@link NamedFilterList NamedFilterList}s created from these
- * {@code Filter}s (key: filter chain name, value: NamedFilterList). The {@code NamedFilterList} is essentially a
- * {@link FilterChain} that also has a name property by which it can be looked up.
- *
- * @author Les Hazlewood
- * @see NamedFilterList
- * @since 1.0
- */
-public class DefaultFilterChainManager implements FilterChainManager {
-
- private static transient final Logger log = LoggerFactory.getLogger(DefaultFilterChainManager.class);
-
- private FilterConfig filterConfig;
-
- private Map<String, Filter> filters; //pool of filters available for creating chains
-
- private Map<String, NamedFilterList> filterChains; //key: chain name, value: chain
-
- public DefaultFilterChainManager() {
- this.filters = new LinkedHashMap<String, Filter>();
- this.filterChains = new LinkedHashMap<String, NamedFilterList>();
- addDefaultFilters(false);
- }
-
- public DefaultFilterChainManager(FilterConfig filterConfig) {
- this.filters = new LinkedHashMap<String, Filter>();
- this.filterChains = new LinkedHashMap<String, NamedFilterList>();
- setFilterConfig(filterConfig);
- addDefaultFilters(true);
- }
-
- /**
- * Returns the {@code FilterConfig} provided by the Servlet container at webapp startup.
- *
- * @return the {@code FilterConfig} provided by the Servlet container at webapp startup.
- */
- public FilterConfig getFilterConfig() {
- return filterConfig;
- }
-
- /**
- * Sets the {@code FilterConfig} provided by the Servlet container at webapp startup.
- *
- * @param filterConfig the {@code FilterConfig} provided by the Servlet container at webapp startup.
- */
- public void setFilterConfig(FilterConfig filterConfig) {
- this.filterConfig = filterConfig;
- }
-
- public Map<String, Filter> getFilters() {
- return filters;
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void setFilters(Map<String, Filter> filters) {
- this.filters = filters;
- }
-
- public Map<String, NamedFilterList> getFilterChains() {
- return filterChains;
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void setFilterChains(Map<String, NamedFilterList> filterChains) {
- this.filterChains = filterChains;
- }
-
- public Filter getFilter(String name) {
- return this.filters.get(name);
- }
-
- public void addFilter(String name, Filter filter) {
- addFilter(name, filter, true);
- }
-
- public void addFilter(String name, Filter filter, boolean init) {
- addFilter(name, filter, init, true);
- }
-
- public void createChain(String chainName, String chainDefinition) {
- if (!StringUtils.hasText(chainName)) {
- throw new NullPointerException("chainName cannot be null or empty.");
- }
- if (!StringUtils.hasText(chainDefinition)) {
- throw new NullPointerException("chainDefinition cannot be null or empty.");
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Creating chain [" + chainName + "] from String definition [" + chainDefinition + "]");
- }
-
- //parse the value by tokenizing it to get the resulting filter-specific config entries
- //
- //e.g. for a value of
- //
- // "authc, roles[admin,user], perms[file:edit]"
- //
- // the resulting token array would equal
- //
- // { "authc", "roles[admin,user]", "perms[file:edit]" }
- //
- String[] filterTokens = split(chainDefinition);
-
- //each token is specific to each filter.
- //strip the name and extract any filter-specific config between brackets [ ]
- for (String token : filterTokens) {
- String[] nameAndConfig = token.split("\\[", 2);
- String name = nameAndConfig[0];
- String config = null;
-
- if (nameAndConfig.length == 2) {
- config = nameAndConfig[1];
- //if there was an open bracket, there was a close bracket, so strip it too:
- config = config.substring(0, config.length() - 1);
- }
-
- //now we have the filter name, path and (possibly null) path-specific config. Let's apply them:
- addToChain(chainName, name, config);
- }
- }
-
- protected void addFilter(String name, Filter filter, boolean init, boolean overwrite) {
- Filter existing = getFilter(name);
- if (existing == null || overwrite) {
- if (filter instanceof Nameable) {
- ((Nameable) filter).setName(name);
- }
- if (init) {
- initFilter(filter);
- }
- this.filters.put(name, filter);
- }
- }
-
- public void addToChain(String chainName, String filterName) {
- addToChain(chainName, filterName, null);
- }
-
- public void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) {
- if (!StringUtils.hasText(chainName)) {
- throw new IllegalArgumentException("chainName cannot be null or empty.");
- }
- Filter filter = getFilter(filterName);
- if (filter == null) {
- throw new IllegalArgumentException("There is no filter with name '" + filterName +
- "' to apply to chain [" + chainName + "] in the pool of available Filters. Ensure a " +
- "filter with that name/path has first been registered with the addFilter method(s).");
- }
-
- applyChainConfig(chainName, filter, chainSpecificFilterConfig);
-
- NamedFilterList chain = ensureChain(chainName);
- chain.add(filter);
- }
-
- protected void applyChainConfig(String chainName, Filter filter, String chainSpecificFilterConfig) {
- if (log.isDebugEnabled()) {
- log.debug("Attempting to apply path [" + chainName + "] to filter [" + filter + "] " +
- "with config [" + chainSpecificFilterConfig + "]");
- }
- if (filter instanceof PathConfigProcessor) {
- ((PathConfigProcessor) filter).processPathConfig(chainName, chainSpecificFilterConfig);
- } else {
- if (StringUtils.hasText(chainSpecificFilterConfig)) {
- //they specified a filter configuration, but the Filter doesn't implement PathConfigProcessor
- //this is an erroneous config:
- String msg = "chainSpecificFilterConfig was specified, but the underlying " +
- "Filter instance is not an 'instanceof' " +
- PathConfigProcessor.class.getName() + ". This is required if the filter is to accept " +
- "chain-specific configuration.";
- throw new ConfigurationException(msg);
- }
- }
- }
-
- protected NamedFilterList ensureChain(String chainName) {
- NamedFilterList chain = getChain(chainName);
- if (chain == null) {
- chain = new SimpleNamedFilterList(chainName);
- this.filterChains.put(chainName, chain);
- }
- return chain;
- }
-
- public NamedFilterList getChain(String chainName) {
- return this.filterChains.get(chainName);
- }
-
- public boolean hasChains() {
- return !CollectionUtils.isEmpty(this.filterChains);
- }
-
- public Set<String> getChainNames() {
- //noinspection unchecked
- return this.filterChains != null ? this.filterChains.keySet() : Collections.EMPTY_SET;
- }
-
- public FilterChain proxy(FilterChain original, String chainName) {
- NamedFilterList configured = getChain(chainName);
- if (configured == null) {
- String msg = "There is no configured chain under the name/key [" + chainName + "].";
- throw new IllegalArgumentException(msg);
- }
- return configured.proxy(original);
- }
-
- /**
- * Initializes the filter by calling <code>filter.init( {@link #getFilterConfig() getFilterConfig()} );</code>.
- *
- * @param filter the filter to initialize with the {@code FilterConfig}.
- */
- protected void initFilter(Filter filter) {
- FilterConfig filterConfig = getFilterConfig();
- if (filterConfig == null) {
- throw new IllegalStateException("FilterConfig attribute has not been set. This must occur before filter " +
- "initialization can occur.");
- }
- try {
- filter.init(filterConfig);
- } catch (ServletException e) {
- throw new ConfigurationException(e);
- }
- }
-
- protected void addDefaultFilters(boolean init) {
- for (DefaultFilter defaultFilter : DefaultFilter.values()) {
- addFilter(defaultFilter.name(), defaultFilter.newInstance(), init, false);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import org.apache.shiro.config.ConfigurationException;
+import org.apache.shiro.util.CollectionUtils;
+import org.apache.shiro.util.Nameable;
+import org.apache.shiro.util.StringUtils;
+import org.apache.shiro.web.filter.PathConfigProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.shiro.util.StringUtils.split;
+
+/**
+ * Default {@link FilterChainManager} implementation maintaining a map of {@link Filter Filter} instances
+ * (key: filter name, value: Filter) as well as a map of {@link NamedFilterList NamedFilterList}s created from these
+ * {@code Filter}s (key: filter chain name, value: NamedFilterList). The {@code NamedFilterList} is essentially a
+ * {@link FilterChain} that also has a name property by which it can be looked up.
+ *
+ * @author Les Hazlewood
+ * @see NamedFilterList
+ * @since 1.0
+ */
+public class DefaultFilterChainManager implements FilterChainManager {
+
+ private static transient final Logger log = LoggerFactory.getLogger(DefaultFilterChainManager.class);
+
+ private FilterConfig filterConfig;
+
+ private Map<String, Filter> filters; //pool of filters available for creating chains
+
+ private Map<String, NamedFilterList> filterChains; //key: chain name, value: chain
+
+ public DefaultFilterChainManager() {
+ this.filters = new LinkedHashMap<String, Filter>();
+ this.filterChains = new LinkedHashMap<String, NamedFilterList>();
+ addDefaultFilters(false);
+ }
+
+ public DefaultFilterChainManager(FilterConfig filterConfig) {
+ this.filters = new LinkedHashMap<String, Filter>();
+ this.filterChains = new LinkedHashMap<String, NamedFilterList>();
+ setFilterConfig(filterConfig);
+ addDefaultFilters(true);
+ }
+
+ /**
+ * Returns the {@code FilterConfig} provided by the Servlet container at webapp startup.
+ *
+ * @return the {@code FilterConfig} provided by the Servlet container at webapp startup.
+ */
+ public FilterConfig getFilterConfig() {
+ return filterConfig;
+ }
+
+ /**
+ * Sets the {@code FilterConfig} provided by the Servlet container at webapp startup.
+ *
+ * @param filterConfig the {@code FilterConfig} provided by the Servlet container at webapp startup.
+ */
+ public void setFilterConfig(FilterConfig filterConfig) {
+ this.filterConfig = filterConfig;
+ }
+
+ public Map<String, Filter> getFilters() {
+ return filters;
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void setFilters(Map<String, Filter> filters) {
+ this.filters = filters;
+ }
+
+ public Map<String, NamedFilterList> getFilterChains() {
+ return filterChains;
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void setFilterChains(Map<String, NamedFilterList> filterChains) {
+ this.filterChains = filterChains;
+ }
+
+ public Filter getFilter(String name) {
+ return this.filters.get(name);
+ }
+
+ public void addFilter(String name, Filter filter) {
+ addFilter(name, filter, true);
+ }
+
+ public void addFilter(String name, Filter filter, boolean init) {
+ addFilter(name, filter, init, true);
+ }
+
+ public void createChain(String chainName, String chainDefinition) {
+ if (!StringUtils.hasText(chainName)) {
+ throw new NullPointerException("chainName cannot be null or empty.");
+ }
+ if (!StringUtils.hasText(chainDefinition)) {
+ throw new NullPointerException("chainDefinition cannot be null or empty.");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Creating chain [" + chainName + "] from String definition [" + chainDefinition + "]");
+ }
+
+ //parse the value by tokenizing it to get the resulting filter-specific config entries
+ //
+ //e.g. for a value of
+ //
+ // "authc, roles[admin,user], perms[file:edit]"
+ //
+ // the resulting token array would equal
+ //
+ // { "authc", "roles[admin,user]", "perms[file:edit]" }
+ //
+ String[] filterTokens = split(chainDefinition);
+
+ //each token is specific to each filter.
+ //strip the name and extract any filter-specific config between brackets [ ]
+ for (String token : filterTokens) {
+ String[] nameAndConfig = token.split("\\[", 2);
+ String name = nameAndConfig[0];
+ String config = null;
+
+ if (nameAndConfig.length == 2) {
+ config = nameAndConfig[1];
+ //if there was an open bracket, there was a close bracket, so strip it too:
+ config = config.substring(0, config.length() - 1);
+ }
+
+ //now we have the filter name, path and (possibly null) path-specific config. Let's apply them:
+ addToChain(chainName, name, config);
+ }
+ }
+
+ protected void addFilter(String name, Filter filter, boolean init, boolean overwrite) {
+ Filter existing = getFilter(name);
+ if (existing == null || overwrite) {
+ if (filter instanceof Nameable) {
+ ((Nameable) filter).setName(name);
+ }
+ if (init) {
+ initFilter(filter);
+ }
+ this.filters.put(name, filter);
+ }
+ }
+
+ public void addToChain(String chainName, String filterName) {
+ addToChain(chainName, filterName, null);
+ }
+
+ public void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) {
+ if (!StringUtils.hasText(chainName)) {
+ throw new IllegalArgumentException("chainName cannot be null or empty.");
+ }
+ Filter filter = getFilter(filterName);
+ if (filter == null) {
+ throw new IllegalArgumentException("There is no filter with name '" + filterName +
+ "' to apply to chain [" + chainName + "] in the pool of available Filters. Ensure a " +
+ "filter with that name/path has first been registered with the addFilter method(s).");
+ }
+
+ applyChainConfig(chainName, filter, chainSpecificFilterConfig);
+
+ NamedFilterList chain = ensureChain(chainName);
+ chain.add(filter);
+ }
+
+ protected void applyChainConfig(String chainName, Filter filter, String chainSpecificFilterConfig) {
+ if (log.isDebugEnabled()) {
+ log.debug("Attempting to apply path [" + chainName + "] to filter [" + filter + "] " +
+ "with config [" + chainSpecificFilterConfig + "]");
+ }
+ if (filter instanceof PathConfigProcessor) {
+ ((PathConfigProcessor) filter).processPathConfig(chainName, chainSpecificFilterConfig);
+ } else {
+ if (StringUtils.hasText(chainSpecificFilterConfig)) {
+ //they specified a filter configuration, but the Filter doesn't implement PathConfigProcessor
+ //this is an erroneous config:
+ String msg = "chainSpecificFilterConfig was specified, but the underlying " +
+ "Filter instance is not an 'instanceof' " +
+ PathConfigProcessor.class.getName() + ". This is required if the filter is to accept " +
+ "chain-specific configuration.";
+ throw new ConfigurationException(msg);
+ }
+ }
+ }
+
+ protected NamedFilterList ensureChain(String chainName) {
+ NamedFilterList chain = getChain(chainName);
+ if (chain == null) {
+ chain = new SimpleNamedFilterList(chainName);
+ this.filterChains.put(chainName, chain);
+ }
+ return chain;
+ }
+
+ public NamedFilterList getChain(String chainName) {
+ return this.filterChains.get(chainName);
+ }
+
+ public boolean hasChains() {
+ return !CollectionUtils.isEmpty(this.filterChains);
+ }
+
+ public Set<String> getChainNames() {
+ //noinspection unchecked
+ return this.filterChains != null ? this.filterChains.keySet() : Collections.EMPTY_SET;
+ }
+
+ public FilterChain proxy(FilterChain original, String chainName) {
+ NamedFilterList configured = getChain(chainName);
+ if (configured == null) {
+ String msg = "There is no configured chain under the name/key [" + chainName + "].";
+ throw new IllegalArgumentException(msg);
+ }
+ return configured.proxy(original);
+ }
+
+ /**
+ * Initializes the filter by calling <code>filter.init( {@link #getFilterConfig() getFilterConfig()} );</code>.
+ *
+ * @param filter the filter to initialize with the {@code FilterConfig}.
+ */
+ protected void initFilter(Filter filter) {
+ FilterConfig filterConfig = getFilterConfig();
+ if (filterConfig == null) {
+ throw new IllegalStateException("FilterConfig attribute has not been set. This must occur before filter " +
+ "initialization can occur.");
+ }
+ try {
+ filter.init(filterConfig);
+ } catch (ServletException e) {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ protected void addDefaultFilters(boolean init) {
+ for (DefaultFilter defaultFilter : DefaultFilter.values()) {
+ addFilter(defaultFilter.name(), defaultFilter.newInstance(), init, false);
+ }
+ }
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/DefaultFilterChainManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainManager.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainManager.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainManager.java Wed May 26 18:34:28 2010
@@ -1,198 +1,198 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import org.apache.shiro.config.ConfigurationException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A {@code FilterChainManager} manages the creation and modification of {@link Filter} chains from an available pool
- * of {@link Filter} instances.
- *
- * @since 1.0
- */
-public interface FilterChainManager {
-
- /**
- * Returns the pool of available {@code Filter}s managed by this manager, keyed by {@code name}.
- *
- * @return the pool of available {@code Filter}s managed by this manager, keyed by {@code name}.
- */
- Map<String, Filter> getFilters();
-
- /**
- * Returns the filter chain identified by the specified {@code chainName} or {@code null} if there is no chain with
- * that name.
- *
- * @param chainName the name identifying the filter chain.
- * @return the filter chain identified by the specified {@code chainName} or {@code null} if there is no chain with
- * that name.
- */
- NamedFilterList getChain(String chainName);
-
- /**
- * Returns {@code true} if one or more configured chains are available, {@code false} if none are configured.
- *
- * @return {@code true} if one or more configured chains are available, {@code false} if none are configured.
- */
- boolean hasChains();
-
- /**
- * Returns the names of all configured chains or an empty {@code Set} if no chains have been configured.
- *
- * @return the names of all configured chains or an empty {@code Set} if no chains have been configured.
- */
- Set<String> getChainNames();
-
- /**
- * Proxies the specified {@code original} FilterChain with the named chain. The returned
- * {@code FilterChain} instance will first execute the configured named chain and then lastly invoke the given
- * {@code original} chain.
- *
- * @param original the original FilterChain to proxy
- * @param chainName the name of the internal configured filter chain that should 'sit in front' of the specified
- * original chain.
- * @return a {@code FilterChain} instance that will execute the named chain and then finally the
- * specified {@code original} FilterChain instance.
- * @throws IllegalArgumentException if there is no configured chain with the given {@code chainName}.
- */
- FilterChain proxy(FilterChain original, String chainName);
-
- /**
- * Adds a filter to the 'pool' of available filters that can be used when
- * {@link #addToChain(String, String, String) creating filter chains}.
- * <p/>
- * Calling this method is effectively the same as calling
- * <code>{@link #addFilter(String, javax.servlet.Filter, boolean) addFilter}(name, filter, <b>true</b>);</code>
- *
- * @param name the name to assign to the filter, used to reference the filter in chain definitions
- * @param filter the filter to initialize and then add to the pool of available filters that can be used
- */
- void addFilter(String name, Filter filter);
-
- /**
- * Adds a filter to the 'pool' of available filters that can be used when
- * {@link #addToChain(String, String, String) creating filter chains}.
- *
- * @param name the name to assign to the filter, used to reference the filter in chain definitions
- * @param filter the filter to assign to the filter pool
- * @param init whether or not the {@code Filter} should be
- * {@link Filter#init(javax.servlet.FilterConfig) initialized} first before being added to the pool.
- */
- void addFilter(String name, Filter filter, boolean init);
-
- /**
- * Creates a filter chain for the given {@code chainName} with the specified {@code chainDefinition}
- * String.
- * <h3>Conventional Use</h3>
- * Because the {@code FilterChainManager} interface does not impose any restrictions on filter chain names,
- * (it expects only Strings), a convenient convention is to make the chain name an actual URL path expression
- * (such as an {@link org.apache.shiro.util.AntPathMatcher Ant path expression}). For example:
- * <p/>
- * <code>createChain(<b><em>path_expression</em></b>, <em>path_specific_filter_chain_definition</em>);</code>
- * This convention can be used by a {@link FilterChainResolver} to inspect request URL paths
- * against the chain name (path) and, if a match is found, return the corresponding chain for runtime filtering.
- * <h3>Chain Definition Format</h3>
- * The {@code chainDefinition} method argument is expected to conform to the following format:
- * <pre>
- * filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN]</pre>
- * where
- * <ol>
- * <li>{@code filterN} is the name of a filter previously
- * {@link #addFilter(String, javax.servlet.Filter) registered} with the manager, and</li>
- * <li>{@code [optional_configN]} is an optional bracketed string that has meaning for that particular filter for
- * <em>this particular chain</em></li>
- * </ol>
- * If the filter does not need specific config for that chain name/URL path,
- * you may discard the brackets - that is, {@code filterN[]} just becomes {@code filterN}.
- * <p/>
- * And because this method does create a chain, remember that order matters! The comma-delimited filter tokens in
- * the {@code chainDefinition} specify the chain's execution order.
- * <h3>Examples</h3>
- * <pre>/account/** = authcBasic</pre>
- * This example says "Create a filter named '{@code /account/**}' consisting of only the '{@code authcBasic}'
- * filter". Also because the {@code authcBasic} filter does not need any path-specific
- * config, it doesn't have any config brackets {@code []}.
- * <p/>
- * <pre>/remoting/** = authcBasic, roles[b2bClient], perms["remote:invoke:wan,lan"]</pre>
- * This example by contrast uses the 'roles' and 'perms' filters which <em>do</em> use bracket notation. This
- * definition says:
- * <p/>
- * Construct a filter chain named '{@code /remoting/**}' which
- * <ol>
- * <li>ensures the user is first authenticated ({@code authcBasic}) then</li>
- * <li>ensures that user has the {@code b2bClient} role, and then finally</li>
- * <li>ensures that they have the {@code remote:invoke:lan,wan} permission.</li>
- * </ol>
- * <p/>
- * <b>Note</b>: because elements within brackets [ ] can be comma-delimited themselves, you must quote the
- * internal bracket definition if commas are needed (the above example has 'lan,wan'). If we didn't do that, the
- * parser would interpret the chain definition as four tokens:
- * <ol>
- * <li>authcBasic</li>
- * <li>roles[b2bclient]</li>
- * <li>perms[remote:invoke:lan</li>
- * <li>wan]</li>
- * </ol>
- * which is obviously incorrect. So remember to use quotes if your internal bracket definitions need to use commas.
- *
- * @param chainName the name to associate with the chain, conventionally a URL path pattern.
- * @param chainDefinition the string-formatted chain definition used to construct an actual
- * {@link NamedFilterList} chain instance.
- * @see FilterChainResolver
- * @see org.apache.shiro.util.AntPathMatcher AntPathMatcher
- */
- void createChain(String chainName, String chainDefinition);
-
- /**
- * Adds (appends) a filter to the filter chain identified by the given {@code chainName}. If there is no chain
- * with the given name, a new one is created and the filter will be the first in the chain.
- *
- * @param chainName the name of the chain where the filter will be appended.
- * @param filterName the name of the {@link #addFilter registered} filter to add to the chain.
- * @throws IllegalArgumentException if there is not a {@link #addFilter(String, javax.servlet.Filter) registered}
- * filter under the given {@code filterName}
- */
- void addToChain(String chainName, String filterName);
-
- /**
- * Adds (appends) a filter to the filter chain identified by the given {@code chainName}. If there is no chain
- * with the given name, a new one is created and the filter will be the first in the chain.
- * <p/>
- * Note that the final argument expects the associated filter to be an instance of
- * a {@link org.apache.shiro.web.filter.PathConfigProcessor PathConfigProcessor} to accept per-chain configuration.
- * If it is not, a {@link IllegalArgumentException} will be thrown.
- *
- * @param chainName the name of the chain where the filter will be appended.
- * @param filterName the name of the {@link #addFilter registered} filter to add to the chain.
- * @param chainSpecificFilterConfig the filter-specific configuration that should be applied for only the specified
- * filter chain.
- * @throws IllegalArgumentException if there is not a {@link #addFilter(String, javax.servlet.Filter) registered}
- * filter under the given {@code filterName}
- * @throws ConfigurationException if the filter is not capable of accepting {@code chainSpecificFilterConfig}
- * (usually such filters implement the
- * {@link org.apache.shiro.web.filter.PathConfigProcessor PathConfigProcessor}
- * interface).
- */
- void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) throws ConfigurationException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import org.apache.shiro.config.ConfigurationException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A {@code FilterChainManager} manages the creation and modification of {@link Filter} chains from an available pool
+ * of {@link Filter} instances.
+ *
+ * @since 1.0
+ */
+public interface FilterChainManager {
+
+ /**
+ * Returns the pool of available {@code Filter}s managed by this manager, keyed by {@code name}.
+ *
+ * @return the pool of available {@code Filter}s managed by this manager, keyed by {@code name}.
+ */
+ Map<String, Filter> getFilters();
+
+ /**
+ * Returns the filter chain identified by the specified {@code chainName} or {@code null} if there is no chain with
+ * that name.
+ *
+ * @param chainName the name identifying the filter chain.
+ * @return the filter chain identified by the specified {@code chainName} or {@code null} if there is no chain with
+ * that name.
+ */
+ NamedFilterList getChain(String chainName);
+
+ /**
+ * Returns {@code true} if one or more configured chains are available, {@code false} if none are configured.
+ *
+ * @return {@code true} if one or more configured chains are available, {@code false} if none are configured.
+ */
+ boolean hasChains();
+
+ /**
+ * Returns the names of all configured chains or an empty {@code Set} if no chains have been configured.
+ *
+ * @return the names of all configured chains or an empty {@code Set} if no chains have been configured.
+ */
+ Set<String> getChainNames();
+
+ /**
+ * Proxies the specified {@code original} FilterChain with the named chain. The returned
+ * {@code FilterChain} instance will first execute the configured named chain and then lastly invoke the given
+ * {@code original} chain.
+ *
+ * @param original the original FilterChain to proxy
+ * @param chainName the name of the internal configured filter chain that should 'sit in front' of the specified
+ * original chain.
+ * @return a {@code FilterChain} instance that will execute the named chain and then finally the
+ * specified {@code original} FilterChain instance.
+ * @throws IllegalArgumentException if there is no configured chain with the given {@code chainName}.
+ */
+ FilterChain proxy(FilterChain original, String chainName);
+
+ /**
+ * Adds a filter to the 'pool' of available filters that can be used when
+ * {@link #addToChain(String, String, String) creating filter chains}.
+ * <p/>
+ * Calling this method is effectively the same as calling
+ * <code>{@link #addFilter(String, javax.servlet.Filter, boolean) addFilter}(name, filter, <b>true</b>);</code>
+ *
+ * @param name the name to assign to the filter, used to reference the filter in chain definitions
+ * @param filter the filter to initialize and then add to the pool of available filters that can be used
+ */
+ void addFilter(String name, Filter filter);
+
+ /**
+ * Adds a filter to the 'pool' of available filters that can be used when
+ * {@link #addToChain(String, String, String) creating filter chains}.
+ *
+ * @param name the name to assign to the filter, used to reference the filter in chain definitions
+ * @param filter the filter to assign to the filter pool
+ * @param init whether or not the {@code Filter} should be
+ * {@link Filter#init(javax.servlet.FilterConfig) initialized} first before being added to the pool.
+ */
+ void addFilter(String name, Filter filter, boolean init);
+
+ /**
+ * Creates a filter chain for the given {@code chainName} with the specified {@code chainDefinition}
+ * String.
+ * <h3>Conventional Use</h3>
+ * Because the {@code FilterChainManager} interface does not impose any restrictions on filter chain names,
+ * (it expects only Strings), a convenient convention is to make the chain name an actual URL path expression
+ * (such as an {@link org.apache.shiro.util.AntPathMatcher Ant path expression}). For example:
+ * <p/>
+ * <code>createChain(<b><em>path_expression</em></b>, <em>path_specific_filter_chain_definition</em>);</code>
+ * This convention can be used by a {@link FilterChainResolver} to inspect request URL paths
+ * against the chain name (path) and, if a match is found, return the corresponding chain for runtime filtering.
+ * <h3>Chain Definition Format</h3>
+ * The {@code chainDefinition} method argument is expected to conform to the following format:
+ * <pre>
+ * filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN]</pre>
+ * where
+ * <ol>
+ * <li>{@code filterN} is the name of a filter previously
+ * {@link #addFilter(String, javax.servlet.Filter) registered} with the manager, and</li>
+ * <li>{@code [optional_configN]} is an optional bracketed string that has meaning for that particular filter for
+ * <em>this particular chain</em></li>
+ * </ol>
+ * If the filter does not need specific config for that chain name/URL path,
+ * you may discard the brackets - that is, {@code filterN[]} just becomes {@code filterN}.
+ * <p/>
+ * And because this method does create a chain, remember that order matters! The comma-delimited filter tokens in
+ * the {@code chainDefinition} specify the chain's execution order.
+ * <h3>Examples</h3>
+ * <pre>/account/** = authcBasic</pre>
+ * This example says "Create a filter named '{@code /account/**}' consisting of only the '{@code authcBasic}'
+ * filter". Also because the {@code authcBasic} filter does not need any path-specific
+ * config, it doesn't have any config brackets {@code []}.
+ * <p/>
+ * <pre>/remoting/** = authcBasic, roles[b2bClient], perms["remote:invoke:wan,lan"]</pre>
+ * This example by contrast uses the 'roles' and 'perms' filters which <em>do</em> use bracket notation. This
+ * definition says:
+ * <p/>
+ * Construct a filter chain named '{@code /remoting/**}' which
+ * <ol>
+ * <li>ensures the user is first authenticated ({@code authcBasic}) then</li>
+ * <li>ensures that user has the {@code b2bClient} role, and then finally</li>
+ * <li>ensures that they have the {@code remote:invoke:lan,wan} permission.</li>
+ * </ol>
+ * <p/>
+ * <b>Note</b>: because elements within brackets [ ] can be comma-delimited themselves, you must quote the
+ * internal bracket definition if commas are needed (the above example has 'lan,wan'). If we didn't do that, the
+ * parser would interpret the chain definition as four tokens:
+ * <ol>
+ * <li>authcBasic</li>
+ * <li>roles[b2bclient]</li>
+ * <li>perms[remote:invoke:lan</li>
+ * <li>wan]</li>
+ * </ol>
+ * which is obviously incorrect. So remember to use quotes if your internal bracket definitions need to use commas.
+ *
+ * @param chainName the name to associate with the chain, conventionally a URL path pattern.
+ * @param chainDefinition the string-formatted chain definition used to construct an actual
+ * {@link NamedFilterList} chain instance.
+ * @see FilterChainResolver
+ * @see org.apache.shiro.util.AntPathMatcher AntPathMatcher
+ */
+ void createChain(String chainName, String chainDefinition);
+
+ /**
+ * Adds (appends) a filter to the filter chain identified by the given {@code chainName}. If there is no chain
+ * with the given name, a new one is created and the filter will be the first in the chain.
+ *
+ * @param chainName the name of the chain where the filter will be appended.
+ * @param filterName the name of the {@link #addFilter registered} filter to add to the chain.
+ * @throws IllegalArgumentException if there is not a {@link #addFilter(String, javax.servlet.Filter) registered}
+ * filter under the given {@code filterName}
+ */
+ void addToChain(String chainName, String filterName);
+
+ /**
+ * Adds (appends) a filter to the filter chain identified by the given {@code chainName}. If there is no chain
+ * with the given name, a new one is created and the filter will be the first in the chain.
+ * <p/>
+ * Note that the final argument expects the associated filter to be an instance of
+ * a {@link org.apache.shiro.web.filter.PathConfigProcessor PathConfigProcessor} to accept per-chain configuration.
+ * If it is not, a {@link IllegalArgumentException} will be thrown.
+ *
+ * @param chainName the name of the chain where the filter will be appended.
+ * @param filterName the name of the {@link #addFilter registered} filter to add to the chain.
+ * @param chainSpecificFilterConfig the filter-specific configuration that should be applied for only the specified
+ * filter chain.
+ * @throws IllegalArgumentException if there is not a {@link #addFilter(String, javax.servlet.Filter) registered}
+ * filter under the given {@code filterName}
+ * @throws ConfigurationException if the filter is not capable of accepting {@code chainSpecificFilterConfig}
+ * (usually such filters implement the
+ * {@link org.apache.shiro.web.filter.PathConfigProcessor PathConfigProcessor}
+ * interface).
+ */
+ void addToChain(String chainName, String filterName, String chainSpecificFilterConfig) throws ConfigurationException;
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainResolver.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainResolver.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainResolver.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainResolver.java Wed May 26 18:34:28 2010
@@ -1,54 +1,54 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-/**
- * A {@code FilterChainResolver} can resolve an appropriate {@link FilterChain} to execute during a
- * {@code ServletRequest}. It allows resolution of arbitrary filter chains which can be executed for any given
- * request or URI/URL.
- * <p/>
- * This mechanism allows for a much more flexible FilterChain resolution than normal {@code web.xml} servlet filter
- * definitions: it allows arbitrary filter chains to be defined per URL in a much more concise and easy to read manner,
- * and even allows filter chains to be dynamically resolved or constructed at runtime if the underlying implementation
- * supports it.
- *
- * @since 1.0
- */
-public interface FilterChainResolver {
-
- /**
- * Returns the filter chain that should be executed for the given request, or {@code null} if the
- * original chain should be used.
- * <p/>
- * This method allows a implementation to define arbitrary security {@link javax.servlet.Filter Filter}
- * chains for any given request or URL pattern.
- *
- * @param request the incoming ServletRequest
- * @param response the outgoing ServletResponse
- * @param originalChain the original {@code FilterChain} intercepted by the ShiroFilter implementation.
- * @return the filter chain that should be executed for the given request, or {@code null} if the
- * original chain should be used.
- */
- FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain);
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A {@code FilterChainResolver} can resolve an appropriate {@link FilterChain} to execute during a
+ * {@code ServletRequest}. It allows resolution of arbitrary filter chains which can be executed for any given
+ * request or URI/URL.
+ * <p/>
+ * This mechanism allows for a much more flexible FilterChain resolution than normal {@code web.xml} servlet filter
+ * definitions: it allows arbitrary filter chains to be defined per URL in a much more concise and easy to read manner,
+ * and even allows filter chains to be dynamically resolved or constructed at runtime if the underlying implementation
+ * supports it.
+ *
+ * @since 1.0
+ */
+public interface FilterChainResolver {
+
+ /**
+ * Returns the filter chain that should be executed for the given request, or {@code null} if the
+ * original chain should be used.
+ * <p/>
+ * This method allows a implementation to define arbitrary security {@link javax.servlet.Filter Filter}
+ * chains for any given request or URL pattern.
+ *
+ * @param request the incoming ServletRequest
+ * @param response the outgoing ServletResponse
+ * @param originalChain the original {@code FilterChain} intercepted by the ShiroFilter implementation.
+ * @return the filter chain that should be executed for the given request, or {@code null} if the
+ * original chain should be used.
+ */
+ FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain);
+
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/FilterChainResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/NamedFilterList.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/NamedFilterList.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/NamedFilterList.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/NamedFilterList.java Wed May 26 18:34:28 2010
@@ -1,51 +1,51 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import java.util.List;
-
-/**
- * A {@code NamedFilterList} is a {@code List} of {@code Filter} instances that is uniquely identified by a
- * {@link #getName() name}. It has the ability to generate new {@link FilterChain} instances reflecting this list's
- * filter order via the {@link #proxy proxy} method.
- *
- * @author Les Hazlewood
- * @since 1.0
- */
-public interface NamedFilterList extends List<Filter> {
-
- /**
- * Returns the configuration-unique name assigned to this {@code Filter} list.
- *
- * @return the configuration-unique name assigned to this {@code Filter} list.
- */
- String getName();
-
- /**
- * Returns a new {@code FilterChain} instance that will first execute this list's {@code Filter}s (in list order)
- * and end with the execution of the given {@code filterChain} instance.
- *
- * @param filterChain the {@code FilterChain} instance to execute after this list's {@code Filter}s have executed.
- * @return a new {@code FilterChain} instance that will first execute this list's {@code Filter}s (in list order)
- * and end with the execution of the given {@code filterChain} instance.
- */
- FilterChain proxy(FilterChain filterChain);
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import java.util.List;
+
+/**
+ * A {@code NamedFilterList} is a {@code List} of {@code Filter} instances that is uniquely identified by a
+ * {@link #getName() name}. It has the ability to generate new {@link FilterChain} instances reflecting this list's
+ * filter order via the {@link #proxy proxy} method.
+ *
+ * @author Les Hazlewood
+ * @since 1.0
+ */
+public interface NamedFilterList extends List<Filter> {
+
+ /**
+ * Returns the configuration-unique name assigned to this {@code Filter} list.
+ *
+ * @return the configuration-unique name assigned to this {@code Filter} list.
+ */
+ String getName();
+
+ /**
+ * Returns a new {@code FilterChain} instance that will first execute this list's {@code Filter}s (in list order)
+ * and end with the execution of the given {@code filterChain} instance.
+ *
+ * @param filterChain the {@code FilterChain} instance to execute after this list's {@code Filter}s have executed.
+ * @return a new {@code FilterChain} instance that will first execute this list's {@code Filter}s (in list order)
+ * and end with the execution of the given {@code filterChain} instance.
+ */
+ FilterChain proxy(FilterChain filterChain);
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/NamedFilterList.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java Wed May 26 18:34:28 2010
@@ -1,149 +1,149 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import org.apache.shiro.util.AntPathMatcher;
-import org.apache.shiro.util.PatternMatcher;
-import org.apache.shiro.web.util.WebUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-/**
- * A {@code FilterChainResolver} that resolves {@link FilterChain}s based on url path
- * matching, as determined by a configurable {@link #setPathMatcher(org.apache.shiro.util.PatternMatcher) PathMatcher}.
- * <p/>
- * This implementation functions by consulting a {@link org.apache.shiro.web.filter.mgt.FilterChainManager} for all configured filter chains (keyed
- * by configured path pattern). If an incoming Request path matches one of the configured path patterns (via
- * the {@code PathMatcher}, the corresponding configured {@code FilterChain} is returned.
- *
- * @since 1.0
- */
-public class PathMatchingFilterChainResolver implements FilterChainResolver {
-
- private static transient final Logger log = LoggerFactory.getLogger(PathMatchingFilterChainResolver.class);
-
- private FilterChainManager filterChainManager;
-
- private PatternMatcher pathMatcher;
-
- public PathMatchingFilterChainResolver() {
- this.pathMatcher = new AntPathMatcher();
- this.filterChainManager = new DefaultFilterChainManager();
- }
-
- public PathMatchingFilterChainResolver(FilterConfig filterConfig) {
- this.pathMatcher = new AntPathMatcher();
- this.filterChainManager = new DefaultFilterChainManager(filterConfig);
- }
-
- /**
- * Returns the {@code PatternMatcher} used when determining if an incoming request's path
- * matches a configured filter chain. Unless overridden, the
- * default implementation is an {@link org.apache.shiro.util.AntPathMatcher AntPathMatcher}.
- *
- * @return the {@code PatternMatcher} used when determining if an incoming request's path
- * matches a configured filter chain.
- */
- public PatternMatcher getPathMatcher() {
- return pathMatcher;
- }
-
- /**
- * Sets the {@code PatternMatcher} used when determining if an incoming request's path
- * matches a configured filter chain. Unless overridden, the
- * default implementation is an {@link org.apache.shiro.util.AntPathMatcher AntPathMatcher}.
- *
- * @param pathMatcher the {@code PatternMatcher} used when determining if an incoming request's path
- * matches a configured filter chain.
- */
- public void setPathMatcher(PatternMatcher pathMatcher) {
- this.pathMatcher = pathMatcher;
- }
-
- public FilterChainManager getFilterChainManager() {
- return filterChainManager;
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void setFilterChainManager(FilterChainManager filterChainManager) {
- this.filterChainManager = filterChainManager;
- }
-
- public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) {
- FilterChainManager filterChainManager = getFilterChainManager();
- if (!filterChainManager.hasChains()) {
- return null;
- }
-
- String requestURI = getPathWithinApplication(request);
-
- //the 'chain names' in this implementation are actually path patterns defined by the user. We just use them
- //as the chain name for the FilterChainManager's requirements
- for (String pathPattern : filterChainManager.getChainNames()) {
-
- // If the path does match, then pass on to the subclass implementation for specific checks:
- if (pathMatches(pathPattern, requestURI)) {
- if (log.isTraceEnabled()) {
- log.trace("Matched path pattern [" + pathPattern + "] for requestURI [" + requestURI + "]. " +
- "Utilizing corresponding filter chain...");
- }
- return filterChainManager.proxy(originalChain, pathPattern);
- }
- }
-
- return null;
- }
-
- /**
- * Returns {@code true} if an incoming request path (the {@code path} argument)
- * matches a configured filter chain path (the {@code pattern} argument), {@code false} otherwise.
- * <p/>
- * Simply delegates to
- * <b><code>{@link #getPathMatcher() getPathMatcher()}.{@link org.apache.shiro.util.PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>.
- * Subclass implementors should think carefully before overriding this method, as typically a custom
- * {@code PathMatcher} should be configured for custom path matching behavior instead. Favor OO composition
- * rather than inheritance to limit your exposure to Shiro implementation details which may change over time.
- *
- * @param pattern the pattern to match against
- * @param path the value to match with the specified {@code pattern}
- * @return {@code true} if the request {@code path} matches the specified filter chain url {@code pattern},
- * {@code false} otherwise.
- */
- protected boolean pathMatches(String pattern, String path) {
- PatternMatcher pathMatcher = getPathMatcher();
- return pathMatcher.matches(pattern, path);
- }
-
- /**
- * Merely returns
- * <code>WebUtils.{@link org.apache.shiro.web.util.WebUtils#getPathWithinApplication(javax.servlet.http.HttpServletRequest) getPathWithinApplication(request)}</code>
- * and can be overridden by subclasses for custom request-to-application-path resolution behavior.
- *
- * @param request the incoming {@code ServletRequest}
- * @return the request's path within the appliation.
- */
- protected String getPathWithinApplication(ServletRequest request) {
- return WebUtils.getPathWithinApplication(WebUtils.toHttp(request));
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import org.apache.shiro.util.AntPathMatcher;
+import org.apache.shiro.util.PatternMatcher;
+import org.apache.shiro.web.util.WebUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A {@code FilterChainResolver} that resolves {@link FilterChain}s based on url path
+ * matching, as determined by a configurable {@link #setPathMatcher(org.apache.shiro.util.PatternMatcher) PathMatcher}.
+ * <p/>
+ * This implementation functions by consulting a {@link org.apache.shiro.web.filter.mgt.FilterChainManager} for all configured filter chains (keyed
+ * by configured path pattern). If an incoming Request path matches one of the configured path patterns (via
+ * the {@code PathMatcher}, the corresponding configured {@code FilterChain} is returned.
+ *
+ * @since 1.0
+ */
+public class PathMatchingFilterChainResolver implements FilterChainResolver {
+
+ private static transient final Logger log = LoggerFactory.getLogger(PathMatchingFilterChainResolver.class);
+
+ private FilterChainManager filterChainManager;
+
+ private PatternMatcher pathMatcher;
+
+ public PathMatchingFilterChainResolver() {
+ this.pathMatcher = new AntPathMatcher();
+ this.filterChainManager = new DefaultFilterChainManager();
+ }
+
+ public PathMatchingFilterChainResolver(FilterConfig filterConfig) {
+ this.pathMatcher = new AntPathMatcher();
+ this.filterChainManager = new DefaultFilterChainManager(filterConfig);
+ }
+
+ /**
+ * Returns the {@code PatternMatcher} used when determining if an incoming request's path
+ * matches a configured filter chain. Unless overridden, the
+ * default implementation is an {@link org.apache.shiro.util.AntPathMatcher AntPathMatcher}.
+ *
+ * @return the {@code PatternMatcher} used when determining if an incoming request's path
+ * matches a configured filter chain.
+ */
+ public PatternMatcher getPathMatcher() {
+ return pathMatcher;
+ }
+
+ /**
+ * Sets the {@code PatternMatcher} used when determining if an incoming request's path
+ * matches a configured filter chain. Unless overridden, the
+ * default implementation is an {@link org.apache.shiro.util.AntPathMatcher AntPathMatcher}.
+ *
+ * @param pathMatcher the {@code PatternMatcher} used when determining if an incoming request's path
+ * matches a configured filter chain.
+ */
+ public void setPathMatcher(PatternMatcher pathMatcher) {
+ this.pathMatcher = pathMatcher;
+ }
+
+ public FilterChainManager getFilterChainManager() {
+ return filterChainManager;
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void setFilterChainManager(FilterChainManager filterChainManager) {
+ this.filterChainManager = filterChainManager;
+ }
+
+ public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) {
+ FilterChainManager filterChainManager = getFilterChainManager();
+ if (!filterChainManager.hasChains()) {
+ return null;
+ }
+
+ String requestURI = getPathWithinApplication(request);
+
+ //the 'chain names' in this implementation are actually path patterns defined by the user. We just use them
+ //as the chain name for the FilterChainManager's requirements
+ for (String pathPattern : filterChainManager.getChainNames()) {
+
+ // If the path does match, then pass on to the subclass implementation for specific checks:
+ if (pathMatches(pathPattern, requestURI)) {
+ if (log.isTraceEnabled()) {
+ log.trace("Matched path pattern [" + pathPattern + "] for requestURI [" + requestURI + "]. " +
+ "Utilizing corresponding filter chain...");
+ }
+ return filterChainManager.proxy(originalChain, pathPattern);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns {@code true} if an incoming request path (the {@code path} argument)
+ * matches a configured filter chain path (the {@code pattern} argument), {@code false} otherwise.
+ * <p/>
+ * Simply delegates to
+ * <b><code>{@link #getPathMatcher() getPathMatcher()}.{@link org.apache.shiro.util.PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>.
+ * Subclass implementors should think carefully before overriding this method, as typically a custom
+ * {@code PathMatcher} should be configured for custom path matching behavior instead. Favor OO composition
+ * rather than inheritance to limit your exposure to Shiro implementation details which may change over time.
+ *
+ * @param pattern the pattern to match against
+ * @param path the value to match with the specified {@code pattern}
+ * @return {@code true} if the request {@code path} matches the specified filter chain url {@code pattern},
+ * {@code false} otherwise.
+ */
+ protected boolean pathMatches(String pattern, String path) {
+ PatternMatcher pathMatcher = getPathMatcher();
+ return pathMatcher.matches(pattern, path);
+ }
+
+ /**
+ * Merely returns
+ * <code>WebUtils.{@link org.apache.shiro.web.util.WebUtils#getPathWithinApplication(javax.servlet.http.HttpServletRequest) getPathWithinApplication(request)}</code>
+ * and can be overridden by subclasses for custom request-to-application-path resolution behavior.
+ *
+ * @param request the incoming {@code ServletRequest}
+ * @return the request's path within the appliation.
+ */
+ protected String getPathWithinApplication(ServletRequest request) {
+ return WebUtils.getPathWithinApplication(WebUtils.toHttp(request));
+ }
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterList.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterList.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterList.java (original)
+++ incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterList.java Wed May 26 18:34:28 2010
@@ -1,174 +1,174 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.web.filter.mgt;
-
-import org.apache.shiro.util.StringUtils;
-import org.apache.shiro.web.servlet.ProxiedFilterChain;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import java.util.*;
-
-/**
- * Simple {@code NamedFilterList} implementation that is supported by a backing {@link List} instance and a simple
- * {@link #getName() name} property. All {@link List} method implementations are immediately delegated to the
- * wrapped backing list.
- *
- * @since 1.0
- */
-public class SimpleNamedFilterList implements NamedFilterList {
-
- private String name;
- private List<Filter> backingList;
-
- /**
- * Creates a new {@code SimpleNamedFilterList} instance with the specified {@code name}, defaulting to a new
- * {@link ArrayList ArrayList} instance as the backing list.
- *
- * @param name the name to assign to this instance.
- * @throws IllegalArgumentException if {@code name} is null or empty.
- */
- public SimpleNamedFilterList(String name) {
- this(name, new ArrayList<Filter>());
- }
-
- /**
- * Creates a new {@code SimpleNamedFilterList} instance with the specified {@code name} and {@code backingList}.
- *
- * @param name the name to assign to this instance.
- * @param backingList the list instance used to back all of this class's {@link List} method implementations.
- * @throws IllegalArgumentException if {@code name} is null or empty.
- * @throws NullPointerException if the backing list is {@code null}.
- */
- public SimpleNamedFilterList(String name, List<Filter> backingList) {
- if (backingList == null) {
- throw new NullPointerException("backingList constructor argument cannot be null.");
- }
- this.backingList = backingList;
- setName(name);
- }
-
- protected void setName(String name) {
- if (!StringUtils.hasText(name)) {
- throw new IllegalArgumentException("Cannot specify a null or empty name.");
- }
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public FilterChain proxy(FilterChain orig) {
- return new ProxiedFilterChain(orig, this);
- }
-
- public boolean add(Filter filter) {
- return this.backingList.add(filter);
- }
-
- public void add(int index, Filter filter) {
- this.backingList.add(index, filter);
- }
-
- public boolean addAll(Collection<? extends Filter> c) {
- return this.backingList.addAll(c);
- }
-
- public boolean addAll(int index, Collection<? extends Filter> c) {
- return this.backingList.addAll(index, c);
- }
-
- public void clear() {
- this.backingList.clear();
- }
-
- public boolean contains(Object o) {
- return this.backingList.contains(o);
- }
-
- public boolean containsAll(Collection<?> c) {
- return this.backingList.containsAll(c);
- }
-
- public Filter get(int index) {
- return this.backingList.get(index);
- }
-
- public int indexOf(Object o) {
- return this.backingList.indexOf(o);
- }
-
- public boolean isEmpty() {
- return this.backingList.isEmpty();
- }
-
- public Iterator<Filter> iterator() {
- return this.backingList.iterator();
- }
-
- public int lastIndexOf(Object o) {
- return this.backingList.lastIndexOf(o);
- }
-
- public ListIterator<Filter> listIterator() {
- return this.backingList.listIterator();
- }
-
- public ListIterator<Filter> listIterator(int index) {
- return this.backingList.listIterator(index);
- }
-
- public Filter remove(int index) {
- return this.backingList.remove(index);
- }
-
- public boolean remove(Object o) {
- return this.backingList.remove(o);
- }
-
- public boolean removeAll(Collection<?> c) {
- return this.backingList.removeAll(c);
- }
-
- public boolean retainAll(Collection<?> c) {
- return this.backingList.retainAll(c);
- }
-
- public Filter set(int index, Filter filter) {
- return this.backingList.set(index, filter);
- }
-
- public int size() {
- return this.backingList.size();
- }
-
- public List<Filter> subList(int fromIndex, int toIndex) {
- return this.backingList.subList(fromIndex, toIndex);
- }
-
- public Object[] toArray() {
- return this.backingList.toArray();
- }
-
- public <T> T[] toArray(T[] a) {
- //noinspection SuspiciousToArrayCall
- return this.backingList.toArray(a);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.web.filter.mgt;
+
+import org.apache.shiro.util.StringUtils;
+import org.apache.shiro.web.servlet.ProxiedFilterChain;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import java.util.*;
+
+/**
+ * Simple {@code NamedFilterList} implementation that is supported by a backing {@link List} instance and a simple
+ * {@link #getName() name} property. All {@link List} method implementations are immediately delegated to the
+ * wrapped backing list.
+ *
+ * @since 1.0
+ */
+public class SimpleNamedFilterList implements NamedFilterList {
+
+ private String name;
+ private List<Filter> backingList;
+
+ /**
+ * Creates a new {@code SimpleNamedFilterList} instance with the specified {@code name}, defaulting to a new
+ * {@link ArrayList ArrayList} instance as the backing list.
+ *
+ * @param name the name to assign to this instance.
+ * @throws IllegalArgumentException if {@code name} is null or empty.
+ */
+ public SimpleNamedFilterList(String name) {
+ this(name, new ArrayList<Filter>());
+ }
+
+ /**
+ * Creates a new {@code SimpleNamedFilterList} instance with the specified {@code name} and {@code backingList}.
+ *
+ * @param name the name to assign to this instance.
+ * @param backingList the list instance used to back all of this class's {@link List} method implementations.
+ * @throws IllegalArgumentException if {@code name} is null or empty.
+ * @throws NullPointerException if the backing list is {@code null}.
+ */
+ public SimpleNamedFilterList(String name, List<Filter> backingList) {
+ if (backingList == null) {
+ throw new NullPointerException("backingList constructor argument cannot be null.");
+ }
+ this.backingList = backingList;
+ setName(name);
+ }
+
+ protected void setName(String name) {
+ if (!StringUtils.hasText(name)) {
+ throw new IllegalArgumentException("Cannot specify a null or empty name.");
+ }
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public FilterChain proxy(FilterChain orig) {
+ return new ProxiedFilterChain(orig, this);
+ }
+
+ public boolean add(Filter filter) {
+ return this.backingList.add(filter);
+ }
+
+ public void add(int index, Filter filter) {
+ this.backingList.add(index, filter);
+ }
+
+ public boolean addAll(Collection<? extends Filter> c) {
+ return this.backingList.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends Filter> c) {
+ return this.backingList.addAll(index, c);
+ }
+
+ public void clear() {
+ this.backingList.clear();
+ }
+
+ public boolean contains(Object o) {
+ return this.backingList.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return this.backingList.containsAll(c);
+ }
+
+ public Filter get(int index) {
+ return this.backingList.get(index);
+ }
+
+ public int indexOf(Object o) {
+ return this.backingList.indexOf(o);
+ }
+
+ public boolean isEmpty() {
+ return this.backingList.isEmpty();
+ }
+
+ public Iterator<Filter> iterator() {
+ return this.backingList.iterator();
+ }
+
+ public int lastIndexOf(Object o) {
+ return this.backingList.lastIndexOf(o);
+ }
+
+ public ListIterator<Filter> listIterator() {
+ return this.backingList.listIterator();
+ }
+
+ public ListIterator<Filter> listIterator(int index) {
+ return this.backingList.listIterator(index);
+ }
+
+ public Filter remove(int index) {
+ return this.backingList.remove(index);
+ }
+
+ public boolean remove(Object o) {
+ return this.backingList.remove(o);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return this.backingList.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return this.backingList.retainAll(c);
+ }
+
+ public Filter set(int index, Filter filter) {
+ return this.backingList.set(index, filter);
+ }
+
+ public int size() {
+ return this.backingList.size();
+ }
+
+ public List<Filter> subList(int fromIndex, int toIndex) {
+ return this.backingList.subList(fromIndex, toIndex);
+ }
+
+ public Object[] toArray() {
+ return this.backingList.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ //noinspection SuspiciousToArrayCall
+ return this.backingList.toArray(a);
+ }
+}
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/SimpleNamedFilterList.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/mgt/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/filter/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/mgt/CookieRememberMeManager.java
------------------------------------------------------------------------------
svn:eol-style = native