diff --git a/docs/manual/src/docbook/namespace-config.xml b/docs/manual/src/docbook/namespace-config.xml index 137b6086db..26f42c2e4b 100644 --- a/docs/manual/src/docbook/namespace-config.xml +++ b/docs/manual/src/docbook/namespace-config.xml @@ -9,9 +9,9 @@ Namespace configuration has been available since version 2.0 of the Spring framework. It allows you to supplement the traditional Spring beans application context syntax with elements from additional XML schema. You can find more information in the Spring Reference Documentation. A namespace element can be used simply to allow a - more concise way of configuring an individual bean or, more powerfully, to define an + xlink:href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apc.html" + > Reference Documentation. A namespace element can be used simply to allow a more + concise way of configuring an individual bean or, more powerfully, to define an alternative configuration syntax which more closely matches the problem domain and hides the underlying complexity from the user. A simple element may conceal the fact that multiple beans and processing steps are being added to the application context. For @@ -22,15 +22,16 @@ beans. The most common alternative configuration requirements are supported by attributes on the ldap-server element and the user is isolated from worrying about which beans they need to create and what the bean property names are. - You can find out more about the use of the ldap-server - element in the chapter on LDAP. + You can find out more about the use of the ldap-server element + in the chapter on LDAP. . Use of a good XML editor while editing the application context file should provide information on the attributes and elements that are available. We would recommend that you try out the SpringSource Tool Suite - as it has special features for working with standard Spring namespaces. - To start using the security namespace in your application context, all you need to do - is add the schema declaration to your application context file: + xlink:href="http://www.springsource.com/products/sts">SpringSource Tool Suite as + it has special features for working with standard Spring namespaces. + To start using the security namespace in your application context, you need to have + the spring-security-config jar on your classpath. Then all you need + to do is add the schema declaration to your application context file: - - - Web/HTTP Security - the most complex part. Sets up - the filters and related service beans used to apply the framework - authentication mechanisms, to secure URLs, render login and error pages - and much more. - - - - Business Object (Method) Security - options for - securing the service layer. - - - - AuthenticationManager - handles authentication - requests from other parts of the framework. - - - - AccessDecisionManager - provides access decisions - for web and method security. A default one will be registered, but you - can also choose to use a custom one, declared using normal Spring bean - syntax. - - - - AuthenticationProviders - mechanisms against which - the authentication manager authenticates users. The namespace provides - supports for several standard options and also a means of adding custom - beans declared using a traditional syntax. - - - - UserDetailsService - closely related to - authentication providers, but often also required by other beans. - - + + Web/HTTP Security - the most complex part. Sets up + the filters and related service beans used to apply the framework + authentication mechanisms, to secure URLs, render login and error pages and + much more. + + + Business Object (Method) Security - options for + securing the service layer. + + + AuthenticationManager - handles authentication + requests from other parts of the framework. + + + AccessDecisionManager - provides access decisions + for web and method security. A default one will be registered, but you can + also choose to use a custom one, declared using normal Spring bean + syntax. + + + AuthenticationProviders - mechanisms against which + the authentication manager authenticates users. The namespace provides + supports for several standard options and also a means of adding custom + beans declared using a traditional syntax. + + + UserDetailsService - closely related to + authentication providers, but often also required by other beans. + + We'll see how to configure these in the following sections. @@ -115,7 +110,7 @@
<literal>web.xml</literal> Configuration The first thing you need to do is add the following filter declaration to your - web.xml file: web.xml file: springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy @@ -129,12 +124,11 @@ infrastructure. DelegatingFilterProxy is a Spring Framework class which delegates to a filter implementation which is defined as a Spring bean in your application context. In this case, the bean is named - springSecurityFilterChain, which is an internal infrastructure - bean created by the namespace to handle web security. Note that you should not use - this bean name yourself. Once you've added this to your - web.xml, you're ready to start editing your application context - file. Web security services are configured using the <http> - element. + springSecurityFilterChain, which is an internal infrastructure bean + created by the namespace to handle web security. Note that you should not use this + bean name yourself. Once you've added this to your web.xml, + you're ready to start editing your application context file. Web security services + are configured using the <http> element.
A Minimal <literal><http></literal> Configuration @@ -145,12 +139,12 @@ ]]> Which says that we want all URLs within our application to be secured, requiring the role ROLE_USER to access them. The - <http> element is the parent for all web-related namespace + <http> element is the parent for all web-related namespace functionality. The <intercept-url> element defines a - pattern which is matched against the URLs of incoming - requests using an ant path style syntax. You can also use regular-expression - matching as an alternative (see the namespace appendix for more details). The - access attribute defines the access requirements for requests + pattern which is matched against the URLs of incoming requests + using an ant path style syntax. You can also use regular-expression matching as an + alternative (see the namespace appendix for more details). The + access attribute defines the access requirements for requests matching the given pattern. With the default configuration, this is typically a comma-separated list of roles, one of which a user must have to be allowed to make the request. The prefix ROLE_ is a marker which indicates that a @@ -159,18 +153,18 @@ limited to the use of simple roles (hence the use of the prefix to differentiate between different types of security attributes). We'll see later how the interpretation can vary - The interpretation of the comma-separated values in the - access attribute depends on the implementation of the - AccessDecisionManager which - is used. In Spring Security 3.0, the attribute can also be populated with an - EL expression. + The interpretation of the comma-separated values in the + access attribute depends on the implementation of the AccessDecisionManager which is used. In + Spring Security 3.0, the attribute can also be populated with an EL expression. . You can use multiple <intercept-url> elements to define different access requirements for different sets of URLs, but they will be evaluated in the order listed and the first match will be used. So you must put the most specific matches at the top. You can also add a - method attribute to limit the match to a particular HTTP + method attribute to limit the match to a particular HTTP method (GET, POST, PUT etc.). If a request matches multiple patterns, the method-specific match will take precedence regardless of ordering. @@ -189,17 +183,17 @@ If you are familiar with pre-namespace versions of the framework, you can probably already guess roughly what's going on here. The - <http> element is responsible for creating a - FilterChainProxy and the filter beans which it uses. + <http> element is responsible for creating a + FilterChainProxy and the filter beans which it uses. Common problems like incorrect filter ordering are no longer an issue as the filter positions are predefined. The <authentication-provider> element creates a - DaoAuthenticationProvider bean and the - <user-service> element creates an - InMemoryDaoImpl. All - authentication-provider elements must be children of the - <authentication-manager> element, which creates a - ProviderManager and registers the authentication + DaoAuthenticationProvider bean and the + <user-service> element creates an + InMemoryDaoImpl. All + authentication-provider elements must be children of the + <authentication-manager> element, which creates a + ProviderManager and registers the authentication providers with it. You can find more detailed information on the beans that are created in the namespace appendix. It's worth cross-checking this if you want to start understanding what the @@ -209,20 +203,20 @@ The configuration above defines two users, their passwords and their roles within the application (which will be used for access control). It is also possible to load user information from a standard properties file using the - properties attribute on user-service. See - the section on in-memory - authentication for more details on the file format. Using the - <authentication-provider> element means that the user + properties attribute on user-service. See the + section on in-memory + authentication for more details on the file format. Using the + <authentication-provider> element means that the user information will be used by the authentication manager to process authentication requests. You can have multiple <authentication-provider> elements to define different authentication sources and each will be consulted in turn. At this point you should be able to start up your application and you will be required to log in to proceed. Try it out, or try experimenting with the - tutorial sample application that comes with the project. The - above configuration actually adds quite a few services to the application because we - have used the auto-config attribute. For example, form-based - login processing is automatically enabled. + tutorial sample application that comes with the project. The above + configuration actually adds quite a few services to the application because we have + used the auto-config attribute. For example, form-based login + processing is automatically enabled.
What does <literal>auto-config</literal> Include? The auto-config attribute, as we have used it above, is @@ -234,16 +228,16 @@ ]]> These other elements are responsible for setting up form-login, basic authentication and logout handling services respectively - In versions prior to 3.0, this list also included remember-me - functionality. This could cause some confusing errors with some - configurations and was removed in 3.0. In 3.0, the addition of an - AnonymousAuthenticationFilter is part of the - default <http> configuration, so the - <anonymous /> element is added regardless of - whether auto-config is enabled. + In versions prior to 3.0, this list also included remember-me + functionality. This could cause some confusing errors with some + configurations and was removed in 3.0. In 3.0, the addition of an + AnonymousAuthenticationFilter is part of the default + <http> configuration, so the <anonymous + /> element is added regardless of whether + auto-config is enabled. . They each have attributes which can be used to alter their - behaviour. In anything other than very basic scenarios, it is probably better - to omit the auto-config attribute and configure what you require + behaviour. In anything other than very basic scenarios, it is probably better to + omit the auto-config attribute and configure what you require explicitly in the interest of clarity.
@@ -264,21 +258,20 @@ ]]> Note that you can still use auto-config. The - form-login element just overrides the default settings. Also - note that we've added an extra intercept-url element to say that - any requests for the login page should be available to anonymous users - See the chapter on anonymous - authentication and also the AuthenticatedVoter class - for more details on how the value - IS_AUTHENTICATED_ANONYMOUSLY is processed. + form-login element just overrides the default settings. Also note + that we've added an extra intercept-url element to say that any + requests for the login page should be available to anonymous users + See the chapter on anonymous + authentication and also the AuthenticatedVoter class for more details on how the value + IS_AUTHENTICATED_ANONYMOUSLY is processed. . Otherwise the request would be matched by the pattern - /** and it wouldn't be possible to access the login page - itself! This is a common configuration error and will result in an infinite loop in - the application. Spring Security will emit a warning in the log if your login page + /** and it wouldn't be possible to access the login page itself! + This is a common configuration error and will result in an infinite loop in the + application. Spring Security will emit a warning in the log if your login page appears to be secured. It is also possible to have all requests matching a - particular pattern bypass the security filter chain completely, by defining a separate - http element for the pattern like this: http element for the pattern like this: @@ -287,27 +280,26 @@ ]]> - - From Spring Security 3.1 it is now possible to use multiple http - elements to define separate security filter chain configurations for different - request patterns. If the pattern attribute is omitted from an - http element, it matches all requests. Creating an unsecured - pattern is a simple example of this syntax, where the pattern is mapped to an empty filter chain - The use of multiple <http> elements is an - important feature, allowing the namespace to simultaneously support both stateful and stateless - paths within the same application, for example. The previous syntax, using the attribute - filters="none" on an intercept-url element - is incompatible with this change and is no longer supported in 3.1.. - We'll look at this new syntax in more detail in the chapter on the - Security Filter Chain. - - - It's important to realise that these unsecured requests will be completely - oblivious to any Spring Security web-related configuration or additional - attributes such as requires-channel, so you will not be able to - access information on the current user or call secured methods during the request. - Use access='IS_AUTHENTICATED_ANONYMOUSLY' as an alternative if - you still want the security filter chain to be applied. + From Spring Security 3.1 it is now possible to use multiple + http elements to define separate security filter chain + configurations for different request patterns. If the pattern + attribute is omitted from an http element, it matches all + requests. Creating an unsecured pattern is a simple example of this syntax, where + the pattern is mapped to an empty filter chain + The use of multiple <http> elements is an important + feature, allowing the namespace to simultaneously support both stateful and + stateless paths within the same application, for example. The previous syntax, + using the attribute filters="none" on an + intercept-url element is incompatible with this change and is + no longer supported in 3.1. + . We'll look at this new syntax in more detail in the chapter on the + Security Filter Chain. + It's important to realise that these unsecured requests will be completely + oblivious to any Spring Security web-related configuration or additional attributes + such as requires-channel, so you will not be able to access + information on the current user or call secured methods during the request. Use + access='IS_AUTHENTICATED_ANONYMOUSLY' as an alternative if you + still want the security filter chain to be applied. If you want to use basic authentication instead of form login, then change the configuration to @@ -327,9 +319,9 @@ "/". You can also configure things so that the user always ends up at this page (regardless of whether the login was "on-demand" or they explicitly chose to log in) by setting the - always-use-default-target attribute to "true". This is - useful if your application always requires that the user starts at a "home" - page, for example: always-use-default-target attribute to "true". This is useful + if your application always requires that the user starts at a "home" page, for + example: @@ -338,11 +330,11 @@ ]]> For even more control over the destination, you can use the - authentication-success-handler-ref attribute as an + authentication-success-handler-ref attribute as an alternative to default-target-url. The referenced bean should be an instance of AuthenticationSuccessHandler. You'll find more on this in the Core Filters chapter and also in the namespace appendix, as well as + >Core Filters chapter and also in the namespace appendix, as well as information on how to customize the flow when authentication fails. @@ -353,7 +345,7 @@ user information in something like a database or an LDAP server. LDAP namespace configuration is dealt with in the LDAP chapter, so we won't cover it here. If you have a custom implementation of Spring Security's - UserDetailsService, called "myUserDetailsService" in your + UserDetailsService, called "myUserDetailsService" in your application context, then you can authenticate against this using @@ -367,12 +359,11 @@ ]]> Where securityDataSource is the name of a - DataSource bean in the application context, pointing at a + DataSource bean in the application context, pointing at a database containing the standard Spring Security user data tables. - Alternatively, you could configure a Spring Security - JdbcDaoImpl bean and point at that using the - user-service-ref attribute: user data tables. Alternatively, + you could configure a Spring Security JdbcDaoImpl bean and + point at that using the user-service-ref attribute: @@ -383,18 +374,18 @@ ]]> You can also use standard - AuthenticationProvider beans as follows AuthenticationProvider beans as follows ]]> where myAuthenticationProvider is the name of a bean in your application context which implements - AuthenticationProvider. You can use multiple - authentication-provider elements, in which case the providers + AuthenticationProvider. You can use multiple + authentication-provider elements, in which case the providers will be queried in the order they are declared. See for more on information on how the Spring Security - AuthenticationManager is configured using the + AuthenticationManager is configured using the namespace.
Adding a Password Encoder @@ -425,8 +416,8 @@ ]]> You can use a custom password encoder bean by using the - ref attribute of password-encoder. - This should contain the name of a bean in the application context which is an + ref attribute of password-encoder. This + should contain the name of a bean in the application context which is an instance of Spring Security's PasswordEncoder interface.
@@ -443,8 +434,8 @@ Adding HTTP/HTTPS Channel Security If your application supports both HTTP and HTTPS, and you require that particular URLs can only be accessed over HTTPS, then this is directly supported using the - requires-channel attribute on - <intercept-url>: requires-channel attribute on + <intercept-url>: @@ -482,8 +473,8 @@ If you wish to place constraints on a single user's ability to log in to your application, Spring Security supports this out of the box with the following simple additions. First you need to add the following listener to your - web.xml file to keep Spring Security updated about - session lifecycle events: web.xml file to keep Spring Security updated about session + lifecycle events: org.springframework.security.web.session.HttpSessionEventPublisher @@ -506,45 +497,44 @@ ]]> The second login will then be rejected. By - rejected, we mean that the user will be sent to the - authentication-failure-url if form-based login is being - used. If the second authentication takes place through another non-interactive + rejected, we mean that the user will be sent to the + authentication-failure-url if form-based login is being used. + If the second authentication takes place through another non-interactive mechanism, such as remember-me, an unauthorized (402) error will be sent to the client. If instead you want to use an error page, you can add the attribute - session-authentication-error-url to the - session-management element. + session-authentication-error-url to the + session-management element. If you are using a customized authentication filter for form-based login, then you have to configure concurrent session control support explicitly. More details can be found in the Session Management - chapter. + chapter.
Session Fixation Attack Protection - - Session - fixation attacks are a potential risk where it is possible for a + Session + fixation attacks are a potential risk where it is possible for a malicious attacker to create a session by accessing a site, then persuade another user to log in with the same session (by sending them a link containing the session identifier as a parameter, for example). Spring Security protects against this automatically by creating a new session when a user logs in. If you don't require this protection, or it conflicts with some other requirement, you can control the behaviour using the - session-fixation-protection attribute on - <session-management>, which has three options - - migrateSession - creates a new session and - copies the existing session attributes to the new session. This is - the default. - - - none - Don't do anything. The original session - will be retained. - - - newSession - Create a new "clean" session, - without copying the existing session data. - + session-fixation-protection attribute on + <session-management>, which has three options + + migrateSession - creates a new session and copies + the existing session attributes to the new session. This is the + default. + + + none - Don't do anything. The original session will + be retained. + + + newSession - Create a new "clean" session, without + copying the existing session data. +
@@ -558,24 +548,23 @@ ]]>
You should then register yourself with an OpenID provider (such as myopenid.com), and add the user information to your in-memory - <user-service> : <user-service> : ]]> You should be able to login using the myopenid.com site to authenticate. It is also possible to select a specific - UserDetailsService bean for use OpenID by setting - the user-service-ref attribute on the - openid-login element. See the previous section on authentication providers for more - information. Note that we have omitted the password attribute from the above user - configuration, since this set of user data is only being used to load the - authorities for the user. A random password will be generate internally, preventing - you from accidentally using this user data as an authentication source elsewhere in - your configuration. + UserDetailsService bean for use OpenID by setting the + user-service-ref attribute on the openid-login + element. See the previous section on authentication providers for more information. Note that we have omitted the + password attribute from the above user configuration, since this set of user data is + only being used to load the authorities for the user. A random password will be + generate internally, preventing you from accidentally using this user data as an + authentication source elsewhere in your configuration.
Attribute Exchange Support for OpenID attribute exchange. As an example, the following configuration would + xlink:href="http://openid.net/specs/openid-attribute-exchange-1_0.html" + >attribute exchange. As an example, the following configuration would attempt to retrieve the email and full name from the OpenID provider, for use by the application: @@ -585,27 +574,26 @@ ]]>The type of each OpenID attribute is a URI, determined by a particular schema, in this case http://axschema.org/. If an - attribute must be retrieved for successful authentication, the - required attribute can be set. The exact schema and - attributes supported will depend on your OpenID provider. The attribute values - are returned as part of the authentication process and can be accessed - afterwards using the following code: + xlink:href="http://axschema.org/">http://axschema.org/. If an attribute + must be retrieved for successful authentication, the required + attribute can be set. The exact schema and attributes supported will depend on + your OpenID provider. The attribute values are returned as part of the + authentication process and can be accessed afterwards using the following code: OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication(); List<OpenIDAttribute> attributes = token.getAttributes();The - OpenIDAttribute contains the attribute type and the + OpenIDAttribute contains the attribute type and the retrieved value (or values in the case of multi-valued attributes). We'll see more about how the SecurityContextHolder class is used when we look at core Spring Security components in the technical overview chapter. Multiple + xlink:href="#core-components">technical overview chapter. Multiple attribute exchange configurations are also be supported, if you wish to use multiple identity providers. You can supply multiple - attribute-exchange elements, using an - identifier-matcher attribute on each. This contains a - regular expression which will be matched against the OpenID identifier supplied - by the user. See the OpenID sample application in the codebase for an example + attribute-exchange elements, using an + identifier-matcher attribute on each. This contains a regular + expression which will be matched against the OpenID identifier supplied by the + user. See the OpenID sample application in the codebase for an example configuration, providing different attribute lists for the Google, Yahoo and MyOpenID providers.
@@ -618,123 +606,122 @@ List<OpenIDAttribute> attributes = token.getAttributes();
The which there isn't currently a namespace configuration option (CAS, for example). Or you might want to use a customized version of a standard namespace filter, such as the UsernamePasswordAuthenticationFilter which is created by the - <form-login> element, taking advantage of some of the - extra configuration options which are available by using the bean explicitly. How - can you do this with namespace configuration, since the filter chain is not directly + <form-login> element, taking advantage of some of the extra + configuration options which are available by using the bean explicitly. How can you + do this with namespace configuration, since the filter chain is not directly exposed? The order of the filters is always strictly enforced when using the namespace. When the application context is being created, the filter beans are sorted by the namespace handling code and the standard Spring Security filters each have an alias in the namespace and a well-known position. - In previous versions, the sorting took place after the filter instances - had been created, during post-processing of the application context. In - version 3.0+ the sorting is now done at the bean metadata level, before the - classes have been instantiated. This has implications for how you add your - own filters to the stack as the entire filter list must be known during the - parsing of the <http> element, so the syntax has - changed slightly in 3.0. + In previous versions, the sorting took place after the filter instances had + been created, during post-processing of the application context. In version 3.0+ + the sorting is now done at the bean metadata level, before the classes have been + instantiated. This has implications for how you add your own filters to the + stack as the entire filter list must be known during the parsing of the + <http> element, so the syntax has changed slightly in + 3.0. The filters, aliases and namespace elements/attributes which create the filters are shown in . The filters are listed in the order in which they occur in the filter chain. - Standard Filter Aliases and Ordering - - - - - - - Alias - Filter Class - Namespace Element or Attribute - - - - - CHANNEL_FILTER - ChannelProcessingFilter - http/intercept-url@requires-channel - - - CONCURRENT_SESSION_FILTER - ConcurrentSessionFilter - - session-management/concurrency-control - - - SECURITY_CONTEXT_FILTER - SecurityContextPersistenceFilter - http - - - LOGOUT_FILTER - LogoutFilter - http/logout - - - X509_FILTER - X509AuthenticationFilter - http/x509 - - - PRE_AUTH_FILTER - AstractPreAuthenticatedProcessingFilter - Subclasses - N/A - - - CAS_FILTER - CasAuthenticationFilter - N/A - - - FORM_LOGIN_FILTER - UsernamePasswordAuthenticationFilter - http/form-login - - - BASIC_AUTH_FILTER - BasicAuthenticationFilter - http/http-basic - - - SERVLET_API_SUPPORT_FILTER - SecurityContextHolderAwareFilter - http/@servlet-api-provision - - - REMEMBER_ME_FILTER - RememberMeAuthenticationFilter - http/remember-me - - - ANONYMOUS_FILTER - AnonymousAuthenticationFilter - http/anonymous - - - SESSION_MANAGEMENT_FILTER - SessionManagementFilter - session-management - - - EXCEPTION_TRANSLATION_FILTER - ExceptionTranslationFilter - http - - - FILTER_SECURITY_INTERCEPTOR - FilterSecurityInterceptor - http - - - SWITCH_USER_FILTER - SwitchUserFilter - N/A - - - + Standard Filter Aliases and Ordering + + + + + + + Alias + Filter Class + Namespace Element or Attribute + + + + + CHANNEL_FILTER + ChannelProcessingFilter + http/intercept-url@requires-channel + + + CONCURRENT_SESSION_FILTER + ConcurrentSessionFilter + session-management/concurrency-control + + + SECURITY_CONTEXT_FILTER + SecurityContextPersistenceFilter + http + + + LOGOUT_FILTER + LogoutFilter + http/logout + + + X509_FILTER + X509AuthenticationFilter + http/x509 + + + PRE_AUTH_FILTER + AstractPreAuthenticatedProcessingFilter + Subclasses + N/A + + + CAS_FILTER + CasAuthenticationFilter + N/A + + + FORM_LOGIN_FILTER + UsernamePasswordAuthenticationFilter + http/form-login + + + BASIC_AUTH_FILTER + BasicAuthenticationFilter + http/http-basic + + + SERVLET_API_SUPPORT_FILTER + SecurityContextHolderAwareFilter + http/@servlet-api-provision + + + REMEMBER_ME_FILTER + RememberMeAuthenticationFilter + http/remember-me + + + ANONYMOUS_FILTER + AnonymousAuthenticationFilter + http/anonymous + + + SESSION_MANAGEMENT_FILTER + SessionManagementFilter + session-management + + + EXCEPTION_TRANSLATION_FILTER + ExceptionTranslationFilter + http + + + FILTER_SECURITY_INTERCEPTOR + FilterSecurityInterceptor + http + + + SWITCH_USER_FILTER + SwitchUserFilter + N/A + + +
You can add your own filter to the stack, using the - custom-filter element and one of these names to specify the + custom-filter element and one of these names to specify the position your filter should appear at: @@ -745,20 +732,20 @@ List<OpenIDAttribute> attributes = token.getAttributes();The
You can also use the after or before attributes if you want your filter to be inserted before or after another filter in the stack. The names "FIRST" and "LAST" can be used with the - position attribute to indicate that you want your filter to + position attribute to indicate that you want your filter to appear before or after the entire stack, respectively. Avoiding filter position conflicts If you are inserting a custom filter which may occupy the same position as one of the standard filters created by the namespace then it's important that you don't include the namespace versions by mistake. Avoid using the - auto-config attribute and remove any elements which - create filters whose functionality you want to replace. + auto-config attribute and remove any elements which create + filters whose functionality you want to replace. Note that you can't replace filters which are created by the use of the - <http> element itself - - SecurityContextPersistenceFilter, - ExceptionTranslationFilter or - FilterSecurityInterceptor. + <http> element itself - + SecurityContextPersistenceFilter, + ExceptionTranslationFilter or + FilterSecurityInterceptor. If you're replacing a namespace filter which requires an authentication entry point (i.e. where the authentication process is triggered by an attempt by an @@ -772,11 +759,11 @@ List<OpenIDAttribute> attributes = token.getAttributes();The a traditional bean syntax and link them into the namespace, as we've just seen. The corresponding AuthenticationEntryPoint can be set using the entry-point-ref attribute on the - <http> element. + <http> element. The CAS sample application is a good example of the use of custom beans with the namespace, including this syntax. If you aren't familiar with authentication entry points, they are discussed in the technical overview chapter. + xlink:href="#tech-intro-auth-entry-point">technical overview chapter. @@ -787,9 +774,9 @@ List<OpenIDAttribute> attributes = token.getAttributes();The security to your service layer methods. It provides support for JSR-250 annotation security as well as the framework's original @Secured annotation. From 3.0 you can also make use of new expression-based - annotations. You can apply security to a single bean, using the - intercept-methods element to decorate the bean declaration, or - you can secure multiple beans across the entire service layer using the AspectJ style + annotations. You can apply security to a single bean, using the + intercept-methods element to decorate the bean declaration, or you + can secure multiple beans across the entire service layer using the AspectJ style pointcuts.
The <literal><global-method-security></literal> Element @@ -797,14 +784,14 @@ List<OpenIDAttribute> attributes = token.getAttributes();The setting the appropriate attributes on the element), and also to group together security pointcut declarations which will be applied across your entire application context. You should only declare one - <global-method-security> element. The following - declaration would enable support for Spring Security's @Secured: <global-method-security> element. The following declaration + would enable support for Spring Security's @Secured: ]]> Adding an annotation to a method (on an class or interface) would then limit the access to that method accordingly. Spring Security's native annotation support defines a set of attributes for the method. These will be passed to the - AccessDecisionManager for it to make the actual + AccessDecisionManager for it to make the actual decision: public interface BankService { @@ -843,16 +830,13 @@ List<OpenIDAttribute> attributes = token.getAttributes();The annotations are a good choice if you need to define simple rules that go beyond checking the role names against the user's list of authorities. You can enable more than one type of annotation in the same application, but you should avoid mixing - annotations types in the same interface or class to avoid confusion. - - The annotated methods will only be secured for instances which are defined - as Spring beans (in the same application context in which method-security - is enabled). If you want to secure instances which are not created by Spring - (using the new operator, for example) then you need to use - AspectJ. + annotations types in the same interface or class to avoid confusion. + The annotated methods will only be secured for instances which are defined as + Spring beans (in the same application context in which method-security is + enabled). If you want to secure instances which are not created by Spring (using + the new operator, for example) then you need to use AspectJ. - - +
Adding Security Pointcuts using <literal>protect-pointcut</literal> The use of protect-pointcut is particularly powerful, as @@ -866,8 +850,8 @@ List<OpenIDAttribute> attributes = token.getAttributes();The This will protect all methods on beans declared in the application context whose classes are in the com.mycompany package and whose class names end in "Service". Only users with the - ROLE_USER role will be able to invoke these methods. As - with URL matching, the most specific matches must come first in the list of + ROLE_USER role will be able to invoke these methods. As with + URL matching, the most specific matches must come first in the list of pointcuts, as the first matching expression will be used.
@@ -879,24 +863,24 @@ List<OpenIDAttribute> attributes = token.getAttributes();The later, as this section is only really relevant for people who need to do some customization in order to use more than simple role-based security. When you use a namespace configuration, a default instance of - AccessDecisionManager is automatically registered for - you and will be used for making access decisions for method invocations and web URL - access, based on the access attributes you specify in your - intercept-url and protect-pointcut - declarations (and in annotations if you are using annotation secured methods). + AccessDecisionManager is automatically registered for you + and will be used for making access decisions for method invocations and web URL access, + based on the access attributes you specify in your intercept-url and + protect-pointcut declarations (and in annotations if you are using + annotation secured methods). The default strategy is to use an AffirmativeBased AccessDecisionManager with a - RoleVoter and an AuthenticatedVoter. - You can find out more about these in the chapter on authorization. + RoleVoter and an AuthenticatedVoter. You + can find out more about these in the chapter on authorization.
Customizing the AccessDecisionManager If you need to use a more complicated access control strategy then it is easy to set an alternative for both method and web security. For method security, you do this by setting the - access-decision-manager-ref attribute on - global-method-security to the Id of the appropriate - AccessDecisionManager bean in the application + access-decision-manager-ref attribute on + global-method-security to the Id of the appropriate + AccessDecisionManager bean in the application context: ... @@ -913,7 +897,7 @@ List<OpenIDAttribute> attributes = token.getAttributes();The
The Authentication Manager and the Namespace The main interface which provides authentication services in Spring Security is the - AuthenticationManager. This is usually an instance of + AuthenticationManager. This is usually an instance of Spring Security's ProviderManager class, which you may already be familiar with if you've used the framework before. If not, it will be covered later, in the technical overview chapter. The @@ -921,12 +905,12 @@ List<OpenIDAttribute> attributes = token.getAttributes();The namespace element. You can't use a custom AuthenticationManager if you are using either HTTP or method security through the namespace, but this should not be a problem as you have full control over the - AuthenticationProviders that are used. + AuthenticationProviders that are used. You may want to register additional AuthenticationProvider beans with the ProviderManager and you can do this using the - <authentication-provider> element with the - ref attribute, where the value of the attribute is the name of - the provider bean you want to add. For example: <authentication-provider> element with the + ref attribute, where the value of the attribute is the name of the + provider bean you want to add. For example: