JSecurity

org.jsecurity.web.config
Class IniWebConfiguration

java.lang.Object
  extended by org.jsecurity.config.ResourceConfiguration
      extended by org.jsecurity.config.TextConfiguration
          extended by org.jsecurity.config.IniConfiguration
              extended by org.jsecurity.web.config.IniWebConfiguration
All Implemented Interfaces:
Serializable, Configuration, SecurityManagerFactory, Initializable, WebConfiguration
Direct Known Subclasses:
SpringIniWebConfiguration

public class IniWebConfiguration
extends IniConfiguration
implements WebConfiguration

A WebConfiguration that supports configuration via the .ini format.

Since:
Jun 1, 2008 11:02:44 PM
Author:
Les Hazlewood
See Also:
Serialized Form

Field Summary
protected  Map<String,List<Filter>> chains
           
protected  FilterConfig filterConfig
           
static String FILTERS
           
protected  PatternMatcher pathMatcher
           
static String URLS
           
 
Fields inherited from class org.jsecurity.config.IniConfiguration
configUrl, DEFAULT_INI_RESOURCE_PATH, ignoreResourceNotFound, iniResource, MAIN, SESSION_MODE_PROPERTY_NAME
 
Fields inherited from class org.jsecurity.config.ResourceConfiguration
securityManager
 
Constructor Summary
IniWebConfiguration()
           
 
Method Summary
protected  void afterSecurityManagerSet(Map<String,Map<String,String>> sections)
          This implementation: First builds the filter instances by processing the [filters] section Builds a collection filter chains according to the definitions in the [urls] section Initializes the filter instances in the order in which they were defined
protected  void assertFilter(String name, Object o)
           
protected  void assertFilters(Map<String,?> map)
           
protected  FilterChain createChain(List<Filter> filters, FilterChain originalChain)
          Creates a new FilterChain based on the specified configured url filter chain and original chain.
 Map<String,List<Filter>> createChains(Map<String,String> urls, Map<String,Filter> filters)
           
protected  Map<String,Filter> createDefaultFilters()
           
 FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain)
          Returns the filter chain that should be executed for the given request, or null if the original chain should be used.
protected  FilterChain getChain(String chainUrl, FilterChain originalChain)
          Returns the FilterChain to use for the specified application path, or null if the original FilterChain should be used.
 FilterConfig getFilterConfig()
          Returns the FilterConfig provided by the Servlet container at webapp startup.
protected  Map<String,Filter> getFilters(Map<String,String> section)
           
 PatternMatcher getPathMatcher()
          Returns the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section.
protected  String getPathWithinApplication(ServletRequest request)
          Merely returns WebUtils.
protected  void initFilter(Filter filter)
          Initializes the filter by calling filter.init( getFilterConfig() );.
protected  void initFilters(Map<String,List<Filter>> chains)
           
protected  RealmSecurityManager newSecurityManagerInstance()
          Creates a new, uninitialized SecurityManager instance that will be used to build up the JSecurity environment for the web application.
protected  boolean pathMatches(String pattern, String path)
          Returns true if an incoming request's path (the path argument) matches a configured filter chain path in the [urls] section (the pattern argument), false otherwise.
 void setFilterConfig(FilterConfig filterConfig)
          Sets the FilterConfig provided by the Servlet container at webapp startup.
 void setPathMatcher(PatternMatcher pathMatcher)
          Sets the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section.
 
Methods inherited from class org.jsecurity.config.IniConfiguration
createDefaultSecurityManager, createSecurityManager, createSecurityManagerForSection, getConfigUrl, init, load, load, load, load, process, processIni, setConfigUrl
 
Methods inherited from class org.jsecurity.config.TextConfiguration
getConfig, loadTextConfig, setConfig
 
Methods inherited from class org.jsecurity.config.ResourceConfiguration
getSecurityManager, setSecurityManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jsecurity.mgt.SecurityManagerFactory
getSecurityManager
 

Field Detail

FILTERS

public static final String FILTERS
See Also:
Constant Field Values

URLS

public static final String URLS
See Also:
Constant Field Values

filterConfig

protected FilterConfig filterConfig

chains

protected Map<String,List<Filter>> chains

pathMatcher

protected PatternMatcher pathMatcher
Constructor Detail

IniWebConfiguration

public IniWebConfiguration()
Method Detail

getPathMatcher

public PatternMatcher getPathMatcher()
Returns the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section. Unless overridden, the default implementation is an AntPathMatcher.

Returns:
the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section.
Since:
0.9.0

setPathMatcher

public void setPathMatcher(PatternMatcher pathMatcher)
Sets the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section. Unless overridden, the default implementation is an AntPathMatcher.

Parameters:
pathMatcher - the PatternMatcher used when determining if an incoming request's path matches a configured filter chain path in the [urls] section.
Since:
0.9.0

getFilterConfig

public FilterConfig getFilterConfig()
Returns the FilterConfig provided by the Servlet container at webapp startup.

Returns:
the FilterConfig provided by the Servlet container at webapp startup.

setFilterConfig

public void setFilterConfig(FilterConfig filterConfig)
Sets the FilterConfig provided by the Servlet container at webapp startup.

Parameters:
filterConfig - the FilterConfig provided by the Servlet container at webapp startup.

getChain

public FilterChain getChain(ServletRequest request,
                            ServletResponse response,
                            FilterChain originalChain)
Description copied from interface: WebConfiguration
Returns the filter chain that should be executed for the given request, or null if the original chain should be used.

This method allows a Configuration implementation to define arbitrary security Filter chains for any given request or URL pattern.

Specified by:
getChain in interface WebConfiguration
Parameters:
request - the incoming ServletRequest
response - the outgoing ServletResponse
originalChain - the original FilterChain intercepted by the JSecurityFilter.
Returns:
the filter chain that should be executed for the given request, or null if the original chain should be used.

getChain

protected FilterChain getChain(String chainUrl,
                               FilterChain originalChain)
Returns the FilterChain to use for the specified application path, or null if the original FilterChain should be used.

The default implementation simply calls this.chains.get(chainUrl) to acquire the configured List<Filter> filter chain. If that configured chain is non-null and not empty, it is returned, otherwise null is returned to indicate that the originalChain should be used instead.

Parameters:
chainUrl - the configured filter chain url
originalChain - the original FilterChain given by the Servlet container.
Returns:
the FilterChain to use for the specified application path, or null if the original FilterChain should be used.

createChain

protected FilterChain createChain(List<Filter> filters,
                                  FilterChain originalChain)
Creates a new FilterChain based on the specified configured url filter chain and original chain.

The input arguments are expected be be non-null and non-empty, since these conditions are accounted for in the getChain(chainUrl,originalChain) implementation that calls this method.

The default implementation merely returns new FilterChainWrapper(filters, originalChain), and can be overridden by subclasses for custom creation.

Parameters:
filters - the configured filter chain for the incoming request application path
originalChain - the original FilterChain given by the Servlet container.
Returns:
a new FilterChain based on the specified configured url filter chain and original chain.

pathMatches

protected boolean pathMatches(String pattern,
                              String path)
Returns true if an incoming request's path (the path argument) matches a configured filter chain path in the [urls] section (the pattern argument), false otherwise.

Simply delegates to getPathMatcher().matches(pattern,path), but can be overridden by subclasses for custom matching behavior.

Parameters:
pattern - the pattern to match against
path - the value to match with the specified pattern
Returns:
true if the request path matches the specified filter chain url pattern, false otherwise.

getPathWithinApplication

protected String getPathWithinApplication(ServletRequest request)
Merely returns WebUtils.getPathWithinApplication(request) and can be overridden by subclasses for custom request-to-application-path resolution behavior.

Parameters:
request - the incoming ServletRequest
Returns:
the request's path within the appliation.

newSecurityManagerInstance

protected RealmSecurityManager newSecurityManagerInstance()
Creates a new, uninitialized SecurityManager instance that will be used to build up the JSecurity environment for the web application.

The default implementation simply returns new DefaultWebSecurityManager();

Overrides:
newSecurityManagerInstance in class IniConfiguration
Returns:
a new, uninitialized SecurityManager instance that will be used to build up the JSecurity environment for the web application.

afterSecurityManagerSet

protected void afterSecurityManagerSet(Map<String,Map<String,String>> sections)
This implementation:
  1. First builds the filter instances by processing the [filters] section
  2. Builds a collection filter chains according to the definitions in the [urls] section
  3. Initializes the filter instances in the order in which they were defined

Overrides:
afterSecurityManagerSet in class IniConfiguration
Parameters:
sections - the configured .ini sections where the key is the section name (without [] brackets) and the value is the key/value pairs inside that section.

initFilters

protected void initFilters(Map<String,List<Filter>> chains)

initFilter

protected void initFilter(Filter filter)
Initializes the filter by calling filter.init( getFilterConfig() );.

Parameters:
filter - the filter to initialize with the FilterConfig.

getFilters

protected Map<String,Filter> getFilters(Map<String,String> section)

assertFilters

protected void assertFilters(Map<String,?> map)

assertFilter

protected void assertFilter(String name,
                            Object o)
                     throws ConfigurationException
Throws:
ConfigurationException

createDefaultFilters

protected Map<String,Filter> createDefaultFilters()

createChains

public Map<String,List<Filter>> createChains(Map<String,String> urls,
                                             Map<String,Filter> filters)

JSecurity

Copyright © 2004-2008 JSecurity.