(window.webpackJsonp=window.webpackJsonp||[]).push([[264],{690:function(e,t,a){"use strict";a.r(t);var n=a(56),o=Object(n.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"security-namespace-configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#security-namespace-configuration"}},[e._v("#")]),e._v(" Security Namespace Configuration")]),e._v(" "),a("h2",{attrs:{id:"introduction"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#introduction"}},[e._v("#")]),e._v(" Introduction")]),e._v(" "),a("p",[e._v("Namespace configuration has been available since version 2.0 of the Spring Framework.\nIt allows you to supplement the traditional Spring beans application context syntax with elements from additional XML schema.\nYou can find more information in the Spring "),a("a",{attrs:{href:"https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Reference Documentation"),a("OutboundLink")],1),e._v(".\nA 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.\nA simple element may conceal the fact that multiple beans and processing steps are being added to the application context.\nFor example, adding the following element from the security namespace to an application context will start up an embedded LDAP server for testing use within the application:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("\n")])])]),a("p",[e._v("This is much simpler than wiring up the equivalent Apache Directory Server beans.\nThe most common alternative configuration requirements are supported by attributes on the "),a("code",[e._v("ldap-server")]),e._v(" element and the user is isolated from worrying about which beans they need to create and what the bean property names are."),a("sup",{staticClass:"footnote"},[e._v("["),a("a",{staticClass:"footnote",attrs:{id:"_footnoteref_1",href:"#_footnotedef_1",title:"View footnote."}},[e._v("1")]),e._v("]")]),e._v(".].\nUse of a good XML editor while editing the application context file should provide information on the attributes and elements that are available.\nWe would recommend that you try out the "),a("a",{attrs:{href:"https://spring.io/tools",target:"_blank",rel:"noopener noreferrer"}},[e._v("Eclipse IDE with Spring Tools"),a("OutboundLink")],1),e._v(" as it has special features for working with standard Spring namespaces.")]),e._v(" "),a("p",[e._v("To start using the security namespace in your application context, you need to have the "),a("code",[e._v("spring-security-config")]),e._v(" jar on your classpath.\nThen all you need to do is add the schema declaration to your application context file:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\t...\n\n')])])]),a("p",[e._v('In many of the examples you will see (and in the sample applications), we will often use "security" as the default namespace rather than "beans", which means we can omit the prefix on all the security namespace elements, making the content easier to read.\nYou may also want to do this if you have your application context divided up into separate files and have most of your security configuration in one of them.\nYour security application context file would then start like this')]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\t...\n\n')])])]),a("p",[e._v("We’ll assume this syntax is being used from now on in this chapter.")]),e._v(" "),a("h3",{attrs:{id:"design-of-the-namespace"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#design-of-the-namespace"}},[e._v("#")]),e._v(" Design of the Namespace")]),e._v(" "),a("p",[e._v("The namespace is designed to capture the most common uses of the framework and provide a simplified and concise syntax for enabling them within an application.\nThe design is based around the large-scale dependencies within the framework, and can be divided up into the following areas:")]),e._v(" "),a("ul",[a("li",[a("p",[a("em",[e._v("Web/HTTP Security")]),e._v(" - the most complex part.\nSets 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.")])]),e._v(" "),a("li",[a("p",[a("em",[e._v("Business Object (Method) Security")]),e._v(" - options for securing the service layer.")])]),e._v(" "),a("li",[a("p",[a("em",[e._v("AuthenticationManager")]),e._v(" - handles authentication requests from other parts of the framework.")])]),e._v(" "),a("li",[a("p",[a("em",[e._v("AccessDecisionManager")]),e._v(" - provides access decisions for web and method security.\nA default one will be registered, but you can also choose to use a custom one, declared using normal Spring bean syntax.")])]),e._v(" "),a("li",[a("p",[a("em",[e._v("AuthenticationProvider")]),e._v("s - mechanisms against which the authentication manager authenticates users.\nThe namespace provides supports for several standard options and also a means of adding custom beans declared using a traditional syntax.")])]),e._v(" "),a("li",[a("p",[a("em",[e._v("UserDetailsService")]),e._v(" - closely related to authentication providers, but often also required by other beans.")])])]),e._v(" "),a("p",[e._v("We’ll see how to configure these in the following sections.")]),e._v(" "),a("h2",{attrs:{id:"getting-started-with-security-namespace-configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#getting-started-with-security-namespace-configuration"}},[e._v("#")]),e._v(" Getting Started with Security Namespace Configuration")]),e._v(" "),a("p",[e._v("In this section, we’ll look at how you can build up a namespace configuration to use some of the main features of the framework.\nLet’s assume you initially want to get up and running as quickly as possible and add authentication support and access control to an existing web application, with a few test logins.\nThen we’ll look at how to change over to authenticating against a database or other security repository.\nIn later sections we’ll introduce more advanced namespace configuration options.")]),e._v(" "),a("h3",{attrs:{id:"web-xml-configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#web-xml-configuration"}},[e._v("#")]),e._v(" web.xml Configuration")]),e._v(" "),a("p",[e._v("The first thing you need to do is add the following filter declaration to your "),a("code",[e._v("web.xml")]),e._v(" file:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("\nspringSecurityFilterChain\norg.springframework.web.filter.DelegatingFilterProxy\n\n\n\nspringSecurityFilterChain\n/*\n\n")])])]),a("p",[e._v("This provides a hook into the Spring Security web infrastructure."),a("code",[e._v("DelegatingFilterProxy")]),e._v(' is a Spring Framework class which delegates to a filter implementation which is defined as a Spring bean in your application context.\nIn this case, the bean is named "springSecurityFilterChain", which is an internal infrastructure bean created by the namespace to handle web security.\nNote that you should not use this bean name yourself.\nOnce you’ve added this to your '),a("code",[e._v("web.xml")]),e._v(", you’re ready to start editing your application context file.\nWeb security services are configured using the "),a("code",[e._v("")]),e._v(" element.")]),e._v(" "),a("h3",{attrs:{id:"a-minimal-http-configuration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#a-minimal-http-configuration"}},[e._v("#")]),e._v(" A Minimal Configuration")]),e._v(" "),a("p",[e._v("All you need to enable web security to begin with is")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n\n\n\n')])])]),a("p",[e._v("Which says that we want all URLs within our application to be secured, requiring the role "),a("code",[e._v("ROLE_USER")]),e._v(" to access them, we want to log in to the application using a form with username and password, and that we want a logout URL registered which will allow us to log out of the application."),a("code",[e._v("")]),e._v(" element is the parent for all web-related namespace functionality.\nThe "),a("code",[e._v("")]),e._v(" element defines a "),a("code",[e._v("pattern")]),e._v(" which is matched against the URLs of incoming requests using an ant path style syntax "),a("sup",{staticClass:"footnote"},[e._v("["),a("a",{staticClass:"footnote",attrs:{id:"_footnoteref_2",href:"#_footnotedef_2",title:"View footnote."}},[e._v("2")]),e._v("]")]),e._v(" for more details on how matches are actually performed.].\nYou can also use regular-expression matching as an alternative (see the namespace appendix for more details).\nThe "),a("code",[e._v("access")]),e._v(' attribute defines the access requirements for requests matching the given pattern.\nWith 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.\nThe prefix "ROLE_" is a marker which indicates that a simple comparison with the user’s authorities should be made.\nIn other words, a normal role-based check should be used.\nAccess-control in Spring Security is not limited to the use of simple roles (hence the use of the prefix to differentiate between different types of security attributes).\nWe’ll see later how the interpretation can vary '),a("sup",{staticClass:"footnote"},[e._v("["),a("a",{staticClass:"footnote",attrs:{id:"_footnoteref_3",href:"#_footnotedef_3",title:"View footnote."}},[e._v("3")]),e._v("]")]),e._v(".\nIn Spring Security 3.0, the attribute can also be populated with an "),a("RouterLink",{attrs:{to:"/en/authorization/expression-based.html#el-access"}},[e._v("EL expression")]),e._v(".")],1),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("You can use multiple "),a("code",[e._v("")]),e._v(" 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."),a("br"),e._v("So you must put the most specific matches at the top."),a("br"),e._v("You can also add a "),a("code",[e._v("method")]),e._v(" attribute to limit the match to a particular HTTP method ("),a("code",[e._v("GET")]),e._v(", "),a("code",[e._v("POST")]),e._v(", "),a("code",[e._v("PUT")]),e._v(" etc.).")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("To add some users, you can define a set of test data directly in the namespace:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n\t\n\t\x3c!-- Password is prefixed with {noop} to indicate to DelegatingPasswordEncoder that\n\tNoOpPasswordEncoder should be used. This is not safe for production, but makes reading\n\tin samples easier. Normally passwords should be hashed using BCrypt --\x3e\n\t\n\t\n\t\n\n\n')])])]),a("p",[e._v("This is an example of a secure way of storing the same passwords.\nThe password is prefixed with "),a("code",[e._v("{bcrypt}")]),e._v(" to instruct "),a("code",[e._v("DelegatingPasswordEncoder")]),e._v(", which supports any configured "),a("code",[e._v("PasswordEncoder")]),e._v(" for matching, that the passwords are hashed using BCrypt:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n\t\n\t\n\t\n\t\n\t\n\t\n\n\n')])])]),a("p",[e._v("If you are familiar with pre-namespace versions of the framework, you can probably already guess roughly what’s going on here.\nThe "),a("code",[e._v("")]),e._v(" element is responsible for creating a "),a("code",[e._v("FilterChainProxy")]),e._v(" and the filter beans which it uses.\nCommon problems like incorrect filter ordering are no longer an issue as the filter positions are predefined.")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("")]),e._v(" element creates a "),a("code",[e._v("DaoAuthenticationProvider")]),e._v(" bean and the "),a("code",[e._v("")]),e._v(" element creates an "),a("code",[e._v("InMemoryDaoImpl")]),e._v(".\nAll "),a("code",[e._v("authentication-provider")]),e._v(" elements must be children of the "),a("code",[e._v("")]),e._v(" element, which creates a "),a("code",[e._v("ProviderManager")]),e._v(" and registers the authentication providers with it.\nYou can find more detailed information on the beans that are created in the "),a("RouterLink",{attrs:{to:"/en/appendix/namespace/index.html#appendix-namespace"}},[e._v("namespace appendix")]),e._v(".\nIt’s worth cross-checking this if you want to start understanding what the important classes in the framework are and how they are used, particularly if you want to customise things later.")],1),e._v(" "),a("p",[e._v("The configuration above defines two users, their passwords and their roles within the application (which will be used for access control).\nIt is also possible to load user information from a standard properties file using the "),a("code",[e._v("properties")]),e._v(" attribute on "),a("code",[e._v("user-service")]),e._v(".\nSee the section on "),a("RouterLink",{attrs:{to:"/en/authentication/passwords/in-memory.html#servlet-authentication-inmemory"}},[e._v("in-memory authentication")]),e._v(" for more details on the file format.\nUsing the "),a("code",[e._v("")]),e._v(" element means that the user information will be used by the authentication manager to process authentication requests.\nYou can have multiple "),a("code",[e._v("")]),e._v(" elements to define different authentication sources and each will be consulted in turn.")],1),e._v(" "),a("p",[e._v('At this point you should be able to start up your application and you will be required to log in to proceed.\nTry it out, or try experimenting with the "tutorial" sample application that comes with the project.')]),e._v(" "),a("h4",{attrs:{id:"setting-a-default-post-login-destination"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#setting-a-default-post-login-destination"}},[e._v("#")]),e._v(" Setting a Default Post-Login Destination")]),e._v(" "),a("p",[e._v("If a form login isn’t prompted by an attempt to access a protected resource, the "),a("code",[e._v("default-target-url")]),e._v(' option comes into play.\nThis is the URL the user will be taken to after successfully logging in, and defaults to "/".\nYou can also configure things so that the user '),a("em",[e._v("always")]),e._v(' ends up at this page (regardless of whether the login was "on-demand" or they explicitly chose to log in) by setting the '),a("code",[e._v("always-use-default-target")]),e._v(' attribute to "true".\nThis is useful if your application always requires that the user starts at a "home" page, for example:')]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("\n\n\n\n\n")])])]),a("p",[e._v("For even more control over the destination, you can use the "),a("code",[e._v("authentication-success-handler-ref")]),e._v(" attribute as an alternative to "),a("code",[e._v("default-target-url")]),e._v(".\nThe referenced bean should be an instance of "),a("code",[e._v("AuthenticationSuccessHandler")]),e._v(".")]),e._v(" "),a("h2",{attrs:{id:"advanced-web-features"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#advanced-web-features"}},[e._v("#")]),e._v(" Advanced Web Features")]),e._v(" "),a("h3",{attrs:{id:"adding-in-your-own-filters"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#adding-in-your-own-filters"}},[e._v("#")]),e._v(" Adding in Your Own Filters")]),e._v(" "),a("p",[e._v("If you’ve used Spring Security before, you’ll know that the framework maintains a chain of filters in order to apply its services.\nYou may want to add your own filters to the stack at particular locations or use a Spring Security filter for which there isn’t currently a namespace configuration option (CAS, for example).\nOr you might want to use a customized version of a standard namespace filter, such as the "),a("code",[e._v("UsernamePasswordAuthenticationFilter")]),e._v(" which is created by the "),a("code",[e._v("")]),e._v(" element, taking advantage of some of the extra configuration options which are available by using the bean explicitly.\nHow can you do this with namespace configuration, since the filter chain is not directly exposed?")]),e._v(" "),a("p",[e._v("The order of the filters is always strictly enforced when using the namespace.\nWhen 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.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("In previous versions, the sorting took place after the filter instances had been created, during post-processing of the application context."),a("br"),e._v("In version 3.0+ the sorting is now done at the bean metadata level, before the classes have been instantiated."),a("br"),e._v("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 "),a("code",[e._v("")]),e._v(" element, so the syntax has changed slightly in 3.0.")])])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("The filters, aliases and namespace elements/attributes which create the filters are shown in "),a("a",{attrs:{href:"#filter-stack"}},[e._v("Standard Filter Aliases and Ordering")]),e._v(".\nThe filters are listed in the order in which they occur in the filter chain.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Alias")]),e._v(" "),a("th",[e._v("Filter Class")]),e._v(" "),a("th",[e._v("Namespace Element or Attribute")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[e._v("CHANNEL_FILTER")]),e._v(" "),a("td",[a("code",[e._v("ChannelProcessingFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/[[email protected]](/cdn-cgi/l/email-protection)")])])]),e._v(" "),a("tr",[a("td",[e._v("SECURITY_CONTEXT_FILTER")]),e._v(" "),a("td",[a("code",[e._v("SecurityContextPersistenceFilter")])]),e._v(" "),a("td",[a("code",[e._v("http")])])]),e._v(" "),a("tr",[a("td",[e._v("CONCURRENT_SESSION_FILTER")]),e._v(" "),a("td",[a("code",[e._v("ConcurrentSessionFilter")])]),e._v(" "),a("td",[a("code",[e._v("session-management/concurrency-control")])])]),e._v(" "),a("tr",[a("td",[e._v("HEADERS_FILTER")]),e._v(" "),a("td",[a("code",[e._v("HeaderWriterFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/headers")])])]),e._v(" "),a("tr",[a("td",[e._v("CSRF_FILTER")]),e._v(" "),a("td",[a("code",[e._v("CsrfFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/csrf")])])]),e._v(" "),a("tr",[a("td",[e._v("LOGOUT_FILTER")]),e._v(" "),a("td",[a("code",[e._v("LogoutFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/logout")])])]),e._v(" "),a("tr",[a("td",[e._v("X509_FILTER")]),e._v(" "),a("td",[a("code",[e._v("X509AuthenticationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/x509")])])]),e._v(" "),a("tr",[a("td",[e._v("PRE_AUTH_FILTER")]),e._v(" "),a("td",[a("code",[e._v("AbstractPreAuthenticatedProcessingFilter")]),e._v(" Subclasses")]),e._v(" "),a("td",[e._v("N/A")])]),e._v(" "),a("tr",[a("td",[e._v("CAS_FILTER")]),e._v(" "),a("td",[a("code",[e._v("CasAuthenticationFilter")])]),e._v(" "),a("td",[e._v("N/A")])]),e._v(" "),a("tr",[a("td",[e._v("FORM_LOGIN_FILTER")]),e._v(" "),a("td",[a("code",[e._v("UsernamePasswordAuthenticationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/form-login")])])]),e._v(" "),a("tr",[a("td",[e._v("BASIC_AUTH_FILTER")]),e._v(" "),a("td",[a("code",[e._v("BasicAuthenticationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/http-basic")])])]),e._v(" "),a("tr",[a("td",[e._v("SERVLET_API_SUPPORT_FILTER")]),e._v(" "),a("td",[a("code",[e._v("SecurityContextHolderAwareRequestFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/@servlet-api-provision")])])]),e._v(" "),a("tr",[a("td",[e._v("JAAS_API_SUPPORT_FILTER")]),e._v(" "),a("td",[a("code",[e._v("JaasApiIntegrationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/@jaas-api-provision")])])]),e._v(" "),a("tr",[a("td",[e._v("REMEMBER_ME_FILTER")]),e._v(" "),a("td",[a("code",[e._v("RememberMeAuthenticationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/remember-me")])])]),e._v(" "),a("tr",[a("td",[e._v("ANONYMOUS_FILTER")]),e._v(" "),a("td",[a("code",[e._v("AnonymousAuthenticationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http/anonymous")])])]),e._v(" "),a("tr",[a("td",[e._v("SESSION_MANAGEMENT_FILTER")]),e._v(" "),a("td",[a("code",[e._v("SessionManagementFilter")])]),e._v(" "),a("td",[a("code",[e._v("session-management")])])]),e._v(" "),a("tr",[a("td",[e._v("EXCEPTION_TRANSLATION_FILTER")]),e._v(" "),a("td",[a("code",[e._v("ExceptionTranslationFilter")])]),e._v(" "),a("td",[a("code",[e._v("http")])])]),e._v(" "),a("tr",[a("td",[e._v("FILTER_SECURITY_INTERCEPTOR")]),e._v(" "),a("td",[a("code",[e._v("FilterSecurityInterceptor")])]),e._v(" "),a("td",[a("code",[e._v("http")])])]),e._v(" "),a("tr",[a("td",[e._v("SWITCH_USER_FILTER")]),e._v(" "),a("td",[a("code",[e._v("SwitchUserFilter")])]),e._v(" "),a("td",[e._v("N/A")])])])]),e._v(" "),a("p",[e._v("You can add your own filter to the stack, using the "),a("code",[e._v("custom-filter")]),e._v(" element and one of these names to specify the position your filter should appear at:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n\n\n\n\n')])])]),a("p",[e._v("You can also use the "),a("code",[e._v("after")]),e._v(" or "),a("code",[e._v("before")]),e._v(' attributes if you want your filter to be inserted before or after another filter in the stack.\nThe names "FIRST" and "LAST" can be used with the '),a("code",[e._v("position")]),e._v(" attribute to indicate that you want your filter to appear before or after the entire stack, respectively.")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th"),e._v(" "),a("th",[e._v("Avoiding filter position conflicts"),a("br"),a("br"),e._v("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."),a("br"),e._v("Remove any elements which create filters whose functionality you want to replace."),a("br"),a("br"),e._v("Note that you can’t replace filters which are created by the use of the "),a("code",[e._v("")]),e._v(" element itself - "),a("code",[e._v("SecurityContextPersistenceFilter")]),e._v(", "),a("code",[e._v("ExceptionTranslationFilter")]),e._v(" or "),a("code",[e._v("FilterSecurityInterceptor")]),e._v("."),a("br"),e._v("Some other filters are added by default, but you can disable them."),a("br"),e._v("An "),a("code",[e._v("AnonymousAuthenticationFilter")]),e._v(" is added by default and unless you have "),a("RouterLink",{attrs:{to:"/en/authentication/session-management.html#ns-session-fixation"}},[e._v("session-fixation protection")]),e._v(" disabled, a "),a("code",[e._v("SessionManagementFilter")]),e._v(" will also be added to the filter chain.")],1)])]),e._v(" "),a("tbody")]),e._v(" "),a("p",[e._v("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 unauthenticated user to access to a secured resource), you will need to add a custom entry point bean too.")]),e._v(" "),a("h2",{attrs:{id:"method-security"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#method-security"}},[e._v("#")]),e._v(" Method Security")]),e._v(" "),a("p",[e._v("From version 2.0 onwards Spring Security has improved support substantially for adding security to your service layer methods.\nIt provides support for JSR-250 annotation security as well as the framework’s original "),a("code",[e._v("@Secured")]),e._v(" annotation.\nFrom 3.0 you can also make use of new "),a("RouterLink",{attrs:{to:"/en/authorization/expression-based.html#el-access"}},[e._v("expression-based annotations")]),e._v(".\nYou can apply security to a single bean, using the "),a("code",[e._v("intercept-methods")]),e._v(" element to decorate the bean declaration, or you can secure multiple beans across the entire service layer using the AspectJ style pointcuts.")],1),e._v(" "),a("h2",{attrs:{id:"the-default-accessdecisionmanager"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#the-default-accessdecisionmanager"}},[e._v("#")]),e._v(" The Default AccessDecisionManager")]),e._v(" "),a("p",[e._v("This section assumes you have some knowledge of the underlying architecture for access-control within Spring Security.\nIf you don’t you can skip it and come back to it 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.")]),e._v(" "),a("p",[e._v("When you use a namespace configuration, a default instance of "),a("code",[e._v("AccessDecisionManager")]),e._v(" 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 "),a("code",[e._v("intercept-url")]),e._v(" and "),a("code",[e._v("protect-pointcut")]),e._v(" declarations (and in annotations if you are using annotation secured methods).")]),e._v(" "),a("p",[e._v("The default strategy is to use an "),a("code",[e._v("AffirmativeBased")]),e._v(" "),a("code",[e._v("AccessDecisionManager")]),e._v(" with a "),a("code",[e._v("RoleVoter")]),e._v(" and an "),a("code",[e._v("AuthenticatedVoter")]),e._v(".\nYou can find out more about these in the chapter on "),a("RouterLink",{attrs:{to:"/en/authorization/architecture.html#authz-arch"}},[e._v("authorization")]),e._v(".")],1),e._v(" "),a("h3",{attrs:{id:"customizing-the-accessdecisionmanager"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#customizing-the-accessdecisionmanager"}},[e._v("#")]),e._v(" Customizing the AccessDecisionManager")]),e._v(" "),a("p",[e._v("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.")]),e._v(" "),a("p",[e._v("For method security, you do this by setting the "),a("code",[e._v("access-decision-manager-ref")]),e._v(" attribute on "),a("code",[e._v("global-method-security")]),e._v(" to the "),a("code",[e._v("id")]),e._v(" of the appropriate "),a("code",[e._v("AccessDecisionManager")]),e._v(" bean in the application context:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n...\n\n')])])]),a("p",[e._v("The syntax for web security is the same, but on the "),a("code",[e._v("http")]),e._v(" element:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n...\n\n')])])]),a("hr"),e._v(" "),a("p",[a("a",{attrs:{href:"#_footnoteref_1"}},[e._v("1")]),e._v(". You can find out more about the use of the "),a("code",[e._v("ldap-server")]),e._v(" element in the chapter on xref:servlet/authentication/unpwd/ldap.adoc#servlet-authentication-ldap[LDAP Authentication")]),e._v(" "),a("p",[a("a",{attrs:{href:"#_footnoteref_2"}},[e._v("2")]),e._v(". See the section on xref:servlet/exploits/firewall.adoc#servlet-httpfirewall["),a("code",[e._v("HttpFirewall")])]),e._v(" "),a("p",[a("a",{attrs:{href:"#_footnoteref_3"}},[e._v("3")]),e._v(". The interpretation of the comma-separated values in the "),a("code",[e._v("access")]),e._v(" attribute depends on the implementation of the "),a("a",{attrs:{href:"#ns-access-manager"}},[e._v("AccessDecisionManager")]),e._v(" which is used.")]),e._v(" "),a("p",[a("RouterLink",{attrs:{to:"/en/spring-security/kotlin.html"}},[e._v("Kotlin Configuration")]),a("RouterLink",{attrs:{to:"/en/test/index.html"}},[e._v("Testing")])],1)])}),[],!1,null,null,null);t.default=o.exports}}]);