From 8e68fa13341e17a7bba86ea674e14a9ad1e54e83 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Wed, 13 Oct 2010 19:34:04 +0100 Subject: [PATCH] SEC-1584: Added namespace support for injecting custom HttpFirewall instance into FilterChainProxy. --- config/convert_schema.sh | 4 +- .../security/config/Elements.java | 1 + .../config/SecurityNamespaceHandler.java | 2 + .../HttpFirewallBeanDefinitionParser.java | 39 + ...ttpFirewallInjectionBeanPostProcessor.java | 40 + .../main/resources/META-INF/spring.schemas | 3 +- ...ty-3.0.3.rnc => spring-security-3.0.4.rnc} | 31 +- .../security/config/spring-security-3.0.4.xsd | 1386 +++++++++++++++++ ...HttpSecurityBeanDefinitionParserTests.java | 13 + .../util/InMemoryXmlApplicationContext.java | 4 +- .../manual/src/docbook/appendix-namespace.xml | 1371 ++++++++-------- .../security/web/FilterChainProxy.java | 4 + 12 files changed, 2253 insertions(+), 645 deletions(-) create mode 100644 config/src/main/java/org/springframework/security/config/http/HttpFirewallBeanDefinitionParser.java create mode 100644 config/src/main/java/org/springframework/security/config/http/HttpFirewallInjectionBeanPostProcessor.java rename config/src/main/resources/org/springframework/security/config/{spring-security-3.0.3.rnc => spring-security-3.0.4.rnc} (94%) create mode 100644 config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.xsd diff --git a/config/convert_schema.sh b/config/convert_schema.sh index 35b1405451..8b68cba82f 100755 --- a/config/convert_schema.sh +++ b/config/convert_schema.sh @@ -3,9 +3,9 @@ pushd src/main/resources/org/springframework/security/config/ echo "Converting rnc file to xsd ..." -java -jar ~/bin/trang.jar spring-security-3.0.3.rnc spring-security-3.0.3.xsd +java -jar ~/bin/trang.jar spring-security-3.0.4.rnc spring-security-3.0.4.xsd echo "Applying XSL transformation to xsd ..." -xsltproc --output spring-security-3.0.3.xsd spring-security.xsl spring-security-3.0.3.xsd +xsltproc --output spring-security-3.0.4.xsd spring-security.xsl spring-security-3.0.4.xsd popd \ No newline at end of file diff --git a/config/src/main/java/org/springframework/security/config/Elements.java b/config/src/main/java/org/springframework/security/config/Elements.java index fb101232cb..685b5520f0 100644 --- a/config/src/main/java/org/springframework/security/config/Elements.java +++ b/config/src/main/java/org/springframework/security/config/Elements.java @@ -50,4 +50,5 @@ public abstract class Elements { @Deprecated public static final String FILTER_INVOCATION_DEFINITION_SOURCE = "filter-invocation-definition-source"; public static final String LDAP_PASSWORD_COMPARE = "password-compare"; + public static final String HTTP_FIREWALL = "http-firewall"; } diff --git a/config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java b/config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java index bdc6141fa5..45cf26cb12 100644 --- a/config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java +++ b/config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java @@ -15,6 +15,7 @@ import org.springframework.security.config.authentication.JdbcUserServiceBeanDef import org.springframework.security.config.authentication.UserServiceBeanDefinitionParser; import org.springframework.security.config.http.FilterChainMapBeanDefinitionDecorator; import org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser; +import org.springframework.security.config.http.HttpFirewallBeanDefinitionParser; import org.springframework.security.config.http.HttpSecurityBeanDefinitionParser; import org.springframework.security.config.ldap.LdapProviderBeanDefinitionParser; import org.springframework.security.config.ldap.LdapServerBeanDefinitionParser; @@ -119,6 +120,7 @@ public final class SecurityNamespaceHandler implements NamespaceHandler { // Only load the web-namespace parsers if the web classes are available if (ClassUtils.isPresent("org.springframework.security.web.FilterChainProxy", getClass().getClassLoader())) { parsers.put(Elements.HTTP, new HttpSecurityBeanDefinitionParser()); + parsers.put(Elements.HTTP_FIREWALL, new HttpFirewallBeanDefinitionParser()); parsers.put(Elements.FILTER_INVOCATION_DEFINITION_SOURCE, new FilterInvocationSecurityMetadataSourceParser()); parsers.put(Elements.FILTER_SECURITY_METADATA_SOURCE, new FilterInvocationSecurityMetadataSourceParser()); filterChainMapBDD = new FilterChainMapBeanDefinitionDecorator(); diff --git a/config/src/main/java/org/springframework/security/config/http/HttpFirewallBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/HttpFirewallBeanDefinitionParser.java new file mode 100644 index 0000000000..6f5f1347f7 --- /dev/null +++ b/config/src/main/java/org/springframework/security/config/http/HttpFirewallBeanDefinitionParser.java @@ -0,0 +1,39 @@ +package org.springframework.security.config.http; + +import org.springframework.beans.BeanMetadataElement; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.security.config.BeanIds; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +import java.util.*; + +/** + * Injects the supplied {@code HttpFirewall} bean reference into the {@code FilterChainProxy}. + * + * @author Luke Taylor + */ +public class HttpFirewallBeanDefinitionParser implements BeanDefinitionParser { + + @Override + public BeanDefinition parse(Element element, ParserContext pc) { + String ref = element.getAttribute("ref"); + + if (!StringUtils.hasText(ref)) { + pc.getReaderContext().error("ref attribute is required", pc.extractSource(element)); + } + + BeanDefinitionBuilder injector = BeanDefinitionBuilder.rootBeanDefinition(HttpFirewallInjectionBeanPostProcessor.class); + injector.addConstructorArgValue(ref); + + pc.getReaderContext().registerWithGeneratedName(injector.getBeanDefinition()); + + return null; + } +} diff --git a/config/src/main/java/org/springframework/security/config/http/HttpFirewallInjectionBeanPostProcessor.java b/config/src/main/java/org/springframework/security/config/http/HttpFirewallInjectionBeanPostProcessor.java new file mode 100644 index 0000000000..a88cb90a47 --- /dev/null +++ b/config/src/main/java/org/springframework/security/config/http/HttpFirewallInjectionBeanPostProcessor.java @@ -0,0 +1,40 @@ +package org.springframework.security.config.http; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.security.config.BeanIds; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.security.web.firewall.HttpFirewall; + +/** + * @author Luke Taylor + */ +public class HttpFirewallInjectionBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware { + private ConfigurableListableBeanFactory beanFactory; + private String ref; + + public HttpFirewallInjectionBeanPostProcessor(String ref) { + this.ref = ref; + } + + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if (BeanIds.FILTER_CHAIN_PROXY.equals(beanName)) { + HttpFirewall fw = (HttpFirewall) beanFactory.getBean(ref); + ((FilterChainProxy)bean).setFirewall(fw); + } + + return bean; + } + + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; + } +} diff --git a/config/src/main/resources/META-INF/spring.schemas b/config/src/main/resources/META-INF/spring.schemas index 4a869f8b1d..fb8035bf20 100644 --- a/config/src/main/resources/META-INF/spring.schemas +++ b/config/src/main/resources/META-INF/spring.schemas @@ -1,5 +1,6 @@ -http\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.0.3.xsd +http\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.0.4.xsd http\://www.springframework.org/schema/security/spring-security-3.0.xsd=org/springframework/security/config/spring-security-3.0.xsd +http\://www.springframework.org/schema/security/spring-security-3.0.4.xsd=org/springframework/security/config/spring-security-3.0.4.xsd http\://www.springframework.org/schema/security/spring-security-3.0.3.xsd=org/springframework/security/config/spring-security-3.0.3.xsd http\://www.springframework.org/schema/security/spring-security-2.0.xsd=org/springframework/security/config/spring-security-2.0.xsd http\://www.springframework.org/schema/security/spring-security-2.0.1.xsd=org/springframework/security/config/spring-security-2.0.1.xsd diff --git a/config/src/main/resources/org/springframework/security/config/spring-security-3.0.3.rnc b/config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.rnc similarity index 94% rename from config/src/main/resources/org/springframework/security/config/spring-security-3.0.3.rnc rename to config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.rnc index 3981ae283c..7ad0dce5f3 100644 --- a/config/src/main/resources/org/springframework/security/config/spring-security-3.0.3.rnc +++ b/config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.rnc @@ -187,7 +187,7 @@ protect.attlist &= global-method-security = ## Provides method security for all beans registered in the Spring application context. Specifically, beans will be scanned for matches with the ordered list of "protect-pointcut" sub-elements, Spring Security annotations and/or. Where there is a match, the beans will automatically be proxied and security authorization applied to the methods accordingly. If you use and enable all four sources of method security metadata (ie "protect-pointcut" declarations, expression annotations, @Secured and also JSR250 security annotations), the metadata sources will be queried in that order. In practical terms, this enables you to use XML to override method security metadata expressed in annotations. If using annotations, the order of precedence is EL-based (@PreAuthorize etc.), @Secured and finally JSR-250. - element global-method-security {global-method-security.attlist, (pre-post-annotation-handling | expression-handler)?, protect-pointcut*, after-invocation-provider*} + element global-method-security {global-method-security.attlist, (pre-post-annotation-handling | expression-handler)?, protect-pointcut*, after-invocation-provider*} global-method-security.attlist &= ## Specifies whether the use of Spring Security's pre and post invocation annotations (@PreFilter, @PreAuthorize, @PostFilter, @PostAuthorize) should be enabled for this application context. Defaults to "disabled". attribute pre-post-annotations {"disabled" | "enabled" }? @@ -245,6 +245,9 @@ protect-pointcut.attlist &= ## Access configuration attributes list that applies to all methods matching the pointcut, e.g. "ROLE_A,ROLE_B" attribute access {xsd:token} +http-firewall = + ## Allows a custom instance of HttpFirewall to be injected into the FilterChainProxy created by the namespace. + element http-firewall {ref} http = ## Container element for HTTP security configuration @@ -319,16 +322,16 @@ intercept-url.attlist &= attribute requires-channel {xsd:token}? logout = - ## Incorporates a logout processing filter. Most web applications require a logout filter, although you may not require one if you write a controller to provider similar logic. + ## Incorporates a logout processing filter. Most web applications require a logout filter, although you may not require one if you write a controller to provider similar logic. element logout {logout.attlist, empty} logout.attlist &= - ## Specifies the URL that will cause a logout. Spring Security will initialize a filter that responds to this particular URL. Defaults to /j_spring_security_logout if unspecified. + ## Specifies the URL that will cause a logout. Spring Security will initialize a filter that responds to this particular URL. Defaults to /j_spring_security_logout if unspecified. attribute logout-url {xsd:token}? logout.attlist &= - ## Specifies the URL to display once the user has logged out. If not specified, defaults to /. + ## Specifies the URL to display once the user has logged out. If not specified, defaults to /. attribute logout-success-url {xsd:token}? logout.attlist &= - ## Specifies whether a logout also causes HttpSession invalidation, which is generally desirable. If unspecified, defaults to true. + ## Specifies whether a logout also causes HttpSession invalidation, which is generally desirable. If unspecified, defaults to true. attribute invalidate-session {boolean}? logout.attlist &= ## A reference to a LogoutSuccessHandler implementation which will be used to determine the destination to which the user is taken after logging out. @@ -565,29 +568,29 @@ properties-file = attribute properties {xsd:token}? user = - ## Represents a user in the application. + ## Represents a user in the application. element user {user.attlist, empty} user.attlist &= - ## The username assigned to the user. + ## The username assigned to the user. attribute name {xsd:token} user.attlist &= - ## The password assigned to the user. This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element). This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities. If omitted, the namespace will generate a random value, preventing its accidental use for authentication. Cannot be empty. + ## The password assigned to the user. This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element). This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities. If omitted, the namespace will generate a random value, preventing its accidental use for authentication. Cannot be empty. attribute password {xsd:string}? user.attlist &= - ## One of more authorities granted to the user. Separate authorities with a comma (but no space). For example, "ROLE_USER,ROLE_ADMINISTRATOR" + ## One of more authorities granted to the user. Separate authorities with a comma (but no space). For example, "ROLE_USER,ROLE_ADMINISTRATOR" attribute authorities {xsd:token} user.attlist &= - ## Can be set to "true" to mark an account as locked and unusable. + ## Can be set to "true" to mark an account as locked and unusable. attribute locked {boolean}? user.attlist &= - ## Can be set to "true" to mark an account as disabled and unusable. + ## Can be set to "true" to mark an account as disabled and unusable. attribute disabled {boolean}? jdbc-user-service = - ## Causes creation of a JDBC-based UserDetailsService. + ## Causes creation of a JDBC-based UserDetailsService. element jdbc-user-service {id? & jdbc-user-service.attlist} jdbc-user-service.attlist &= - ## The bean ID of the DataSource which provides the required tables. + ## The bean ID of the DataSource which provides the required tables. attribute data-source-ref {xsd:token} jdbc-user-service.attlist &= cache-ref? @@ -628,5 +631,3 @@ position = named-security-filter = "FIRST" | "CHANNEL_FILTER" | "CONCURRENT_SESSION_FILTER" | "SECURITY_CONTEXT_FILTER" | "LOGOUT_FILTER" | "X509_FILTER" | "PRE_AUTH_FILTER" | "CAS_FILTER" | "FORM_LOGIN_FILTER" | "OPENID_FILTER" |"BASIC_AUTH_FILTER" | "SERVLET_API_SUPPORT_FILTER" | "REMEMBER_ME_FILTER" | "ANONYMOUS_FILTER" | "EXCEPTION_TRANSLATION_FILTER" | "SESSION_MANAGEMENT_FILTER" | "FILTER_SECURITY_INTERCEPTOR" | "SWITCH_USER_FILTER" | "LAST" - - diff --git a/config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.xsd b/config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.xsd new file mode 100644 index 0000000000..15d02c4bd2 --- /dev/null +++ b/config/src/main/resources/org/springframework/security/config/spring-security-3.0.4.xsd @@ -0,0 +1,1386 @@ + + + + + + Defines the hashing algorithm used on user passwords. We recommend strongly against using MD4, as it is a very weak hashing algorithm. + + + + + + + + + + + + + + + + + + Whether a string should be base64 encoded + + + + + + + + + + + + + Defines the type of pattern used to specify URL paths (either JDK 1.4-compatible regular expressions, or Apache Ant expressions). Defaults to "ant" if unspecified. + + + + + + + + + + + + + Specifies an IP port number. Used to configure an embedded LDAP server, for example. + + + + + + + Specifies a URL. + + + + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + + + Defines a reference to a Spring bean Id. + + + + + + + Defines a reference to a cache for use with a UserDetailsService. + + + + + + + A reference to a user-service (or UserDetailsService bean) Id + + + + + + + A reference to a DataSource bean + + + + + + + + Defines a reference to a Spring bean Id. + + + + + Defines the hashing algorithm used on user passwords. We recommend strongly against using MD4, as it is a very weak hashing algorithm. + + + + + + + + + + + + + + + + Whether a string should be base64 encoded + + + + + + + + + + + + + + A property of the UserDetails object which will be used as salt by a password encoder. Typically something like "username" might be used. + + + + + + + A single value that will be used as the salt for a password encoder. + + + + + + + + + + + + + A non-empty string prefix that will be added to role strings loaded from persistent storage (e.g. "ROLE_"). Use the value "none" for no prefix in cases where the default is non-empty. + + + + + + + Enables the use of expressions in the 'access' attributes in <intercept-url> elements rather than the traditional list of configuration attributes. Defaults to 'false'. If enabled, each attribute should contain a single boolean expression. If the expression evaluates to 'true', access will be granted. + + + + + Defines an LDAP server location or starts an embedded server. The url indicates the location of a remote server. If no url is given, an embedded server will be started, listening on the supplied port number. The port is optional and defaults to 33389. A Spring LDAP ContextSource bean will be registered for the server with the id supplied. + + + + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + Specifies a URL. + + + + + Specifies an IP port number. Used to configure an embedded LDAP server, for example. + + + + + Username (DN) of the "manager" user identity which will be used to authenticate to a (non-embedded) LDAP server. If omitted, anonymous access will be used. + + + + + The password for the manager DN. + + + + + Explicitly specifies an ldif file resource to load into an embedded LDAP server + + + + + Optional root suffix for the embedded LDAP server. Default is "dc=springframework,dc=org" + + + + + + + The optional server to use. If omitted, and a default LDAP server is registered (using <ldap-server> with no Id), that server will be used. + + + + + + + Group search filter. Defaults to (uniqueMember={0}). The substituted parameter is the DN of the user. + + + + + + + Search base for group membership searches. Defaults to "" (searching from the root). + + + + + + + The LDAP filter used to search for users (optional). For example "(uid={0})". The substituted parameter is the user's login name. + + + + + + + Search base for user searches. Defaults to "". Only used with a 'user-search-filter'. + + + + + + + The LDAP attribute name which contains the role name which will be used within Spring Security. Defaults to "cn". + + + + + + + Allows the objectClass of the user entry to be specified. If set, the framework will attempt to load standard attributes for the defined class into the returned UserDetails object + + + + + + + + + + + + + Allows explicit customization of the loaded user object by specifying a UserDetailsContextMapper bean which will be called with the context information from the user's directory entry + + + + + + + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + The optional server to use. If omitted, and a default LDAP server is registered (using <ldap-server> with no Id), that server will be used. + + + + + The LDAP filter used to search for users (optional). For example "(uid={0})". The substituted parameter is the user's login name. + + + + + Search base for user searches. Defaults to "". Only used with a 'user-search-filter'. + + + + + Group search filter. Defaults to (uniqueMember={0}). The substituted parameter is the DN of the user. + + + + + Search base for group membership searches. Defaults to "" (searching from the root). + + + + + The LDAP attribute name which contains the role name which will be used within Spring Security. Defaults to "cn". + + + + + Defines a reference to a cache for use with a UserDetailsService. + + + + + A non-empty string prefix that will be added to role strings loaded from persistent storage (e.g. "ROLE_"). Use the value "none" for no prefix in cases where the default is non-empty. + + + + + Allows the objectClass of the user entry to be specified. If set, the framework will attempt to load standard attributes for the defined class into the returned UserDetails object + + + + + + + + + + + Allows explicit customization of the loaded user object by specifying a UserDetailsContextMapper bean which will be called with the context information from the user's directory entry + + + + + + + + The optional server to use. If omitted, and a default LDAP server is registered (using <ldap-server> with no Id), that server will be used. + + + + + Search base for user searches. Defaults to "". Only used with a 'user-search-filter'. + + + + + The LDAP filter used to search for users (optional). For example "(uid={0})". The substituted parameter is the user's login name. + + + + + Search base for group membership searches. Defaults to "" (searching from the root). + + + + + Group search filter. Defaults to (uniqueMember={0}). The substituted parameter is the DN of the user. + + + + + The LDAP attribute name which contains the role name which will be used within Spring Security. Defaults to "cn". + + + + + A specific pattern used to build the user's DN, for example "uid={0},ou=people". The key "{0}" must be present and will be substituted with the username. + + + + + A non-empty string prefix that will be added to role strings loaded from persistent storage (e.g. "ROLE_"). Use the value "none" for no prefix in cases where the default is non-empty. + + + + + Allows the objectClass of the user entry to be specified. If set, the framework will attempt to load standard attributes for the defined class into the returned UserDetails object + + + + + + + + + + + Allows explicit customization of the loaded user object by specifying a UserDetailsContextMapper bean which will be called with the context information from the user's directory entry + + + + + + + + The attribute in the directory which contains the user password. Defaults to "userPassword". + + + + + Defines the hashing algorithm used on user passwords. We recommend strongly against using MD4, as it is a very weak hashing algorithm. + + + + + + + + + + + + + + + + Can be used inside a bean definition to add a security interceptor to the bean and set up access configuration attributes for the bean's methods + + + + Defines a protected method and the access control configuration attributes that apply to it. We strongly advise you NOT to mix "protect" declarations with any services provided "global-method-security". + + + + + + + + + + Optional AccessDecisionManager bean ID to be used by the created method security interceptor. + + + + + + + + A method name + + + + + Access configuration attributes list that applies to the method, e.g. "ROLE_A,ROLE_B". + + + + + Provides method security for all beans registered in the Spring application context. Specifically, beans will be scanned for matches with the ordered list of "protect-pointcut" sub-elements, Spring Security annotations and/or. Where there is a match, the beans will automatically be proxied and security authorization applied to the methods accordingly. If you use and enable all four sources of method security metadata (ie "protect-pointcut" declarations, expression annotations, @Secured and also JSR250 security annotations), the metadata sources will be queried in that order. In practical terms, this enables you to use XML to override method security metadata expressed in annotations. If using annotations, the order of precedence is EL-based (@PreAuthorize etc.), @Secured and finally JSR-250. + + + + + Allows the default expression-based mechanism for handling Spring Security's pre and post invocation annotations (@PreFilter, @PreAuthorize, @PostFilter, @PostAuthorize) to be replace entirely. Only applies if these annotations are enabled. + + + + Defines the PrePostInvocationAttributeFactory instance which is used to generate pre and post invocation metadata from the annotated methods. + + + + + + + + + + + + + Defines the SecurityExpressionHandler instance which will be used if expression-based access-control is enabled. A default implementation (with no ACL support) will be used if not supplied. + + + + + + Defines a protected pointcut and the access control configuration attributes that apply to it. Every bean registered in the Spring application context that provides a method that matches the pointcut will receive security authorization. + + + + + Allows addition of extra AfterInvocationProvider beans which should be called by the MethodSecurityInterceptor created by global-method-security. + + + + + + + + + + Specifies whether the use of Spring Security's pre and post invocation annotations (@PreFilter, @PreAuthorize, @PostFilter, @PostAuthorize) should be enabled for this application context. Defaults to "disabled". + + + + + + + + + + + Specifies whether the use of Spring Security's @Secured annotations should be enabled for this application context. Defaults to "disabled". + + + + + + + + + + + Specifies whether JSR-250 style attributes are to be used (for example "RolesAllowed"). This will require the javax.annotation.security classes on the classpath. Defaults to "disabled". + + + + + + + + + + + Optional AccessDecisionManager bean ID to override the default used for method security. + + + + + Optional RunAsmanager implementation which will be used by the configured MethodSecurityInterceptor + + + + + Allows the advice "order" to be set for the method security interceptor. + + + + + + Can be used to specify that AspectJ should be used instead of the default Spring AOP. If set, secured classes must be woven with the AnnotationSecurityAspect from the spring-security-aspects module. + + + + + + + + + + + + + + + + + + + An AspectJ expression, including the 'execution' keyword. For example, 'execution(int com.foo.TargetObject.countLength(String))' (without the quotes). + + + + + Access configuration attributes list that applies to all methods matching the pointcut, e.g. "ROLE_A,ROLE_B" + + + + + Allows a custom instance of HttpFirewall to be injected into the FilterChainProxy created by the namespace. + + + + + Container element for HTTP security configuration + + + + Specifies the access attributes and/or filter list for a particular set of URLs. + + + + + Defines the access-denied strategy that should be used. An access denied page can be defined or a reference to an AccessDeniedHandler instance. + + + + + Sets up a form login configuration for authentication with a username and password + + + + + Sets up form login for authentication with an Open ID identity + + + + + + + + A reference to a user-service (or UserDetailsService bean) Id + + + + + Adds support for X.509 client authentication. + + + + + Adds support for basic authentication (this is an element to permit future expansion, such as supporting an "ignoreFailure" attribute) + + + + + Incorporates a logout processing filter. Most web applications require a logout filter, although you may not require one if you write a controller to provider similar logic. + + + + + + + Enables concurrent session control, limiting the number of authenticated sessions a user may have at the same time. + + + + + + + + Sets up remember-me authentication. If used with the "key" attribute (or no attributes) the cookie-only implementation will be used. Specifying "token-repository-ref" or "remember-me-data-source-ref" will use the more secure, persisten token approach. + + + + + Adds support for automatically granting all anonymous web requests a particular principal identity and a corresponding granted authority. + + + + + Defines the list of mappings between http and https ports for use in redirects + + + + + + + + + + + + + + + + + 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". + + + + + Enables the use of expressions in the 'access' attributes in <intercept-url> elements rather than the traditional list of configuration attributes. Defaults to 'false'. If enabled, each attribute should contain a single boolean expression. If the expression evaluates to 'true', access will be granted. + + + + + Controls the eagerness with which an HTTP session is created. If not set, defaults to "ifRequired". Note that if a custom SecurityContextRepository is set using security-context-repository-ref, then the only value which can be set is "always". Otherwise the session creation behaviour will be determined by the repository bean implementation. + + + + + + + + + + + + A reference to a SecurityContextRepository bean. This can be used to customize how the SecurityContext is stored between requests. + + + + + Defines the type of pattern used to specify URL paths (either JDK 1.4-compatible regular expressions, or Apache Ant expressions). Defaults to "ant" if unspecified. + + + + + + + + + + + Whether test URLs should be converted to lower case prior to comparing with defined path patterns. If unspecified, defaults to "true". + + + + + Provides versions of HttpServletRequest security methods such as isUserInRole() and getPrincipal() which are implemented by accessing the Spring SecurityContext. Defaults to "true". + + + + + Optional attribute specifying the ID of the AccessDecisionManager implementation which should be used for authorizing HTTP requests. + + + + + Optional attribute specifying the realm name that will be used for all authentication features that require a realm name (eg BASIC and Digest authentication). If unspecified, defaults to "Spring Security Application". + + + + + Allows a customized AuthenticationEntryPoint to be set on the ExceptionTranslationFilter. + + + + + Corresponds to the observeOncePerRequest property of FilterSecurityInterceptor. Defaults to "true" + + + + + Deprecated in favour of the access-denied-handler element. + + + + + + + + + + + + + Defines a reference to a Spring bean Id. + + + + + The access denied page that an authenticated user will be redirected to if they request a page which they don't have the authority to access. + + + + + + + The access denied page that an authenticated user will be redirected to if they request a page which they don't have the authority to access. + + + + + + + + The pattern which defines the URL path. The content will depend on the type set in the containing http element, so will default to ant path syntax. + + + + + The access configuration attributes that apply for the configured path. + + + + + The HTTP Method for which the access configuration attributes should apply. If not specified, the attributes will apply to any method. + + + + + + + + + + + + + + + + The filter list for the path. Currently can be set to "none" to remove a path from having any filters applied. The full filter stack (consisting of all filters created by the namespace configuration, and any added using 'custom-filter'), will be applied to any other paths. + + + + + + + + + + Used to specify that a URL must be accessed over http or https, or that there is no preference. The value should be "http", "https" or "any", respectively. + + + + + + + + Specifies the URL that will cause a logout. Spring Security will initialize a filter that responds to this particular URL. Defaults to /j_spring_security_logout if unspecified. + + + + + Specifies the URL to display once the user has logged out. If not specified, defaults to /. + + + + + Specifies whether a logout also causes HttpSession invalidation, which is generally desirable. If unspecified, defaults to true. + + + + + A reference to a LogoutSuccessHandler implementation which will be used to determine the destination to which the user is taken after logging out. + + + + + Allow the RequestCache used for saving requests during the login process to be set + + + + + + + + The URL that the login form is posted to. If unspecified, it defaults to /j_spring_security_check. + + + + + The URL that will be redirected to after successful authentication, if the user's previous action could not be resumed. This generally happens if the user visits a login page without having first requested a secured operation that triggers authentication. If unspecified, defaults to the root of the application. + + + + + Whether the user should always be redirected to the default-target-url after login. + + + + + The URL for the login page. If no login URL is specified, Spring Security will automatically create a login URL at /spring_security_login and a corresponding filter to render that login URL when requested. + + + + + The URL for the login failure page. If no login failure URL is specified, Spring Security will automatically create a failure login URL at /spring_security_login?login_error and a corresponding filter to render that login failure URL when requested. + + + + + Reference to an AuthenticationSuccessHandler bean which should be used to handle a successful authentication request. Should not be used in combination with default-target-url (or always-use-default-target-url) as the implementation should always deal with navigation to the subsequent destination + + + + + Reference to an AuthenticationFailureHandler bean which should be used to handle a failed authentication request. Should not be used in combination with authentication-failure-url as the implementation should always deal with navigation to the subsequent destination + + + + + + + + + + + + + + + + + + + + Used to explicitly configure a FilterChainProxy instance with a FilterChainMap + + + + Used within filter-chain-map to define a specific URL pattern and the list of filters which apply to the URLs matching that pattern. When multiple filter-chain elements are used within a filter-chain-map element, the most specific patterns must be placed at the top of the list, with most general ones at the bottom. + + + + + + + + + + + + + + + + Used to explicitly configure a FilterSecurityMetadataSource bean for use with a FilterSecurityInterceptor. Usually only needed if you are configuring a FilterChainProxy explicitly, rather than using the <http> element. The intercept-url elements used should only contain pattern, method and access attributes. Any others will result in a configuration error. + + + + Specifies the access attributes and/or filter list for a particular set of URLs. + + + + + + + + + + Enables the use of expressions in the 'access' attributes in <intercept-url> elements rather than the traditional list of configuration attributes. Defaults to 'false'. If enabled, each attribute should contain a single boolean expression. If the expression evaluates to 'true', access will be granted. + + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + as for http element + + + + + Defines the type of pattern used to specify URL paths (either JDK 1.4-compatible regular expressions, or Apache Ant expressions). Defaults to "ant" if unspecified. + + + + + + + + + + + Deprecated synonym for filter-security-metadata-source + + + + Specifies the access attributes and/or filter list for a particular set of URLs. + + + + + + + + + + + Sets the AuthenticationEntryPoint which is used by the BasicAuthenticationFilter. + + + + + + + + Indicates whether an existing session should be invalidated when a user authenticates and a new session started. If set to "none" no change will be made. "newSession" will create a new empty session. "migrateSession" will create a new session and copy the session attributes to the new session. Defaults to "migrateSession". + + + + + + + + + + + + The URL to which a user will be redirected if they submit an invalid session indentifier. Typically used to detect session timeouts. + + + + + Allows injection of the SessionAuthenticationStrategy instance used by the SessionManagementFilter + + + + + Defines the URL of the error page which should be shown when the SessionAuthenticationStrategy raises an exception. If not set, an unauthorized (402) error code will be returned to the client. Note that this attribute doesn't apply if the error occurs during a form-based login, where the URL for authentication failure will take precedence. + + + + + + + + The maximum number of sessions a single authenticated user can have open at the same time. Defaults to "1". + + + + + The URL a user will be redirected to if they attempt to use a session which has been "expired" because they have logged in again. + + + + + Specifies that an unauthorized error should be reported when a user attempts to login when they already have the maximum configured sessions open. The default behaviour is to expire the original session. If the session-authentication-error-url attribute is set on the session-management URL, the user will be redirected to this URL. + + + + + Allows you to define an alias for the SessionRegistry bean in order to access it in your own configuration. + + + + + Allows you to define an external SessionRegistry bean to be used by the concurrency control setup. + + + + + + + + The "key" used to identify cookies from a specific token-based remember-me application. You should set this to a unique value for your application. + + + + + Reference to a PersistentTokenRepository bean for use with the persistent token remember-me implementation. + + + + + A reference to a DataSource bean + + + + + + A reference to a user-service (or UserDetailsService bean) Id + + + + + Exports the internally defined RememberMeServices as a bean alias, allowing it to be used by other beans in the application context. + + + + + Determines whether the "secure" flag will be set on the remember-me cookie. If set to true, the cookie will only be submitted over HTTPS. Defaults to false. + + + + + The period (in seconds) for which the remember-me cookie should be valid. + + + + + + + Reference to a PersistentTokenRepository bean for use with the persistent token remember-me implementation. + + + + + + + Allows a custom implementation of RememberMeServices to be used. Note that this implementation should return RememberMeAuthenticationToken instances with the same "key" value as specified in the remember-me element. Alternatively it should register its own AuthenticationProvider. + + + + + + + + + + + The key shared between the provider and filter. This generally does not need to be set. If unset, it will default to "doesNotMatter". + + + + + The username that should be assigned to the anonymous request. This allows the principal to be identified, which may be important for logging and auditing. if unset, defaults to "anonymousUser". + + + + + The granted authority that should be assigned to the anonymous request. Commonly this is used to assign the anonymous request particular roles, which can subsequently be used in authorization decisions. If unset, defaults to "ROLE_ANONYMOUS". + + + + + With the default namespace setup, the anonymous "authentication" facility is automatically enabled. You can disable it using this property. + + + + + + + + + + + + + + + + The regular expression used to obtain the username from the certificate's subject. Defaults to matching on the common name using the pattern "CN=(.*?),". + + + + + A reference to a user-service (or UserDetailsService bean) Id + + + + + Registers the AuthenticationManager instance and allows its list of AuthenticationProviders to be defined. Also allows you to define an alias to allow you to reference the AuthenticationManager in your own beans. + + + + Indicates that the contained user-service should be used as an authentication source. + + + + + element which defines a password encoding strategy. Used by an authentication provider to convert submitted passwords to hashed versions, for example. + + + + Password salting strategy. A system-wide constant or a property from the UserDetails object can be used. + + + + A property of the UserDetails object which will be used as salt by a password encoder. Typically something like "username" might be used. + + + + + A single value that will be used as the salt for a password encoder. + + + + + Defines a reference to a Spring bean Id. + + + + + + + + + + + Sets up an ldap authentication provider + + + + Specifies that an LDAP provider should use an LDAP compare operation of the user's password to authenticate the user + + + + element which defines a password encoding strategy. Used by an authentication provider to convert submitted passwords to hashed versions, for example. + + + + Password salting strategy. A system-wide constant or a property from the UserDetails object can be used. + + + + A property of the UserDetails object which will be used as salt by a password encoder. Typically something like "username" might be used. + + + + + A single value that will be used as the salt for a password encoder. + + + + + Defines a reference to a Spring bean Id. + + + + + + + + + + + + + + + + + + + The alias you wish to use for the AuthenticationManager bean + + + + + If set to true, the AuthenticationManger will attempt to clear any credentials data in the returned Authentication object, once the user has been authenticated. Defaults to false. + + + + + + + + Defines a reference to a Spring bean Id. + + + + + A reference to a user-service (or UserDetailsService bean) Id + + + + + Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements. + + + + Represents a user in the application. + + + + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + + + + + + + + The username assigned to the user. + + + + + The password assigned to the user. This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element). This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities. If omitted, the namespace will generate a random value, preventing its accidental use for authentication. Cannot be empty. + + + + + One of more authorities granted to the user. Separate authorities with a comma (but no space). For example, "ROLE_USER,ROLE_ADMINISTRATOR" + + + + + Can be set to "true" to mark an account as locked and unusable. + + + + + Can be set to "true" to mark an account as disabled and unusable. + + + + + Causes creation of a JDBC-based UserDetailsService. + + + + A bean identifier, used for referring to the bean elsewhere in the context. + + + + + + + + The bean ID of the DataSource which provides the required tables. + + + + + Defines a reference to a cache for use with a UserDetailsService. + + + + + An SQL statement to query a username, password, and enabled status given a username + + + + + An SQL statement to query for a user's granted authorities given a username. + + + + + An SQL statement to query user's group authorities given a username. + + + + + A non-empty string prefix that will be added to role strings loaded from persistent storage (e.g. "ROLE_"). Use the value "none" for no prefix in cases where the default is non-empty. + + + + + + Used to indicate that a filter bean declaration should be incorporated into the security filter chain. + + + + + + + + The filter immediately after which the custom-filter should be placed in the chain. This feature will only be needed by advanced users who wish to mix their own filters into the security filter chain and have some knowledge of the standard Spring Security filters. The filter names map to specific Spring Security implementation filters. + + + + + The filter immediately before which the custom-filter should be placed in the chain + + + + + The explicit position at which the custom-filter should be placed in the chain. Use if you are replacing a standard filter. + + + + + + + The filter immediately after which the custom-filter should be placed in the chain. This feature will only be needed by advanced users who wish to mix their own filters into the security filter chain and have some knowledge of the standard Spring Security filters. The filter names map to specific Spring Security implementation filters. + + + + + + + The filter immediately before which the custom-filter should be placed in the chain + + + + + + + The explicit position at which the custom-filter should be placed in the chain. Use if you are replacing a standard filter. + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/src/test/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParserTests.java b/config/src/test/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParserTests.java index bb0a55561a..afac521328 100644 --- a/config/src/test/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParserTests.java +++ b/config/src/test/java/org/springframework/security/config/http/HttpSecurityBeanDefinitionParserTests.java @@ -80,6 +80,7 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi import org.springframework.security.web.context.HttpSessionSecurityContextRepository; import org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper; import org.springframework.security.web.context.SecurityContextPersistenceFilter; +import org.springframework.security.web.firewall.DefaultHttpFirewall; import org.springframework.security.web.savedrequest.HttpSessionRequestCache; import org.springframework.security.web.savedrequest.RequestCacheAwareFilter; import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; @@ -1251,6 +1252,18 @@ public class HttpSecurityBeanDefinitionParserTests { fcp.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); } + @Test + public void httpFirewallInjectionIsSupported() throws Exception { + setContext( + "" + + "" + + " " + + "" + + "" + + AUTH_PROVIDER_XML); + FilterChainProxy fcp = (FilterChainProxy) appContext.getBean(BeanIds.FILTER_CHAIN_PROXY); + assertSame(appContext.getBean("fw"), FieldUtils.getFieldValue(fcp, "firewall")); + } private void setContext(String context) { appContext = new InMemoryXmlApplicationContext(context); diff --git a/config/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java b/config/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java index abdcc5ed7d..f8214a27ac 100644 --- a/config/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java +++ b/config/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java @@ -22,11 +22,11 @@ public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext Resource inMemoryXml; public InMemoryXmlApplicationContext(String xml) { - this(xml, "3.0.3", null); + this(xml, "3.0.4", null); } public InMemoryXmlApplicationContext(String xml, ApplicationContext parent) { - this(xml, "3.0.3", parent); + this(xml, "3.0.4", parent); } public InMemoryXmlApplicationContext(String xml, String secVersion, ApplicationContext parent) { diff --git a/docs/manual/src/docbook/appendix-namespace.xml b/docs/manual/src/docbook/appendix-namespace.xml index e606f87aa2..3e25b52655 100644 --- a/docs/manual/src/docbook/appendix-namespace.xml +++ b/docs/manual/src/docbook/appendix-namespace.xml @@ -1,638 +1,759 @@ - - The Security Namespace - - This appendix provides a reference to the elements available in the security namespace 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 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. -
- Web Application Security - the <literal><http></literal> Element - The <http> element encapsulates the security configuration for - the web layer of your application. It creates a FilterChainProxy bean - named "springSecurityFilterChain" which maintains the stack of security filters which make up - the web security configuration - See the introductory chapter for how to set up - the mapping from your web.xml - . Some core filters are always created and others will be added to the stack - depending on the attributes 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). - The <http> namespace block always creates an - HttpSessionContextIntegrationFilter, 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. -
- <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 stack. Defaults to "true". -
-
- <literal>path-type</literal> - Controls whether URL patterns are interpreted as ant paths (the default) or regular - expressions. In practice this sets a particular UrlMatcher - instance on the FilterChainProxy. -
-
- <literal>lowercase-comparisons</literal> - Whether test URLs should be converted to lower case prior to comparing with defined - path patterns. If unspecified, defaults to "true" -
-
- <literal>realm</literal> - Sets the realm name used for basic authentication (if enabled). Corresponds to the - realmName property on - 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. -
-
- <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. -
-
- <literal>access-denied-page</literal> - Deprecated in favour of the access-denied-handler child element. - -
-
- <literal>once-per-request</literal> - Corresponds to the observeOncePerRequest property of - 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 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. -
-
-
- <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 section on the - 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 and to exclude particular patterns from - the filter chain entirely (by setting the attribute filters="none"). 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 - path-type attribute from the containing http element, so will default - to ant path syntax. -
-
- <literal>method</literal> - The HTTP Method which will be used in combination with the pattern to match an - incoming request. If omitted, any method will match. If an identical pattern is specified - with and without a method, the method-specific match will take precedence. -
-
- <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). -
-
- <literal>requires-channel</literal> - Can be http or https depending on whether a 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 - context. - If a <port-mappings> configuration is added, this will be - used to by the SecureChannelProcessor and - InsecureChannelProcessor beans to determine the ports used for - redirecting to HTTP/HTTPS. -
-
- <literal>filters</literal> - Can only take the value none. This will cause any matching request to - bypass the Spring Security filter chain entirely. None of the rest of the - <http> configuration will have any effect on the request and there - will be no security context available for its duration. Access to secured methods during - the request will fail. -
-
-
- The <literal><port-mappings></literal> Element - By default, an instance of PortMapperImpl will be added to the - configuration for use in redirecting to secure and insecure URLs. This element can - optionally be used to override the default mappings which that class defines. 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. -
-
- The <literal><form-login></literal> Element - Used to add an UsernamePasswordAuthenticationFilter to the - filter stack and an LoginUrlAuthenticationEntryPoint to the - 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. - 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 - "/spring-security-login". -
-
- <literal>login-processing-url</literal> - Maps to the filterProcessesUrl property of - 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 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 URL. -
-
- <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 login page. - Maps to the alwaysUseDefaultTargetUrl property of - 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 "/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. -
-
- <literal>authentication-success-handler-ref</literal> - This can be used as an alternative to default-target-url and - always-use-default-target, giving you full control over the - navigation flow after a successful authentication. The value should be he name of an - AuthenticationSuccessHandler bean in the application - context. -
-
- <literal>authentication-failure-handler-ref</literal> - Can be used as an alternative to authentication-failure-url, giving - you full control over the navigation flow after an authentication failure. The value - should be he name of an AuthenticationFailureHandler bean - in the application context. -
-
-
- The <literal><http-basic></literal> Element - Adds a BasicAuthenticationFilter and - BasicAuthenticationEntryPoint to the configuration. The latter will - only be used as the configuration entry point if form-based login is not enabled. -
-
- 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. -
- <literal>data-source-ref</literal> - If this is set, PersistentTokenBasedRememberMeServices will be - used and configured with a JdbcTokenRepositoryImpl instance. - -
-
- <literal>token-repository-ref</literal> - Configures a PersistentTokenBasedRememberMeServices but allows - the use of a custom 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 context which implements this interface. -
-
- <literal>token-repository-ref</literal> - Configures a PersistentTokenBasedRememberMeServices but allows - the use of a custom PersistentTokenRepository bean. -
-
- The <literal>key</literal> Attribute - Maps to the "key" property of 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. - . -
-
- <literal>token-validity-seconds</literal> - Maps to the tokenValiditySeconds property of - 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 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. -
-
-
- The <literal><session-management></literal> Element - Session-management related functionality is implemented by the addition of a - SessionManagementFilter to the filter stack. -
- <literal>session-fixation-protection</literal> - Indicates whether an existing session should be invalidated when a user authenticates - and a new session started. If set to "none" no change will be made. "newSession" will - create a new empty session. "migrateSession" will create 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. -
-
-
- 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. -
- The <literal>max-sessions</literal> attribute - Maps to the maximumSessions property of - ConcurrentSessionControlStrategy. -
-
- The <literal>expired-url</literal> attribute - The URL a user will be redirected to if they attempt to use a session which has been - "expired" by the concurrent session controller because the user has exceeded the number of - allowed sessions and has logged in again elsewhere. Should be set unless - exception-if-maximum-exceeded is set. If no value is supplied, an - expiry message will just be written directly back to the response. -
-
- The <literal>error-if-maximum-exceeded</literal> attribute - If set to "true" a 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 - 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. - It can also be useful to have a reference to the internal session registry for use in - your own beans or an admin interface. You can expose the interal bean using the - session-registry-alias attribute, giving it a name that you can use - elsewhere in your configuration. -
-
-
- The <literal><anonymous></literal> Element - Adds an AnonymousAuthenticationFilter to the stack and an - 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 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. -
- 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). -
-
- The <literal>user-service-ref</literal> attribute - Allows a specific UserDetailsService to be used with - X.509 in the case where multiple instances are configured. If not set, an attempt will be - made to locate a suitable instance automatically and use that. -
-
-
- The <literal><openid-login></literal> Element - 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 attribute, or will be - located automatically in the application context. -
-
- The <literal><logout></literal> Element - Adds a LogoutFilter to the filter stack. This is configured with - a SecurityContextLogoutHandler. -
- The <literal>logout-url</literal> attribute - The URL which will cause a logout (i.e. which will be processed by the filter). - Defaults to "/j_spring_security_logout". -
-
- The <literal>logout-success-url</literal> attribute - The destination URL which the user will be taken to after logging out. Defaults to - "/". -
-
- The <literal>invalidate-session</literal> attribute - Maps to the invalidateHttpSession of the - 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 maintained by - Spring Security. Full details can be found in the namespace chapter. -
-
-
- 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 configured - with a list of one or more 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. -
- 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. -
- 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 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. -
- 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 instance, potentially with an - accompanying SaltSource bean to provide salt values for - hashing. + If a <port-mappings> configuration is added, this + will be used to by the SecureChannelProcessor and + InsecureChannelProcessor beans to determine the ports + used for redirecting to HTTP/HTTPS. +
+
+ <literal>filters</literal> + Can only take the value none. This will cause any matching + request to bypass the Spring Security filter chain entirely. None of the rest of + the <http> configuration will have any effect on the + request and there will be no security context available for its duration. Access + to secured methods during the request will fail. +
-
-
- Using <literal><authentication-provider></literal> to refer to an - <interfacename>AuthenticationProvider</interfacename> 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: + The <literal><port-mappings></literal> Element + By default, an instance of PortMapperImpl will be added to + the configuration for use in redirecting to secure and insecure URLs. This element + can optionally be used to override the default mappings which that class defines. + 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. +
+
+ The <literal><form-login></literal> Element + Used to add an UsernamePasswordAuthenticationFilter to the + filter stack and an LoginUrlAuthenticationEntryPoint to the + 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. + 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 + "/spring_security_login". +
+
+ <literal>login-processing-url</literal> + Maps to the filterProcessesUrl property of + 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 + 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 + URL. +
+
+ <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 + login page. Maps to the alwaysUseDefaultTargetUrl property of + 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 + "/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. +
+
+ <literal>authentication-success-handler-ref</literal> + This can be used as an alternative to default-target-url + and always-use-default-target, giving you full control over + 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. +
+
+ <literal>authentication-failure-handler-ref</literal> + Can be used as an alternative to + authentication-failure-url, giving you full control over the + navigation flow after an authentication failure. The value should be he name of + an AuthenticationFailureHandler bean in the + application context. +
+
+
+ The <literal><http-basic></literal> Element + Adds a BasicAuthenticationFilter and + BasicAuthenticationEntryPoint to the configuration. The + latter will only be used as the configuration entry point if form-based login is not + enabled. +
+
+ 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. +
+ <literal>data-source-ref</literal> + If this is set, PersistentTokenBasedRememberMeServices + will be used and configured with a + JdbcTokenRepositoryImpl instance. +
+
+ <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 + context which implements this interface. Should also implement + LogoutHandler if a logout filter is in use. +
+
+ <literal>token-repository-ref</literal> + Configures a PersistentTokenBasedRememberMeServices + but allows the use of a custom + PersistentTokenRepository bean. +
+
+ The <literal>key</literal> Attribute + Maps to the "key" property of + 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. + . +
+
+ <literal>token-validity-seconds</literal> + Maps to the tokenValiditySeconds property of + 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 + 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. +
+
+
+ The <literal><session-management></literal> Element + Session-management related functionality is implemented by the addition of a + SessionManagementFilter to the filter stack. +
+ <literal>session-fixation-protection</literal> + Indicates whether an existing session should be invalidated when a user + authenticates and a new session started. If set to "none" no change will be + made. "newSession" will create a new empty session. "migrateSession" will create + 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. +
+
+
+ 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. +
+ The <literal>max-sessions</literal> attribute + Maps to the maximumSessions property of + ConcurrentSessionControlStrategy. +
+
+ The <literal>expired-url</literal> attribute + The URL a user will be redirected to if they attempt to use a session which + has been "expired" by the concurrent session controller because the user has + exceeded the number of allowed sessions and has logged in again elsewhere. + Should be set unless exception-if-maximum-exceeded is set. If + no value is supplied, an expiry message will just be written directly back to + the response. +
+
+ The <literal>error-if-maximum-exceeded</literal> attribute + If set to "true" a + 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 + 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. + It can also be useful to have a reference to the internal session registry + for use in your own beans or an admin interface. You can expose the interal bean + using the session-registry-alias attribute, giving it a name + that you can use elsewhere in your configuration. +
+
+
+ The <literal><anonymous></literal> Element + Adds an AnonymousAuthenticationFilter to the stack and an + 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 + 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. +
+ 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). +
+
+ The <literal>user-service-ref</literal> attribute + Allows a specific UserDetailsService to be + used with X.509 in the case where multiple instances are configured. If not set, + an attempt will be made to locate a suitable instance automatically and use + that. +
+
+
+ The <literal><openid-login></literal> Element + 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 + attribute, or will be located automatically in the application context. +
+ The <literal><attribute-exchange></literal> Element + The attribute-exchange element defines the list of + attributes which should be requested from the identity provider. More than one + can be used, in which case each must have an identifier-match + attribute, containing a regular expression which is matched against the supplied + OpenID identifer. This allows different attribute lists to be fetched from + different providers (Google, Yahoo etc). +
+
+
+ The <literal><logout></literal> Element + Adds a LogoutFilter to the filter stack. This is + configured with a SecurityContextLogoutHandler. +
+ The <literal>logout-url</literal> attribute + The URL which will cause a logout (i.e. which will be processed by the + filter). Defaults to "/j_spring_security_logout". +
+
+ The <literal>logout-success-url</literal> attribute + The destination URL which the user will be taken to after logging out. + Defaults to "/". +
+
+ The <literal>success-handler-ref</literal> attribute + May be used to supply an instance of LogoutSuccessHandler + which will be invoked to control the navigation after logging out. + +
+
+ The <literal>invalidate-session</literal> attribute + Maps to the invalidateHttpSession of the + SecurityContextLogoutHandler. Defaults to "true", so the + session will be invalidated on logout. +
+
+ The <literal>delete-cookies</literal> attribute + A comma-separated list of the names of cookies which should be deleted when the user logs out. + +
+
+
+ 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 + 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. +
+
+ The <literal><http-firewall></literal> Element + This is a top-level element which can be used to inject a custom implementation of + HttpFirewall into the + FilterChainProxy created by the namespace. The default + implementation should be suitable for most applications. +
+
+
+ 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 + configured with a list of one or more + 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. +
+ 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. +
+ 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 + 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. +
+ 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 + instance, potentially with an accompanying + SaltSource bean to provide salt values for + hashing. +
+
+
+ Using <literal><authentication-provider></literal> to refer to an + <interfacename>AuthenticationProvider</interfacename> 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: ]]> -
+
+
- -
- Method Security -
- The <literal><global-method-security></literal> Element - This element is the primary means of adding support for securing methods on Spring - Security beans. Methods can be secured by the use of annotations (defined at 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. -
- The <literal>secured-annotations</literal> and <literal>jsr250-annotations</literal> - 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 annotations. -
-
- Securing Methods using <literal><protect-pointcut></literal> - Rather than defining security attributes on an individual method or class basis using - the @Secured annotation, you can define 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 - - You can find an example in the 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. -
+
+ Method Security +
+ The <literal><global-method-security></literal> Element + This element is the primary means of adding support for securing methods on + Spring Security beans. Methods can be secured by the use of annotations (defined at + 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. +
+ The <literal>secured-annotations</literal> and + <literal>jsr250-annotations</literal> 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 + 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. +
+
+ Securing Methods using <literal><protect-pointcut></literal> + Rather than defining security attributes on an individual method or class + basis using the @Secured annotation, you can define + 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 + + You can find an example in the 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. +
+
+
+ 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 + 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 + 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 + 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. + 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 + 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 + authentication providers, it must be included as a child of the + 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. +
+
+ The <literal>user-search-base</literal> and + <literal>user-search-filter</literal> 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. +
+
+ <literal>group-search-filter</literal>, + <literal>group-search-base</literal>, + <literal>group-role-attribute</literal> and <literal>role-prefix</literal> + Attributes + The value of group-search-base is mapped to the + 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". + Similarly role-prefix maps to + 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. +
+
+
+ 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>. +
+
-
- 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 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 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 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. - 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 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 authentication - providers, it must be included as a child of the - 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. -
-
- The <literal>user-search-base</literal> and <literal>user-search-filter</literal> - 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. -
-
- <literal>group-search-filter</literal>, <literal>group-search-base</literal>, - <literal>group-role-attribute</literal> and <literal>role-prefix</literal> - Attributes - The value of group-search-base is mapped to the - 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". Similarly - role-prefix maps to 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. -
-
-
- 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>. -
-
-
diff --git a/web/src/main/java/org/springframework/security/web/FilterChainProxy.java b/web/src/main/java/org/springframework/security/web/FilterChainProxy.java index 8684a5a856..1f826ad82d 100644 --- a/web/src/main/java/org/springframework/security/web/FilterChainProxy.java +++ b/web/src/main/java/org/springframework/security/web/FilterChainProxy.java @@ -304,6 +304,10 @@ public class FilterChainProxy extends GenericFilterBean { return matcher; } + public void setFirewall(HttpFirewall firewall) { + this.firewall = firewall; + } + /** * If set to 'true', the query string will be stripped from the request URL before * attempting to find a matching filter chain. This is the default value.