diff --git a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java index 2b4375baa4..cc6afb8c6c 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpConfigurationBuilder.java @@ -4,6 +4,7 @@ import static org.springframework.security.config.http.HttpSecurityBeanDefinitio import static org.springframework.security.config.http.SecurityFilters.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.springframework.beans.factory.config.BeanDefinition; @@ -74,6 +75,11 @@ class HttpConfigurationBuilder { private static final String ATT_REF = "ref"; + private static final String ATT_SECURED = "security"; + private static final String OPT_SECURITY_NONE = "none"; + private static final String OPT_SECURITY_CONTEXT_ONLY = "contextOnly"; + + private final Element httpElt; private final ParserContext pc; private final SessionCreationPolicy sessionPolicy; @@ -95,6 +101,7 @@ class HttpConfigurationBuilder { public HttpConfigurationBuilder(Element element, ParserContext pc, MatcherType matcherType, String portMapperName, BeanReference authenticationManager) { + this.httpElt = element; this.pc = pc; this.portMapperName = portMapperName; diff --git a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java index 04aeddeed6..f43e8422df 100644 --- a/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParser.java @@ -52,7 +52,9 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser { static final String ATT_REQUIRES_CHANNEL = "requires-channel"; private static final String ATT_REF = "ref"; - private static final String ATT_SECURED = "secured"; + private static final String ATT_SECURED = "security"; + private static final String OPT_SECURITY_NONE = "none"; + private static final String OPT_SECURITY_CONTEXT_ONLY = "contextOnly"; static final String EXPRESSION_FIMDS_CLASS = "org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource"; static final String EXPRESSION_HANDLER_CLASS = "org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"; @@ -97,9 +99,9 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser { } List createFilterChain(Element element, ParserContext pc, MatcherType matcherType) { - boolean unSecured = "false".equals(element.getAttribute(ATT_SECURED)); + String security = element.getAttribute(ATT_SECURED); - if (unSecured) { + if (StringUtils.hasText(security)) { if (!StringUtils.hasText(element.getAttribute(ATT_PATH_PATTERN))) { pc.getReaderContext().error("The '" + ATT_SECURED + "' attribute must be used in combination with" + " the '" + ATT_PATH_PATTERN +"' attribute.", pc.extractSource(element)); @@ -112,7 +114,11 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser { } } - return Collections.emptyList(); + if (security.equals(OPT_SECURITY_NONE)) { + return Collections.emptyList(); + } + + } final String portMapperName = createPortMapper(element, pc); diff --git a/config/src/main/resources/org/springframework/security/config/spring-security-3.1.rnc b/config/src/main/resources/org/springframework/security/config/spring-security-3.1.rnc index d4d1e13a72..056b6736ba 100644 --- a/config/src/main/resources/org/springframework/security/config/spring-security-3.1.rnc +++ b/config/src/main/resources/org/springframework/security/config/spring-security-3.1.rnc @@ -261,8 +261,8 @@ http.attlist &= ## The request URL pattern which will be mapped to the filter chain created by this element. If omitted, the filter chain will match all requests. attribute pattern {xsd:token}? http.attlist &= - ## When set to 'false', requests matching the pattern attribute will be ignored by Spring Security. No security filters will be applied and no SecurityContext will be available. If set, the element must be empty, with no children. - attribute secured {boolean}? + ## When set to 'none', requests matching the pattern attribute will be ignored by Spring Security. No security filters will be applied and no SecurityContext will be available. If set, the element must be empty, with no children. + attribute security {"none"}? http.attlist &= ## Automatically registers a login form, BASIC authentication, anonymous authentication, logout services, remember-me and servlet-api-integration. If set to "true", all of these capabilities are added (although you can still customize the configuration of each by providing the respective element). If unspecified, defaults to "false". diff --git a/config/src/main/resources/org/springframework/security/config/spring-security-3.1.xsd b/config/src/main/resources/org/springframework/security/config/spring-security-3.1.xsd index f238e20ac5..023e450aff 100644 --- a/config/src/main/resources/org/springframework/security/config/spring-security-3.1.xsd +++ b/config/src/main/resources/org/springframework/security/config/spring-security-3.1.xsd @@ -693,10 +693,15 @@ The request URL pattern which will be mapped to the filter chain created by this <http> element. If omitted, the filter chain will match all requests. - + - When set to 'false', requests matching the pattern attribute will be ignored by Spring Security. No security filters will be applied and no SecurityContext will be available. If set, the <http> element must be empty, with no children. + When set to 'none', requests matching the pattern attribute will be ignored by Spring Security. No security filters will be applied and no SecurityContext will be available. If set, the <http> element must be empty, with no children. + + + + + diff --git a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy index c78e5da9c6..7fb9a2d215 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/MiscHttpConfigTests.groovy @@ -86,7 +86,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { } def filterListShouldBeEmptyForPatternWithNoFilters() { - xml.http(pattern: '/unprotected', secured: 'false') + xml.http(pattern: '/unprotected', security: 'none') httpAutoConfig() {} createAppContext() @@ -95,7 +95,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { } def regexPathsWorkCorrectly() { - xml.http(pattern: '\\A\\/[a-z]+', secured: 'false', 'request-matcher': 'regex') + xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'regex') httpAutoConfig() {} createAppContext() @@ -106,7 +106,7 @@ class MiscHttpConfigTests extends AbstractHttpConfigTests { def ciRegexPathsWorkCorrectly() { when: - xml.http(pattern: '\\A\\/[a-z]+', secured: 'false', 'request-matcher': 'ciRegex') + xml.http(pattern: '\\A\\/[a-z]+', security: 'none', 'request-matcher': 'ciRegex') httpAutoConfig() {} createAppContext() diff --git a/config/src/test/groovy/org/springframework/security/config/http/PlaceHolderAndELConfigTests.groovy b/config/src/test/groovy/org/springframework/security/config/http/PlaceHolderAndELConfigTests.groovy index 242b0221b3..1a007dc0f8 100644 --- a/config/src/test/groovy/org/springframework/security/config/http/PlaceHolderAndELConfigTests.groovy +++ b/config/src/test/groovy/org/springframework/security/config/http/PlaceHolderAndELConfigTests.groovy @@ -24,7 +24,7 @@ class PlaceHolderAndELConfigTests extends AbstractHttpConfigTests { def unsecuredPatternSupportsPlaceholderForPattern() { System.setProperty("pattern.nofilters", "/unprotected"); - xml.http(pattern: '${pattern.nofilters}', secured: 'false') + xml.http(pattern: '${pattern.nofilters}', security: 'none') httpAutoConfig() { interceptUrl('/**', 'ROLE_A') } @@ -44,7 +44,7 @@ class PlaceHolderAndELConfigTests extends AbstractHttpConfigTests { System.setProperty("default.target", "/defaultTarget"); System.setProperty("auth.failure", "/authFailure"); - xml.http(pattern: '${login.page}', secured: 'false') + xml.http(pattern: '${login.page}', security: 'none') xml.http { interceptUrl('${secure.Url}', '${secure.role}') 'form-login'('login-page':'${login.page}', 'default-target-url': '${default.target}', diff --git a/config/src/test/resources/logback-test.xml b/config/src/test/resources/logback-test.xml index a53fe39b00..0bbb0e3369 100644 --- a/config/src/test/resources/logback-test.xml +++ b/config/src/test/resources/logback-test.xml @@ -7,8 +7,8 @@ - + - \ No newline at end of file + diff --git a/docs/manual/src/docbook/appendix-namespace.xml b/docs/manual/src/docbook/appendix-namespace.xml index 6ceb1b03b9..340ff7104a 100644 --- a/docs/manual/src/docbook/appendix-namespace.xml +++ b/docs/manual/src/docbook/appendix-namespace.xml @@ -8,114 +8,111 @@ and information on the underlying beans they create (a knowledge of the individual classes and how they work together is assumed - you can find more information in the project Javadoc and elsewhere in this document). If you haven't used the namespace before, please read the - introductory chapter on namespace configuration, as + introductory chapter on namespace configuration, as this is intended as a supplement to the information there. Using a good quality XML editor while editing a configuration based on the schema is recommended as this will provide contextual information on which elements and attributes are available as well as comments explaining their purpose. The namespace is written in RELAX NG Compact format and later converted - into an XSD schema. If you are familiar with this format, you may wish to examine the schema file directly. + xlink:href="http://www.relaxng.org/">RELAX NG Compact format and later converted into + an XSD schema. If you are familiar with this format, you may wish to examine the schema file directly.
Web Application Security - the <literal><http></literal> Element - If you use an <http> element within your application, - a FilterChainProxy bean named "springSecurityFilterChain" is created and - the configuration within the element is used to build a filter chain within + If you use an <http> element within your application, a + FilterChainProxy bean named "springSecurityFilterChain" is + created and the configuration within the element is used to build a filter chain within FilterChainProxy. As of Spring Security 3.1, additional http elements can be used to add extra filter chains - See the introductory chapter for how to - set up the mapping from your web.xml - . Some core filters are always created in a filter chain and others will be added - to the stack depending on the attributes and child elements which are present. The positions of the - standard filters are fixed (see the filter order - table in the namespace introduction), removing a common source of errors with - previous versions of the framework when users had to configure the filter chain - explicitly in theFilterChainProxy bean. You can, of course, still - do this if you need full control of the configuration. + See the introductory chapter for how to set + up the mapping from your web.xml + . Some core filters are always created in a filter chain and others will be + added to the stack depending on the attributes and child elements which are present. The + positions of the standard filters are fixed (see the + filter order table in the namespace introduction), removing a common source of + errors with previous versions of the framework when users had to configure the filter + chain explicitly in theFilterChainProxy bean. You can, of course, + still do this if you need full control of the configuration. All filters which require a reference to the - AuthenticationManager will be automatically injected - with the internal instance created by the namespace configuration (see the introductory chapter for more on the - AuthenticationManager). + AuthenticationManager will be automatically injected with + the internal instance created by the namespace configuration (see the introductory chapter for more on the + AuthenticationManager). Each <http> namespace block always creates an - SecurityContextPersistenceFilter, an - ExceptionTranslationFilter and a - FilterSecurityInterceptor. These are fixed and cannot be - replaced with alternatives. + SecurityContextPersistenceFilter, an + ExceptionTranslationFilter and a + FilterSecurityInterceptor. These are fixed and cannot be replaced + with alternatives.
<literal><http></literal> Attributes The attributes on the <http> element control some of the - properties on the core filters. + properties on the core filters.
<literal>pattern</literal> - Defining a pattern for the http element controls - the requests which will be filtered through the list of filters which it defines. The - interpretation is dependent on the configured request-matcher. - If no pattern is defined, all requests will be matched, so the most specific patterns should be - declared first. - + Defining a pattern for the http element controls the + requests which will be filtered through the list of filters which it defines. + The interpretation is dependent on the configured request-matcher. If no pattern is defined, + all requests will be matched, so the most specific patterns should be declared + first.
- <literal>secured</literal> - A request pattern can be mapped to an empty filter chain, by setting - this attribute to false. No security will be applied and - none of Spring Security's features will be available. - + <literal>security</literal> + A request pattern can be mapped to an empty filter chain, by setting this + attribute to none. No security will be applied and none of + Spring Security's features will be available.
<literal>servlet-api-provision</literal> Provides versions of HttpServletRequest security methods such as isUserInRole() and getPrincipal() which are implemented by adding a - SecurityContextHolderAwareRequestFilter bean to the + SecurityContextHolderAwareRequestFilter bean to the stack. Defaults to "true".
<literal>request-matcher</literal> Defines the RequestMatcher strategy used in the FilterChainProxy and the beans created by the - intercept-url to match incoming requests. Options are + intercept-url to match incoming requests. Options are currently ant, regex and - ciRegex, for ant, regular-expression and case-insensitive + ciRegex, for ant, regular-expression and case-insensitive regular-expression repsectively. A separate instance is created for each - intercept-url element using its - pattern and method attributes (see - below). Ant paths are matched using an - AntPathRequestMatcher and regular expressions are - matched using a RegexRequestMatcher. See the Javadoc for - these classes for more details on exactly how the matching is preformed. Ant + intercept-url element using its pattern + and method attributes (see below). Ant paths are matched + using an AntPathRequestMatcher and regular expressions + are matched using a RegexRequestMatcher. See the Javadoc + for these classes for more details on exactly how the matching is preformed. Ant paths are the default strategy.
<literal>realm</literal> Sets the realm name used for basic authentication (if enabled). Corresponds to the realmName property on - BasicAuthenticationEntryPoint. + BasicAuthenticationEntryPoint.
<literal>entry-point-ref</literal> Normally the AuthenticationEntryPoint used will be set depending on which authentication mechanisms have been configured. This attribute allows this behaviour to be overridden by defining a customized - AuthenticationEntryPoint bean which will - start the authentication process. + AuthenticationEntryPoint bean which will start + the authentication process.
<literal>security-context-repository-ref</literal> - - Allows injection of a custom SecurityContextRepository - into the SecurityContextPersistenceFilter. - + Allows injection of a custom + SecurityContextRepository into the + SecurityContextPersistenceFilter.
<literal>access-decision-manager-ref</literal> Optional attribute specifying the ID of the - AccessDecisionManager implementation which - should be used for authorizing HTTP requests. By default an - AffirmativeBased implementation is used for with a - RoleVoter and an - AuthenticatedVoter. + AccessDecisionManager implementation which should + be used for authorizing HTTP requests. By default an + AffirmativeBased implementation is used for with a + RoleVoter and an + AuthenticatedVoter.
<literal>access-denied-page</literal> @@ -125,64 +122,62 @@
<literal>once-per-request</literal> Corresponds to the observeOncePerRequest property of - FilterSecurityInterceptor. Defaults to "true". - + FilterSecurityInterceptor. Defaults to "true".
<literal>create-session</literal> Controls the eagerness with which an HTTP session is created. If not set, defaults to "ifRequired". Other options are "always" and "never". The setting of this attribute affect the allowSessionCreation and - forceEagerSessionCreation properties of - HttpSessionContextIntegrationFilter. - allowSessionCreation will always be true unless this + forceEagerSessionCreation properties of + HttpSessionContextIntegrationFilter. + allowSessionCreation will always be true unless this attribute is set to "never". forceEagerSessionCreation is "false" unless it is set to "always". So the default configuration allows session creation but does not force it. The exception is if concurrent session control is enabled, when forceEagerSessionCreation will be set to true, regardless of what the setting is here. Using "never" would then cause an exception during the initialization of - HttpSessionContextIntegrationFilter. + HttpSessionContextIntegrationFilter.
<literal>use-expressions</literal> Enables EL-expressions in the access attribute, as described in the chapter on expression-based - access-control. + access-control.
<literal>disable-url-rewriting</literal> - Prevents session IDs from being appended to URLs in the application. - Clients must use cookies if this attribute is set to true. - + Prevents session IDs from being appended to URLs in the application. Clients + must use cookies if this attribute is set to true.
<literal><access-denied-handler></literal> This element allows you to set the errorPage property for the default AccessDeniedHandler used by the - ExceptionTranslationFilter, (using the - error-page attribute, or to supply your own implementation - using the ref attribute. This is discussed in more detail in the + ExceptionTranslationFilter, (using the + error-page attribute, or to supply your own implementation using + the ref attribute. This is discussed in more detail in the section on the - ExceptionTranslationFilter. + ExceptionTranslationFilter.
The <literal><intercept-url></literal> Element This element is used to define the set of URL patterns that the application is interested in and to configure how they should be handled. It is used to construct the FilterInvocationSecurityMetadataSource used by - the FilterSecurityInterceptor. It is also responsible for configuring a - ChannelAuthenticationFilter if particular URLs need to be - accessed by HTTPS, for example. When matching the specified patterns against an - incoming request, the matching is done in the order in which the elements are - declared. So the most specific matches patterns should come first and the most + the FilterSecurityInterceptor. It is also responsible for + configuring a ChannelAuthenticationFilter if particular URLs + need to be accessed by HTTPS, for example. When matching the specified patterns + against an incoming request, the matching is done in the order in which the elements + are declared. So the most specific matches patterns should come first and the most general should come last.
<literal>pattern</literal> The pattern which defines the URL path. The content will depend on the - request-matcher attribute from the containing http - element, so will default to ant path syntax. + request-matcher attribute from the containing http element, + so will default to ant path syntax.
<literal>method</literal> @@ -194,9 +189,9 @@
<literal>access</literal> Lists the access attributes which will be stored in the - FilterInvocationSecurityMetadataSource for - the defined URL pattern/method combination. This should be a comma-separated - list of the security configuration attributes (such as role names). + FilterInvocationSecurityMetadataSource for the + defined URL pattern/method combination. This should be a comma-separated list of + the security configuration attributes (such as role names).
<literal>requires-channel</literal> @@ -204,15 +199,15 @@ particular URL pattern should be accessed over HTTP or HTTPS respectively. Alternatively the value any can be used when there is no preference. If this attribute is present on any - <intercept-url> element, then a - ChannelAuthenticationFilter will be added to the - filter stack and its additional dependencies added to the application + <intercept-url> element, then a + ChannelAuthenticationFilter will be added to the filter + stack and its additional dependencies added to the application context. If a <port-mappings> configuration is added, this will be used to by the SecureChannelProcessor and - InsecureChannelProcessor beans to determine the ports + InsecureChannelProcessor beans to determine the ports used for redirecting to HTTP/HTTPS.
@@ -232,7 +227,7 @@ Each child <port-mapping> element defines a pair of HTTP:HTTPS ports. The default mappings are 80:443 and 8080:8443. An example of overriding these can be found in the namespace introduction. + >namespace introduction.
The <literal><form-login></literal> Element @@ -241,30 +236,30 @@ application context to provide authentication on demand. This will always take precedence over other namespace-created entry points. If no attributes are supplied, a login page will be generated automatically at the URL "/spring-security-login" - This feature is really just provided for convenience and is not intended - for production (where a view technology will have been chosen and can be - used to render a customized login page). The class - DefaultLoginPageGeneratingFilter is responsible - for rendering the login page and will provide login forms for both normal - form login and/or OpenID if required. + This feature is really just provided for convenience and is not intended for + production (where a view technology will have been chosen and can be used to + render a customized login page). The class + DefaultLoginPageGeneratingFilter is responsible for + rendering the login page and will provide login forms for both normal form login + and/or OpenID if required. The behaviour can be customized using the following attributes.
<literal>login-page</literal> The URL that should be used to render the login page. Maps to the - loginFormUrl property of the - LoginUrlAuthenticationEntryPoint. Defaults to + loginFormUrl property of the + LoginUrlAuthenticationEntryPoint. Defaults to "/spring-security-login".
<literal>login-processing-url</literal> Maps to the filterProcessesUrl property of - UsernamePasswordAuthenticationFilter. The default - value is "/j_spring_security_check". + UsernamePasswordAuthenticationFilter. The default value + is "/j_spring_security_check".
<literal>default-target-url</literal> Maps to the defaultTargetUrl property of - UsernamePasswordAuthenticationFilter. If not set, the + UsernamePasswordAuthenticationFilter. If not set, the default value is "/" (the application root). A user will be taken to this URL after logging in, provided they were not asked to login while attempting to access a secured resource, when they will be taken to the originally requested @@ -273,16 +268,16 @@
<literal>always-use-default-target</literal> If set to "true", the user will always start at the value given by - default-target-url, regardless of how they arrived at the + default-target-url, regardless of how they arrived at the login page. Maps to the alwaysUseDefaultTargetUrl property of - UsernamePasswordAuthenticationFilter. Default value - is "false". + UsernamePasswordAuthenticationFilter. Default value is + "false".
<literal>authentication-failure-url</literal> Maps to the authenticationFailureUrl property of - UsernamePasswordAuthenticationFilter. Defines the URL - the browser will be redirected to on login failure. Defaults to + UsernamePasswordAuthenticationFilter. Defines the URL the + browser will be redirected to on login failure. Defaults to "/spring_security_login?login_error", which will be automatically handled by the automatic login page generator, re-rendering the login page with an error message. @@ -294,8 +289,8 @@ the navigation flow after a successful authentication. The value should be the name of an AuthenticationSuccessHandler bean in the application context. By default, an imlementation of - SavedRequestAwareAuthenticationSuccessHandler is used - and injected with the default-target-url. + SavedRequestAwareAuthenticationSuccessHandler is used and + injected with the default-target-url.
<literal>authentication-failure-handler-ref</literal> @@ -309,7 +304,7 @@
The <literal><http-basic></literal> Element Adds a BasicAuthenticationFilter and - BasicAuthenticationEntryPoint to the configuration. The + BasicAuthenticationEntryPoint to the configuration. The latter will only be used as the configuration entry point if form-based login is not enabled.
@@ -317,57 +312,57 @@ The <literal><remember-me></literal> Element Adds the RememberMeAuthenticationFilter to the stack. This in turn will be configured with either a - TokenBasedRememberMeServices, a - PersistentTokenBasedRememberMeServices or a - user-specified bean implementing RememberMeServices - depending on the attribute settings. + TokenBasedRememberMeServices, a + PersistentTokenBasedRememberMeServices or a user-specified + bean implementing RememberMeServices depending on the + attribute settings.
<literal>data-source-ref</literal> If this is set, PersistentTokenBasedRememberMeServices will be used and configured with a - JdbcTokenRepositoryImpl instance. + JdbcTokenRepositoryImpl instance.
<literal>token-repository-ref</literal> Configures a PersistentTokenBasedRememberMeServices but allows the use of a custom - PersistentTokenRepository bean. + PersistentTokenRepository bean.
<literal>services-ref</literal> Allows complete control of the - RememberMeServices implementation that will - be used by the filter. The value should be the Id of a bean in the application + RememberMeServices implementation that will be + used by the filter. The value should be the Id of a bean in the application context which implements this interface.
<literal>token-repository-ref</literal> Configures a PersistentTokenBasedRememberMeServices but allows the use of a custom - PersistentTokenRepository bean. + PersistentTokenRepository bean.
The <literal>key</literal> Attribute Maps to the "key" property of - AbstractRememberMeServices. Should be set to a unique + AbstractRememberMeServices. Should be set to a unique value to ensure that remember-me cookies are only valid within the one application - This doesn't affect the use of - PersistentTokenBasedRememberMeServices, where - the tokens are stored on the server side. + This doesn't affect the use of + PersistentTokenBasedRememberMeServices, where the + tokens are stored on the server side. .
<literal>token-validity-seconds</literal> Maps to the tokenValiditySeconds property of - AbstractRememberMeServices. Specifies the period in + AbstractRememberMeServices. Specifies the period in seconds for which the remember-me cookie should be valid. By default it will be valid for 14 days.
<literal>user-service-ref</literal> The remember-me services implementations require access to a - UserDetailsService, so there has to be one + UserDetailsService, so there has to be one defined in the application context. If there is only one, it will be selected and used automatically by the namespace configuration. If there are multiple instances, you can specify a bean Id explicitly using this attribute. @@ -376,7 +371,7 @@
The <literal><session-management></literal> Element Session-management related functionality is implemented by the addition of a - SessionManagementFilter to the filter stack. + SessionManagementFilter to the filter stack.
<literal>session-fixation-protection</literal> Indicates whether an existing session should be invalidated when a user @@ -385,28 +380,27 @@ a new session and copy the session attributes to the new session. Defaults to "migrateSession". If session fixation protection is enabled, the - SessionManagementFilter is inected with a - appropriately configured - DefaultSessionAuthenticationStrategy. See the Javadoc - for this class for more details. + SessionManagementFilter is inected with a appropriately + configured DefaultSessionAuthenticationStrategy. See the + Javadoc for this class for more details.
The <literal><concurrency-control></literal> Element Adds support for concurrent session control, allowing limits to be placed on the number of active sessions a user can have. A - ConcurrentSessionFilter will be created, and a - ConcurrentSessionControlStrategy will be used with the - SessionManagementFilter. If a - form-login element has been declared, the strategy object - will also be injected into the created authentication filter. An instance of - SessionRegistry (a - SessionRegistryImpl instance unless the user wishes to - use a custom bean) will be created for use by the strategy. + ConcurrentSessionFilter will be created, and a + ConcurrentSessionControlStrategy will be used with the + SessionManagementFilter. If a form-login + element has been declared, the strategy object will also be injected into the + created authentication filter. An instance of + SessionRegistry (a + SessionRegistryImpl instance unless the user wishes to use a + custom bean) will be created for use by the strategy.
The <literal>max-sessions</literal> attribute Maps to the maximumSessions property of - ConcurrentSessionControlStrategy. + ConcurrentSessionControlStrategy.
The <literal>expired-url</literal> attribute @@ -420,13 +414,13 @@
The <literal>error-if-maximum-exceeded</literal> attribute If set to "true" a - SessionAuthenticationException will be raised + SessionAuthenticationException will be raised when a user attempts to exceed the maximum allowed number of sessions. The default behaviour is to expire the original session.
The <literal>session-registry-alias</literal> and - <literal>session-registry-ref</literal> attributes + session-registry-ref attributes The user can supply their own SessionRegistry implementation using the session-registry-ref attribute. The other concurrent session control beans will be wired up to use it. @@ -439,24 +433,24 @@
The <literal><anonymous></literal> Element Adds an AnonymousAuthenticationFilter to the stack and an - AnonymousAuthenticationProvider. Required if you are - using the IS_AUTHENTICATED_ANONYMOUSLY attribute. + AnonymousAuthenticationProvider. Required if you are using + the IS_AUTHENTICATED_ANONYMOUSLY attribute.
The <literal><x509></literal> Element Adds support for X.509 authentication. An - X509AuthenticationFilter will be added to the stack and - an Http403ForbiddenEntryPoint bean will be created. The - latter will only be used if no other authentication mechanisms are in use (it's only + X509AuthenticationFilter will be added to the stack and an + Http403ForbiddenEntryPoint bean will be created. The latter + will only be used if no other authentication mechanisms are in use (it's only functionality is to return an HTTP 403 error code). A - PreAuthenticatedAuthenticationProvider will also be - created which delegates the loading of user authorities to a - UserDetailsService. + PreAuthenticatedAuthenticationProvider will also be created + which delegates the loading of user authorities to a + UserDetailsService.
The <literal>subject-principal-regex</literal> attribute Defines a regular expression which will be used to extract the username from the certificate (for use with the - UserDetailsService). + UserDetailsService).
The <literal>user-service-ref</literal> attribute @@ -471,10 +465,10 @@ Similar to <form-login> and has the same attributes. The default value for login-processing-url is "/j_spring_openid_security_check". An - OpenIDAuthenticationFilter and - OpenIDAuthenticationProvider will be registered. The - latter requires a reference to a UserDetailsService. - Again, this can be specified by Id, using the user-service-ref + OpenIDAuthenticationFilter and + OpenIDAuthenticationProvider will be registered. The latter + requires a reference to a UserDetailsService. Again, + this can be specified by Id, using the user-service-ref attribute, or will be located automatically in the application context.
The <literal><attribute-exchange></literal> Element @@ -503,86 +497,85 @@
The <literal>invalidate-session</literal> attribute Maps to the invalidateHttpSession of the - SecurityContextLogoutHandler. Defaults to "true", so - the session will be invalidated on logout. + SecurityContextLogoutHandler. Defaults to "true", so the + session will be invalidated on logout.
The <literal><custom-filter></literal> Element This element is used to add a filter to the filter chain. It doesn't create any additional beans but is used to select a bean of type - javax.servlet.Filter which is already defined in - the appllication context and add that at a particular position in the filter chain + javax.servlet.Filter which is already defined in the + appllication context and add that at a particular position in the filter chain maintained by Spring Security. Full details can be found in the namespace chapter.
The <literal>request-cache</literal> Element Sets the RequestCache instance which will be used - by the ExceptionTranslationFilter to store request information - before invoking an AuthenticationEntryPoint. - + by the ExceptionTranslationFilter to store request + information before invoking an + AuthenticationEntryPoint.
Authentication Services Before Spring Security 3.0, an AuthenticationManager was automatically registered internally. Now you must register one explicitly using the - <authentication-manager> element. This creates an instance - of Spring Security's ProviderManager class, which needs to be + <authentication-manager> element. This creates an instance of + Spring Security's ProviderManager class, which needs to be configured with a list of one or more - AuthenticationProvider instances. These can either be + AuthenticationProvider instances. These can either be created using syntax elements provided by the namespace, or they can be standard bean definitions, marked for addition to the list using the - authentication-provider element. + authentication-provider element.
The <literal><authentication-manager></literal> Element Every Spring Security application which uses the namespace must have include this element somewhere. It is responsible for registering the - AuthenticationManager which provides - authentication services to the application. It also allows you to define an alias - name for the internal instance for use in your own configuration. Its use is - described in the namespace introduction. - All elements which create AuthenticationProvider - instances should be children of this element. - - The element also exposes an erase-credentials attribute which maps - to the eraseCredentialsAfterAuthentication property of - the ProviderManager. This is discussed in the - Core Services chapter. + AuthenticationManager which provides authentication + services to the application. It also allows you to define an alias name for the + internal instance for use in your own configuration. Its use is described in the + namespace introduction. All elements + which create AuthenticationProvider instances should + be children of this element. + The element also exposes an erase-credentials attribute which + maps to the eraseCredentialsAfterAuthentication property of the + ProviderManager. This is discussed in the Core Services chapter.
The <literal><authentication-provider></literal> Element Unless used with a ref attribute, this element is shorthand for configuring a DaoAuthenticationProvider. - DaoAuthenticationProvider loads user information from - a UserDetailsService and compares the + >DaoAuthenticationProvider. + DaoAuthenticationProvider loads user information from a + UserDetailsService and compares the username/password combination with the values supplied at login. The - UserDetailsService instance can be defined - either by using an available namespace element - (jdbc-user-service or by using the - user-service-ref attribute to point to a bean defined - elsewhere in the application context). You can find examples of these variations - in the namespace introduction. + UserDetailsService instance can be defined either + by using an available namespace element (jdbc-user-service or + by using the user-service-ref attribute to point to a bean + defined elsewhere in the application context). You can find examples of these + variations in the namespace + introduction.
The <literal><password-encoder></literal> Element Authentication providers can optionally be configured to use a password encoder as described in the namespace introduction. This will result in the bean being - injected with the appropriate PasswordEncoder + >namespace introduction. This will result in the bean being injected + with the appropriate PasswordEncoder instance, potentially with an accompanying - SaltSource bean to provide salt values - for hashing. + SaltSource bean to provide salt values for + hashing.
Using <literal><authentication-provider></literal> to refer to an - <interfacename>AuthenticationProvider</interfacename> Bean + AuthenticationProvider Bean If you have written your own - AuthenticationProvider implementation (or - want to configure one of Spring Security's own implementations as a traditional - bean for some reason, then you can use the following syntax to add it to the - internal ProviderManager's list: AuthenticationProvider implementation (or want to + configure one of Spring Security's own implementations as a traditional bean for + some reason, then you can use the following syntax to add it to the internal + ProviderManager's list: @@ -600,27 +593,26 @@ the interface or class level) or by defining a set of pointcuts as child elements, using AspectJ syntax. Method security uses the same - AccessDecisionManager configuration as web - security, but this can be overridden as explained above , using the same attribute. + AccessDecisionManager configuration as web security, + but this can be overridden as explained above , using the same attribute.
The <literal>secured-annotations</literal> and - <literal>jsr250-annotations</literal> Attributes + jsr250-annotations Attributes Setting these to "true" will enable support for Spring Security's own - @Secured annotations and JSR-250 annotations, - respectively. They are both disabled by default. Use of JSR-250 annotations also - adds a Jsr250Voter to the - AccessDecisionManager, so you need to make - sure you do this if you are using a custom implementation and want to use these + @Secured annotations and JSR-250 annotations, respectively. + They are both disabled by default. Use of JSR-250 annotations also adds a + Jsr250Voter to the + AccessDecisionManager, so you need to make sure + you do this if you are using a custom implementation and want to use these annotations.
The <literal>mode</literal> Attribute - This attribute can be set to aspectj to specify that - AspectJ should be used instead of the default Spring AOP. Secured methods must - be woven with the AnnotationSecurityAspect from the - spring-security-aspects module. - + This attribute can be set to aspectj to specify that AspectJ + should be used instead of the default Spring AOP. Secured methods must be woven + with the AnnotationSecurityAspect from the + spring-security-aspects module.
Securing Methods using <literal><protect-pointcut></literal> @@ -629,120 +621,118 @@ cross-cutting security constraints across whole sets of methods and interfaces in your service layer using the <protect-pointcut> element. This has two attributes: - - expression - the pointcut expression - - - access - the security attributes which - apply - + + expression - the pointcut expression + + + access - the security attributes which apply + You can find an example in the namespace introduction. + xlink:href="#ns-protect-pointcut">namespace introduction.
The <literal><after-invocation-provider></literal> Element This element can be used to decorate an - AfterInvocationProvider for use by the - security interceptor maintained by the - <global-method-security> namespace. You can define - zero or more of these within the global-method-security - element, each with a ref attribute pointing to an - AfterInvocationProvider bean instance within - your application context. + AfterInvocationProvider for use by the security + interceptor maintained by the <global-method-security> + namespace. You can define zero or more of these within the + global-method-security element, each with a + ref attribute pointing to an + AfterInvocationProvider bean instance within your + application context.
LDAP Namespace Options LDAP is covered in some details in its own - chapter. We will expand on that here with some explanation of how the + chapter. We will expand on that here with some explanation of how the namespace options map to Spring beans. The LDAP implementation uses Spring LDAP extensively, so some familiarity with that project's API may be useful.
Defining the LDAP Server using the <literal><ldap-server></literal> Element This element sets up a Spring LDAP - ContextSource for use by the other LDAP - beans, defining the location of the LDAP server and other information (such as a + ContextSource for use by the other LDAP beans, + defining the location of the LDAP server and other information (such as a username and password, if it doesn't allow anonymous access) for connecting to it. It can also be used to create an embedded server for testing. Details of the syntax for both options are covered in the LDAP - chapter. The actual ContextSource + chapter. The actual ContextSource implementation is DefaultSpringSecurityContextSource which extends Spring LDAP's LdapContextSource class. The - manager-dn and manager-password - attributes map to the latter's userDn and - password properties respectively. + manager-dn and manager-password attributes + map to the latter's userDn and password + properties respectively. If you only have one server defined in your application context, the other LDAP namespace-defined beans will use it automatically. Otherwise, you can give the element an "id" attribute and refer to it from other namespace beans using the server-ref attribute. This is actually the bean Id of the - ContextSource instance, if you want to use it in other + ContextSource instance, if you want to use it in other traditional Spring beans.
The <literal><ldap-provider></literal> Element This element is shorthand for the creation of an - LdapAuthenticationProvider instance. By default this - will be configured with a BindAuthenticator instance and - a DefaultAuthoritiesPopulator. As with all namespace + LdapAuthenticationProvider instance. By default this will + be configured with a BindAuthenticator instance and a + DefaultAuthoritiesPopulator. As with all namespace authentication providers, it must be included as a child of the - authentication-provider element. + authentication-provider element.
The <literal>user-dn-pattern</literal> Attribute If your users are at a fixed location in the directory (i.e. you can work out the DN directly from the username without doing a directory search), you can use this attribute to map directly to the DN. It maps directly to the - userDnPatterns property of - AbstractLdapAuthenticator. + userDnPatterns property of + AbstractLdapAuthenticator.
The <literal>user-search-base</literal> and - <literal>user-search-filter</literal> Attributes + user-search-filter Attributes If you need to perform a search to locate the user in the directory, then you can set these attributes to control the search. The - BindAuthenticator will be configured with a - FilterBasedLdapUserSearch and the attribute - values map directly to the first two arguments of that bean's constructor. - If these attributes aren't set and no user-dn-pattern has - been supplied as an alternative, then the default search values of - user-search-filter="(uid={0})" and - user-search-base="" will be used. + BindAuthenticator will be configured with a + FilterBasedLdapUserSearch and the attribute values + map directly to the first two arguments of that bean's constructor. If these + attributes aren't set and no user-dn-pattern has been + supplied as an alternative, then the default search values of + user-search-filter="(uid={0})" and + user-search-base="" will be used.
<literal>group-search-filter</literal>, - <literal>group-search-base</literal>, - <literal>group-role-attribute</literal> and - <literal>role-prefix</literal> Attributes + group-search-base, + group-role-attribute and role-prefix + Attributes The value of group-search-base is mapped to the - groupSearchBase constructor argument of - DefaultAuthoritiesPopulator and defaults to + groupSearchBase constructor argument of + DefaultAuthoritiesPopulator and defaults to "ou=groups". The default filter value is "(uniqueMember={0})", which assumes that the entry is of type "groupOfUniqueNames". - group-role-attribute maps to the - groupRoleAttribute attribute and defaults to "cn". + group-role-attribute maps to the + groupRoleAttribute attribute and defaults to "cn". Similarly role-prefix maps to - rolePrefix and defaults to "ROLE_". + rolePrefix and defaults to "ROLE_".
The <literal><password-compare></literal> Element This is used as child element to <ldap-provider> and switches the authentication strategy from - BindAuthenticator to - PasswordComparisonAuthenticator. This can - optionally be supplied with a hash attribute or with a - child <password-encoder> element to hash the - password before submitting it to the directory for comparison. + BindAuthenticator to + PasswordComparisonAuthenticator. This can optionally + be supplied with a hash attribute or with a child + <password-encoder> element to hash the password + before submitting it to the directory for comparison.
The <literal><ldap-user-service></literal> Element This element configures an LDAP - UserDetailsService. The class used is - LdapUserDetailsService which is a combination of a - FilterBasedLdapUserSearch and a - DefaultAuthoritiesPopulator. The attributes it - supports have the same usage as in <ldap-provider>. - + UserDetailsService. The class used is + LdapUserDetailsService which is a combination of a + FilterBasedLdapUserSearch and a + DefaultAuthoritiesPopulator. The attributes it supports + have the same usage as in <ldap-provider>.
diff --git a/docs/manual/src/docbook/namespace-config.xml b/docs/manual/src/docbook/namespace-config.xml index 70230a78f0..2eda58302d 100644 --- a/docs/manual/src/docbook/namespace-config.xml +++ b/docs/manual/src/docbook/namespace-config.xml @@ -272,8 +272,8 @@ appears to be secured. It is also possible to have all requests matching a particular pattern bypass the security filter chain completely, by defining a separate http element for the pattern like this: - + + @@ -322,7 +322,7 @@ always-use-default-target attribute to "true". This is useful if your application always requires that the user starts at a "home" page, for example: + - + diff --git a/itest/web/src/main/webapp/WEB-INF/http-security-custom-concurrency.xml b/itest/web/src/main/webapp/WEB-INF/http-security-custom-concurrency.xml index 68e53ab9a1..d9e7433ddd 100644 --- a/itest/web/src/main/webapp/WEB-INF/http-security-custom-concurrency.xml +++ b/itest/web/src/main/webapp/WEB-INF/http-security-custom-concurrency.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> - + diff --git a/itest/web/src/main/webapp/WEB-INF/http-security.xml b/itest/web/src/main/webapp/WEB-INF/http-security.xml index 555fce6bc5..004c1f0ad1 100644 --- a/itest/web/src/main/webapp/WEB-INF/http-security.xml +++ b/itest/web/src/main/webapp/WEB-INF/http-security.xml @@ -10,7 +10,7 @@ Http App Context to test form login, remember-me and concurrent session control. Needs to be supplemented with authentication provider(s) --> - + diff --git a/samples/openid/src/main/webapp/WEB-INF/applicationContext-security.xml b/samples/openid/src/main/webapp/WEB-INF/applicationContext-security.xml index 631c14d4c4..a93e35ab07 100644 --- a/samples/openid/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/samples/openid/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -10,10 +10,10 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> - - - - + + + +