appendix-namespace.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <appendix version="5.0" xml:id="appendix-namespace" xmlns="http://docbook.org/ns/docbook"
  3. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
  4. <info>
  5. <title>The Security Namespace</title>
  6. </info>
  7. <para> This appendix provides a reference to the elements available in the security namespace and
  8. information on the underlying beans they create (a knowledge of the individual classes and how
  9. they work together is assumed - you can find more information in the project Javadoc and
  10. elsewhere in this document). If you haven't used the namespace before, please read the <link
  11. xlink:href="#ns-config">introductory chapter</link> on namespace configuration, as this is
  12. intended as a supplement to the information there. Using a good quality XML editor while editing
  13. a configuration based on the schema is recommended as this will provide contextual information
  14. on which elements and attributes are available as well as comments explaining their purpose. The
  15. namespace is written in <link xlink:href="http://www.relaxng.org/">RELAX NG</link> Compact
  16. format and later converted into an XSD schema. If you are familiar with this format, you may
  17. wish to examine the <link
  18. xlink:href="https://src.springsource.org/svn/spring-security/trunk/config/src/main/resources/org/springframework/security/config/spring-security-3.0.rnc"
  19. >schema file</link> directly.</para>
  20. <section xml:id="nsa-http">
  21. <title>Web Application Security - the <literal>&lt;http&gt;</literal> Element</title>
  22. <para> The <literal>&lt;http&gt;</literal> element encapsulates the security configuration for
  23. the web layer of your application. It creates a <classname>FilterChainProxy</classname> bean
  24. named "springSecurityFilterChain" which maintains the stack of security filters which make up
  25. the web security configuration <footnote>
  26. <para>See the <link xlink:href="#ns-web-xml"> introductory chapter</link> for how to set up
  27. the mapping from your <literal>web.xml</literal></para>
  28. </footnote>. Some core filters are always created and others will be added to the stack
  29. depending on the attributes child elements which are present. The positions of the standard
  30. filters are fixed (see <link xlink:href="#filter-stack">the filter order table</link> in the
  31. namespace introduction), removing a common source of errors with previous versions of the
  32. framework when users had to configure the filter chain explicitly in
  33. the<classname>FilterChainProxy</classname> bean. You can, of course, still do this if you
  34. need full control of the configuration. </para>
  35. <para> All filters which require a reference to the
  36. <interfacename>AuthenticationManager</interfacename> will be automatically injected with the
  37. internal instance created by the namespace configuration (see the <link
  38. xlink:href="#ns-auth-manager"> introductory chapter</link> for more on the
  39. <interfacename>AuthenticationManager</interfacename>). </para>
  40. <para> The <literal>&lt;http&gt;</literal> namespace block always creates an
  41. <classname>HttpSessionContextIntegrationFilter</classname>, an
  42. <classname>ExceptionTranslationFilter</classname> and a
  43. <classname>FilterSecurityInterceptor</classname>. These are fixed and cannot be replaced
  44. with alternatives. </para>
  45. <section xml:id="nsa-http-attributes">
  46. <title><literal>&lt;http&gt;</literal> Attributes</title>
  47. <para> The attributes on the <literal>&lt;http&gt;</literal> element control some of the
  48. properties on the core filters. </para>
  49. <section xml:id="nsa-servlet-api-provision">
  50. <title><literal>servlet-api-provision</literal></title>
  51. <para> Provides versions of <literal>HttpServletRequest</literal> security methods such as
  52. <literal>isUserInRole()</literal> and <literal>getPrincipal()</literal> which are
  53. implemented by adding a <classname>SecurityContextHolderAwareRequestFilter</classname>
  54. bean to the stack. Defaults to "true". </para>
  55. </section>
  56. <section xml:id="nsa-path-type">
  57. <title><literal>path-type</literal></title>
  58. <para> Controls whether URL patterns are interpreted as ant paths (the default) or regular
  59. expressions. In practice this sets a particular <interfacename>UrlMatcher</interfacename>
  60. instance on the <classname>FilterChainProxy</classname>. </para>
  61. </section>
  62. <section xml:id="nsa-lowercase-comparisons">
  63. <title><literal>lowercase-comparisons</literal></title>
  64. <para> Whether test URLs should be converted to lower case prior to comparing with defined
  65. path patterns. If unspecified, defaults to "true" </para>
  66. </section>
  67. <section xml:id="nsa-realm">
  68. <title><literal>realm</literal></title>
  69. <para> Sets the realm name used for basic authentication (if enabled). Corresponds to the
  70. <literal>realmName</literal> proerty on
  71. <classname>BasicAuthenticationEntryPoint</classname>. </para>
  72. </section>
  73. <section xml:id="nsa-entry-point-ref">
  74. <title><literal>entry-point-ref</literal></title>
  75. <para> Normally the <interfacename>AuthenticationEntryPoint</interfacename> used will be set
  76. depending on which authentication mechanisms have been configured. This attribute allows
  77. this behaviour to be overridden by defining a customized
  78. <interfacename>AuthenticationEntryPoint</interfacename> bean which will start the
  79. authentication process. </para>
  80. </section>
  81. <section xml:id="nsa-access-decision-manager-ref">
  82. <title><literal>access-decision-manager-ref</literal></title>
  83. <para> Optional attribute specifying the ID of the
  84. <interfacename>AccessDecisionManager</interfacename> implementation which should be used
  85. for authorizing HTTP requests. By default an <classname>AffirmativeBased</classname>
  86. implementation is used for with a <classname>RoleVoter</classname> and an
  87. <classname>AuthenticatedVoter</classname>. </para>
  88. </section>
  89. <section xml:id="nsa-access-denied-page">
  90. <title><literal>access-denied-page</literal></title>
  91. <para> Deprecated in favour of the <literal>access-denied-handler</literal> child element.
  92. </para>
  93. </section>
  94. <section xml:id="nsa-once-per-request">
  95. <title><literal>once-per-request</literal></title>
  96. <para> Corresponds to the <literal>observeOncePerRequest</literal> property of
  97. <classname>FilterSecurityInterceptor</classname>. Defaults to "true". </para>
  98. </section>
  99. <section xml:id="create-session">
  100. <title><literal>create-session</literal></title>
  101. <para> Controls the eagerness with which an HTTP session is created. If not set, defaults to
  102. "ifRequired". Other options are "always" and "never". The setting of this attribute affect
  103. the <literal>allowSessionCreation</literal> and
  104. <literal>forceEagerSessionCreation</literal> properties of
  105. <classname>HttpSessionContextIntegrationFilter</classname>.
  106. <literal>allowSessionCreation</literal> will always be true unless this attribute is set
  107. to "never". <literal>forceEagerSessionCreation</literal> is "false" unless it is set to
  108. "always". So the default configuration allows session creation but does not force it. The
  109. exception is if concurrent session control is enabled, when
  110. <literal>forceEagerSessionCreation</literal> will be set to true, regardless of what the
  111. setting is here. Using "never" would then cause an exception during the initialization of
  112. <classname>HttpSessionContextIntegrationFilter</classname>. </para>
  113. </section>
  114. </section>
  115. <section xml:id="nsa-access-denied-handler">
  116. <title><literal>&lt;access-denied-handler></literal></title>
  117. <para> This element allows you to set the <literal>errorPage</literal> property for the
  118. default <interfacename>AccessDeniedHandler</interfacename> used by the
  119. <classname>ExceptionTranslationFilter</classname>, (using the
  120. <literal>error-page</literal> attribute, or to supply your own implementation using the
  121. <literal>ref</literal> attribute. This is discussed in more detail in the section on <link
  122. xlink:href="#access-denied-handler">the
  123. <classname>ExceptionTranslationFilter</classname></link>.</para>
  124. </section>
  125. <section>
  126. <title>The <literal>&lt;intercept-url&gt;</literal> Element</title>
  127. <para> This element is used to define the set of URL patterns that the application is
  128. interested in and to configure how they should be handled. It is used to construct the
  129. <interfacename>FilterInvocationDefinitionSource</interfacename> used by the
  130. <classname>FilterSecurityInterceptor</classname> and to exclude particular patterns from
  131. the filter chain entirely (by setting the attribute <literal>filters="none"</literal>). It
  132. is also responsible for configuring a <classname>ChannelAuthenticationFilter</classname> if
  133. particular URLs need to be accessed by HTTPS, for example. When matching the specified
  134. patterns against an incoming request, the matching is done in the order in which the
  135. elements are declared. So the most specific matches patterns should come first and the most
  136. general should come last.</para>
  137. <section xml:id="nsa-pattern">
  138. <title><literal>pattern</literal></title>
  139. <para> The pattern which defines the URL path. The content will depend on the
  140. <literal>path-type</literal> attribute from the containing http element, so will default
  141. to ant path syntax. </para>
  142. </section>
  143. <section xml:id="nsa-method">
  144. <title><literal>method</literal></title>
  145. <para> The HTTP Method which will be used in combination with the pattern to match an
  146. incoming request. If omitted, any method will match. If an identical pattern is specified
  147. with and without a method, the method-specific match will take precedence.</para>
  148. </section>
  149. <section xml:id="nsa-access">
  150. <title><literal>access</literal></title>
  151. <para> Lists the access attributes which will be stored in the
  152. <interfacename>FilterInvocationDefinitionSource</interfacename> for the defined URL
  153. pattern/method combination. This should be a comma-separated list of the security
  154. configuration attributes (such as role names). </para>
  155. </section>
  156. <section xml:id="nsa-requires-channel">
  157. <title><literal>requires-channel</literal></title>
  158. <para> Can be <quote>http</quote> or <quote>https</quote> depending on whether a particular
  159. URL pattern should be accessed over HTTP or HTTPS respectively. Alternatively the value
  160. <quote>any</quote> can be used when there is no preference. If this attribute is present
  161. on any <literal>&lt;intercept-url&gt;</literal> element, then a
  162. <classname>ChannelAuthenticationFilter</classname> will be added to the filter stack and
  163. its additional dependencies added to the application
  164. context.<!--See the chapter on <link
  165. xlink:href="#channel-security-config">channel security</link> for an example
  166. configuration using traditional beans. --></para>
  167. <para> If a <literal>&lt;port-mappings&gt;</literal> configuration is added, this will be
  168. used to by the <classname>SecureChannelProcessor</classname> and
  169. <classname>InsecureChannelProcessor</classname> beans to determine the ports used for
  170. redirecting to HTTP/HTTPS. </para>
  171. </section>
  172. <section>
  173. <title><literal>filters</literal></title>
  174. <para>Can only take the value <quote>none</quote>. This will cause any matching request to
  175. bypass the Spring Security filter chain entirely. None of the rest of the
  176. <literal>&lt;http></literal> configuration will have any effect on the request and there
  177. will be no security context available for its duration. Access to secured methods during
  178. the request will fail.</para>
  179. </section>
  180. </section>
  181. <section>
  182. <title>The <literal>&lt;port-mappings&gt;</literal> Element</title>
  183. <para> By default, an instance of <classname>PortMapperImpl</classname> will be added to the
  184. configuration for use in redirecting to secure and insecure URLs. This element can
  185. optionally be used to override the default mappings which that class defines. Each child
  186. <literal>&lt;port-mapping&gt;</literal> element defines a pair of HTTP:HTTPS ports. The
  187. default mappings are 80:443 and 8080:8443. An example of overriding these can be found in
  188. the <link xlink:href="#ns-requires-channel">namespace introduction</link>. </para>
  189. </section>
  190. <section xml:id="nsa-form-login">
  191. <title>The <literal>&lt;form-login&gt;</literal> Element</title>
  192. <para> Used to add an <classname>UsernamePasswordAuthenticationFilter</classname> to the
  193. filter stack and an <classname>LoginUrlAuthenticationEntryPoint</classname> to the
  194. application context to provide authentication on demand. This will always take precedence
  195. over other namespace-created entry points. If no attributes are supplied, a login page will
  196. be generated automatically at the URL "/spring-security-login" <footnote>
  197. <para>This feature is really just provided for convenience and is not intended for
  198. production (where a view technology will have been chosen and can be used to render a
  199. customized login page). The class
  200. <classname>DefaultLoginPageGeneratingFilter</classname> is responsible for rendering
  201. the login page and will provide login forms for both normal form login and/or OpenID if
  202. required.</para>
  203. </footnote> The behaviour can be customized using the following attributes. </para>
  204. <section>
  205. <title><literal>login-page</literal></title>
  206. <para> The URL that should be used to render the login page. Maps to the
  207. <literal>loginFormUrl</literal> property of the
  208. <classname>LoginUrlAuthenticationEntryPoint</classname>. Defaults to
  209. "/spring-security-login". </para>
  210. </section>
  211. <section>
  212. <title><literal>login-processing-url</literal></title>
  213. <para> Maps to the <literal>filterProcessesUrl</literal> property of
  214. <classname>UsernamePasswordAuthenticationFilter</classname>. The default value is
  215. "/j_spring_security_check". </para>
  216. </section>
  217. <section>
  218. <title><literal>default-target-url</literal></title>
  219. <para>Maps to the <literal>defaultTargetUrl</literal> property of
  220. <classname>UsernamePasswordAuthenticationFilter</classname>. If not set, the default
  221. value is "/" (the application root). A user will be taken to this URL after logging in,
  222. provided they were not asked to login while attempting to access a secured resource, when
  223. they will be taken to the originally requested URL. </para>
  224. </section>
  225. <section>
  226. <title><literal>always-use-default-target</literal></title>
  227. <para> If set to "true", the user will always start at the value given by
  228. <literal>default-target-url</literal>, regardless of how they arrived at the login page.
  229. Maps to the <literal>alwaysUseDefaultTargetUrl</literal> property of
  230. <classname>UsernamePasswordAuthenticationFilter</classname>. Default value is "false".
  231. </para>
  232. </section>
  233. <section>
  234. <title><literal>authentication-failure-url</literal></title>
  235. <para> Maps to the <literal>authenticationFailureUrl</literal> property of
  236. <classname>UsernamePasswordAuthenticationFilter</classname>. Defines the URL the browser
  237. will be redirected to on login failure. Defaults to "/spring_security_login?login_error",
  238. which will be automatically handled by the automatic login page generator, re-rendering
  239. the login page with an error message. </para>
  240. </section>
  241. <section>
  242. <title><literal>authentication-success-handler-ref</literal></title>
  243. <para>This can be used as an alternative to <literal>default-target-url</literal> and
  244. <literal>always-use-default-target</literal>, giving you full control over the
  245. navigation flow after a successful authentication. The value should be he name of an
  246. <interfacename>AuthenticationSuccessHandler</interfacename> bean in the application
  247. context. </para>
  248. </section>
  249. <section>
  250. <title><literal>authentication-failure-handler-ref</literal></title>
  251. <para>Can be used as an alternative to <literal>authentication-failure-url</literal>, giving
  252. you full control over the navigation flow after an authentication failure. The value
  253. should be he name of an <interfacename>AuthenticationFailureHandler</interfacename> bean
  254. in the application context. </para>
  255. </section>
  256. </section>
  257. <section xml:id="nsa-http-basic">
  258. <title>The <literal>&lt;http-basic&gt;</literal> Element</title>
  259. <para> Adds a <classname>BasicAuthenticationFilter</classname> and
  260. <classname>BasicAuthenticationEntryPoint</classname> to the configuration. The latter will
  261. only be used as the configuration entry point if form-based login is not enabled. </para>
  262. </section>
  263. <section xml:id="nsa-remember-me">
  264. <title>The <literal>&lt;remember-me&gt;</literal> Element</title>
  265. <para> Adds the <classname>RememberMeAuthenticationFilter</classname> to the stack. This in
  266. turn will be configured with either a <classname>TokenBasedRememberMeServices</classname>, a
  267. <classname>PersistentTokenBasedRememberMeServices</classname> or a user-specified bean
  268. implementing <interfacename>RememberMeServices</interfacename> depending on the attribute
  269. settings. </para>
  270. <section>
  271. <title><literal>data-source-ref</literal></title>
  272. <para> If this is set, <classname>PersistentTokenBasedRememberMeServices</classname> will be
  273. used and configured with a <classname>JdbcTokenRepositoryImpl</classname> instance.
  274. </para>
  275. </section>
  276. <section>
  277. <title><literal>token-repository-ref</literal></title>
  278. <para> Configures a <classname>PersistentTokenBasedRememberMeServices</classname> but allows
  279. the use of a custom <interfacename>PersistentTokenRepository</interfacename> bean. </para>
  280. </section>
  281. <section>
  282. <title><literal>services-ref</literal></title>
  283. <para> Allows complete control of the <interfacename>RememberMeServices</interfacename>
  284. implementation that will be used by the filter. The value should be the Id of a bean in
  285. the application context which implements this interface. </para>
  286. </section>
  287. <section>
  288. <title><literal>token-repository-ref</literal></title>
  289. <para> Configures a <classname>PersistentTokenBasedRememberMeServices</classname> but allows
  290. the use of a custom <interfacename>PersistentTokenRepository</interfacename> bean. </para>
  291. </section>
  292. <section>
  293. <title>The <literal>key</literal> Attribute</title>
  294. <para>Maps to the "key" property of <classname>AbstractRememberMeServices</classname>.
  295. Should be set to a unique value to ensure that remember-me cookies are only valid within
  296. the one application <footnote>
  297. <para>This doesn't affect the use of
  298. <classname>PersistentTokenBasedRememberMeServices</classname>, where the tokens are
  299. stored on the server side.</para>
  300. </footnote>. </para>
  301. </section>
  302. <section>
  303. <title><literal>token-validity-seconds</literal></title>
  304. <para> Maps to the <literal>tokenValiditySeconds</literal> property of
  305. <classname>AbstractRememberMeServices</classname>. Specifies the period in seconds for
  306. which the remember-me cookie should be valid. By default it will be valid for 14 days.
  307. </para>
  308. </section>
  309. <section>
  310. <title><literal>user-service-ref</literal></title>
  311. <para> The remember-me services implementations require access to a
  312. <interfacename>UserDetailsService</interfacename>, so there has to be one defined in the
  313. application context. If there is only one, it will be selected and used automatically by
  314. the namespace configuration. If there are multiple instances, you can specify a bean Id
  315. explicitly using this attribute. </para>
  316. </section>
  317. </section>
  318. <section xml:id="nsa-session-mgmt">
  319. <title>The <literal>&lt;session-management&gt;</literal> Element</title>
  320. <para>Session-management related functionality is implemented by the addition of a
  321. <classname>SessionManagementFilter</classname> to the filter stack.</para>
  322. <section xml:id="session-fixation-protection">
  323. <title><literal>session-fixation-protection</literal></title>
  324. <para> Indicates whether an existing session should be invalidated when a user authenticates
  325. and a new session started. If set to "none" no change will be made. "newSession" will
  326. create a new empty session. "migrateSession" will create a new session and copy the
  327. session attributes to the new session. Defaults to "migrateSession".</para>
  328. <para> If session fixation protection is enabled, the
  329. <classname>SessionManagementFilter</classname> is inected with a appropriately
  330. configured <classname>DefaultSessionAuthenticationStrategy</classname>. See the Javadoc
  331. for this class for more details. </para>
  332. </section>
  333. </section>
  334. <section xml:id="nsa-concurrent-session-control">
  335. <title>The <literal>&lt;concurrency-control&gt;</literal> Element</title>
  336. <para> Adds support for concurrent session control, allowing limits to be placed on the number
  337. of active sessions a user can have. A <classname>ConcurrentSessionFilter</classname> will be
  338. created, and a <classname>ConcurrentSessionControlStrategy</classname> will be used with the
  339. <classname>SessionManagementFilter</classname>. If a <literal>form-login</literal> element
  340. has been declared, the strategy object will also be injected into the created authentication
  341. filter. An instance of <interfacename>SessionRegistry</interfacename> (a
  342. <classname>SessionRegistryImpl</classname> instance unless the user wishes to use a custom
  343. bean) will be created for use by the strategy.</para>
  344. <section>
  345. <title>The <literal>max-sessions</literal> attribute</title>
  346. <para>Maps to the <literal>maximumSessions</literal> property of
  347. <classname>ConcurrentSessionControlStrategy</classname>.</para>
  348. </section>
  349. <section>
  350. <title>The <literal>expired-url</literal> attribute</title>
  351. <para> The URL a user will be redirected to if they attempt to use a session which has been
  352. "expired" by the concurrent session controller because the user has exceeded the number of
  353. allowed sessions and has logged in again elsewhere. Should be set unless
  354. <literal>exception-if-maximum-exceeded</literal> is set. If no value is supplied, an
  355. expiry message will just be written directly back to the response. </para>
  356. </section>
  357. <section>
  358. <title>The <literal>error-if-maximum-exceeded</literal> attribute</title>
  359. <para>If set to "true" a <exceptionname>SessionAuthenticationException</exceptionname> will
  360. be raised when a user attempts to exceed the maximum allowed number of sessions. The
  361. default behaviour is to expire the original session. </para>
  362. </section>
  363. <section>
  364. <title>The <literal>session-registry-alias</literal> and
  365. <literal>session-registry-ref</literal> attributes</title>
  366. <para> The user can supply their own <interfacename>SessionRegistry</interfacename>
  367. implementation using the <literal>session-registry-ref</literal> attribute. The other
  368. concurrent session control beans will be wired up to use it. </para>
  369. <para> It can also be useful to have a reference to the internal session registry for use in
  370. your own beans or an admin interface. You can expose the interal bean using the
  371. <literal>session-registry-alias</literal> attribute, giving it a name that you can use
  372. elsewhere in your configuration. </para>
  373. </section>
  374. </section>
  375. <section xml:id="nsa-anonymous">
  376. <title>The <literal>&lt;anonymous&gt;</literal> Element</title>
  377. <para> Adds an <classname>AnonymousAuthenticationFilter</classname> to the stack and an
  378. <classname>AnonymousAuthenticationProvider</classname>. Required if you are using the
  379. <literal>IS_AUTHENTICATED_ANONYMOUSLY</literal> attribute. </para>
  380. </section>
  381. <section xml:id="nsa-x509">
  382. <title>The <literal>&lt;x509&gt;</literal> Element</title>
  383. <para> Adds support for X.509 authentication. An
  384. <classname>X509AuthenticationFilter</classname> will be added to the stack and an
  385. <classname>Http403ForbiddenEntryPoint</classname> bean will be created. The latter will
  386. only be used if no other authentication mechanisms are in use (it's only functionality is to
  387. return an HTTP 403 error code). A
  388. <classname>PreAuthenticatedAuthenticationProvider</classname> will also be created which
  389. delegates the loading of user authorities to a
  390. <interfacename>UserDetailsService</interfacename>. </para>
  391. <section>
  392. <title>The <literal>subject-principal-regex</literal> attribute</title>
  393. <para> Defines a regular expression which will be used to extract the username from the
  394. certificate (for use with the <interfacename>UserDetailsService</interfacename>). </para>
  395. </section>
  396. <section>
  397. <title>The <literal>user-service-ref</literal> attribute</title>
  398. <para> Allows a specific <interfacename>UserDetailsService</interfacename> to be used with
  399. X.509 in the case where multiple instances are configured. If not set, an attempt will be
  400. made to locate a suitable instance automatically and use that. </para>
  401. </section>
  402. </section>
  403. <section xml:id="nsa-openid-login">
  404. <title>The <literal>&lt;openid-login&gt;</literal> Element</title>
  405. <para> Similar to <literal>&lt;form-login&gt;</literal> and has the same attributes. The
  406. default value for <literal>login-processing-url</literal> is
  407. "/j_spring_openid_security_check". An <classname>OpenIDAuthenticationFilter</classname> and
  408. <classname>OpenIDAuthenticationProvider</classname> will be registered. The latter
  409. requires a reference to a <interfacename>UserDetailsService</interfacename>. Again, this can
  410. be specified by Id, using the <literal>user-service-ref</literal> attribute, or will be
  411. located automatically in the application context. </para>
  412. </section>
  413. <section xml:id="nsa-logout">
  414. <title>The <literal>&lt;logout&gt;</literal> Element</title>
  415. <para> Adds a <classname>LogoutFilter</classname> to the filter stack. This is configured with
  416. a <classname>SecurityContextLogoutHandler</classname>. </para>
  417. <section>
  418. <title>The <literal>logout-url</literal> attribute</title>
  419. <para> The URL which will cause a logout (i.e. which will be processed by the filter).
  420. Defaults to "/j_spring_security_logout". </para>
  421. </section>
  422. <section>
  423. <title>The <literal>logout-success-url</literal> attribute</title>
  424. <para> The destination URL which the user will be taken to after logging out. Defaults to
  425. "/". </para>
  426. </section>
  427. <section>
  428. <title>The <literal>invalidate-session</literal> attribute</title>
  429. <para> Maps to the <literal>invalidateHttpSession</literal> of the
  430. <classname>SecurityContextLogoutHandler</classname>. Defaults to "true", so the session
  431. will be invalidated on logout. </para>
  432. </section>
  433. </section>
  434. <section>
  435. <title>The <literal>&lt;custom-filter></literal> Element</title>
  436. <para>This element is used to add a filter to the filter chain. It doesn't create any
  437. additional beans but is used to select a bean of type
  438. <interfacename>javax.servlet.Filter</interfacename> which is already defined in the
  439. appllication context and add that at a particular position in the filter chain maintained by
  440. Spring Security. Full details can be found in the namespace chapter.</para>
  441. </section>
  442. </section>
  443. <section>
  444. <title>Authentication Services</title>
  445. <para> Before Spring Security 3.0, an <interfacename>AuthenticationManager</interfacename> was
  446. automatically registered internally. Now you must register one explicitly using the
  447. <literal>&lt;authentication-manager&gt;</literal> element. This creates an instance of
  448. Spring Security's <classname>ProviderManager</classname> class, which needs to be configured
  449. with a list of one or more <interfacename>AuthenticationProvider</interfacename> instances.
  450. These can either be created using syntax elements provided by the namespace, or they can be
  451. standard bean definitions, marked for addition to the list using the
  452. <literal>authentication-provider</literal> element. </para>
  453. <section>
  454. <title>The <literal>&lt;authentication-manager&gt;</literal> Element</title>
  455. <para> Every Spring Security application which uses the namespace must have include this
  456. element somewhere. It is resposible for registering the
  457. <interfacename>AuthenticationManager</interfacename> which provides authentication
  458. services to the application. It also allows you to define an alias name for the internal
  459. instance for use in your own configuration. Its use is described in the <link
  460. xlink:href="#ns-auth-manager">namespace introduction</link>. All elements which create
  461. <interfacename>AuthenticationProvider</interfacename> instances should be children of this
  462. element.</para>
  463. <section>
  464. <title>The <literal>&lt;authentication-provider&gt;</literal> Element</title>
  465. <para> This element is basically a shorthand syntax for configuring a <link
  466. xlink:href="#core-services-dao-provider"
  467. ><classname>DaoAuthenticationProvider</classname></link>.
  468. <classname>DaoAuthenticationProvider</classname> loads user information from a
  469. <interfacename>UserDetailsService</interfacename> and compares the username/password
  470. combination with the values supplied at login. The
  471. <interfacename>UserDetailsService</interfacename> instance can be defined either by
  472. using an available namespace element (<literal>jdbc-user-service</literal> or by using the
  473. <literal>user-service-ref</literal> attribute to point to a bean defined elsewhere in
  474. the application context). You can find examples of these variations in the <link
  475. xlink:href="#ns-auth-providers">namespace introduction</link>. </para>
  476. <section>
  477. <title>The <literal>&lt;password-encoder&gt;</literal> Element</title>
  478. <para>Authentication providers can optionally be configured to use a password encoder as
  479. described in the <link xlink:href="#ns-password-encoder">namespace introduction</link>.
  480. This will result in the bean being injected with the appropriate
  481. <interfacename>PasswordEncoder</interfacename> instance, potentially with an
  482. accompanying <interfacename>SaltSource</interfacename> bean to provide salt values for
  483. hashing. </para>
  484. </section>
  485. </section>
  486. <section>
  487. <title>Using <literal>&lt;authentication-provider&gt;</literal> to refer to an
  488. <interfacename>AuthenticationProvider</interfacename> Bean</title>
  489. <para> If you have written your own <interfacename>AuthenticationProvider</interfacename>
  490. implementation (or want to configure one of Spring Security's own implementations as a
  491. traditional bean for some reason, then you can use the following syntax to add it to the
  492. internal <classname>ProviderManager</classname>'s list: <programlisting><![CDATA[
  493. <security:authentication-manager>
  494. <security:authentication-provider ref="myAuthenticationProvider" />
  495. </security:authentication-manager>
  496. <bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider"/>
  497. ]]></programlisting></para>
  498. </section>
  499. </section>
  500. </section>
  501. <section>
  502. <title>Method Security</title>
  503. <section>
  504. <title>The <literal>&lt;global-method-security&gt;</literal> Element</title>
  505. <para> This element is the primary means of adding support for securing methods on Spring
  506. Security beans. Methods can be secured by the use of annotations (defined at the interface
  507. or class level) or by defining a set of pointcuts as child elements, using AspectJ syntax. </para>
  508. <para> Method security uses the same <interfacename>AccessDecisionManager</interfacename>
  509. configuration as web security, but this can be overridden as explained above <xref
  510. xlink:href="#nsa-access-decision-manager-ref"/>, using the same attribute. </para>
  511. <section>
  512. <title>The <literal>secured-annotations</literal> and <literal>jsr250-annotations</literal>
  513. Attributes</title>
  514. <para> Setting these to "true" will enable support for Spring Security's own
  515. <literal>@Secured</literal> annotations and JSR-250 annotations, respectively. They are
  516. both disabled by default. Use of JSR-250 annotations also adds a
  517. <classname>Jsr250Voter</classname> to the
  518. <interfacename>AccessDecisionManager</interfacename>, so you need to make sure you do
  519. this if you are using a custom implementation and want to use these annotations. </para>
  520. </section>
  521. <section>
  522. <title>Securing Methods using <literal>&lt;protect-pointcut&gt;</literal></title>
  523. <para> Rather than defining security attributes on an individual method or class basis using
  524. the <literal>@Secured</literal> annotation, you can define cross-cutting security
  525. constraints across whole sets of methods and interfaces in your service layer using the
  526. <literal>&lt;protect-pointcut&gt;</literal> element. This has two attributes: <itemizedlist>
  527. <listitem>
  528. <para><literal>expression</literal> - the pointcut expression</para>
  529. </listitem>
  530. <listitem>
  531. <para><literal>access</literal> - the security attributes which apply</para>
  532. </listitem>
  533. </itemizedlist> You can find an example in the <link xlink:href="#ns-protect-pointcut"
  534. >namespace introduction</link>. </para>
  535. </section>
  536. <section xml:id="nsa-custom-after-invocation">
  537. <title>The <literal>&lt;after-invocation-provider&gt;</literal> Element</title>
  538. <para> This element can be used to decorate an
  539. <interfacename>AfterInvocationProvider</interfacename> for use by the security
  540. interceptor maintained by the <literal>&lt;global-method-security&gt;</literal> namespace.
  541. You can define zero or more of these within the <literal>global-method-security</literal>
  542. element, each with a <literal>ref</literal> attribute pointing to an
  543. <interfacename>AfterInvocationProvider</interfacename> bean instance within your
  544. application context. </para>
  545. </section>
  546. </section>
  547. <section>
  548. <title>LDAP Namespace Options</title>
  549. <para> LDAP is covered in some details in <link xlink:href="#ldap">its own chapter</link>. We
  550. will expand on that here with some explanation of how the namespace options map to Spring
  551. beans. The LDAP implementation uses Spring LDAP extensively, so some familiarity with that
  552. project's API may be useful. </para>
  553. <section>
  554. <title>Defining the LDAP Server using the <literal>&lt;ldap-server&gt;</literal>
  555. Element</title>
  556. <para> This element sets up a Spring LDAP <interfacename>ContextSource</interfacename> for
  557. use by the other LDAP beans, defining the location of the LDAP server and other
  558. information (such as a username and password, if it doesn't allow anonymous access) for
  559. connecting to it. It can also be used to create an embedded server for testing. Details of
  560. the syntax for both options are covered in the <link xlink:href="#ldap-server">LDAP
  561. chapter</link>. The actual <interfacename>ContextSource</interfacename> implementation
  562. is <classname>DefaultSpringSecurityContextSource</classname> which extends Spring LDAP's
  563. <classname>LdapContextSource</classname> class. The <literal>manager-dn</literal> and
  564. <literal>manager-password</literal> attributes map to the latter's
  565. <literal>userDn</literal> and <literal>password</literal> properties respectively. </para>
  566. <para> If you only have one server defined in your application context, the other LDAP
  567. namespace-defined beans will use it automatically. Otherwise, you can give the element an
  568. "id" attribute and refer to it from other namespace beans using the
  569. <literal>server-ref</literal> attribute. This is actually the bean Id of the
  570. <literal>ContextSource</literal> instance, if you want to use it in other traditional
  571. Spring beans. </para>
  572. </section>
  573. <section>
  574. <title>The <literal>&lt;ldap-provider&gt;</literal> Element</title>
  575. <para> This element is shorthand for the creation of an
  576. <classname>LdapAuthenticationProvider</classname> instance. By default this will be
  577. configured with a <classname>BindAuthenticator</classname> instance and a
  578. <classname>DefaultAuthoritiesPopulator</classname>. As with all namespace authentication
  579. providers, it must be included as a child of the
  580. <literal>authentication-provider</literal> element.</para>
  581. <section>
  582. <title>The <literal>user-dn-pattern</literal> Attribute</title>
  583. <para> If your users are at a fixed location in the directory (i.e. you can work out the
  584. DN directly from the username without doing a directory search), you can use this
  585. attribute to map directly to the DN. It maps directly to the
  586. <literal>userDnPatterns</literal> property of
  587. <classname>AbstractLdapAuthenticator</classname>. </para>
  588. </section>
  589. <section>
  590. <title>The <literal>user-search-base</literal> and <literal>user-search-filter</literal>
  591. Attributes</title>
  592. <para> If you need to perform a search to locate the user in the directory, then you can
  593. set these attributes to control the search. The <classname>BindAuthenticator</classname>
  594. will be configured with a <classname>FilterBasedLdapUserSearch</classname> and the
  595. attribute values map directly to the first two arguments of that bean's constructor. If
  596. these attributes aren't set and no <literal>user-dn-pattern</literal> has been supplied
  597. as an alternative, then the default search values of
  598. <literal>user-search-filter="(uid={0})"</literal> and
  599. <literal>user-search-base=""</literal> will be used. </para>
  600. </section>
  601. <section>
  602. <title><literal>group-search-filter</literal>, <literal>group-search-base</literal>,
  603. <literal>group-role-attribute</literal> and <literal>role-prefix</literal>
  604. Attributes</title>
  605. <para> The value of <literal>group-search-base</literal> is mapped to the
  606. <literal>groupSearchBase</literal> constructor argument of
  607. <classname>DefaultAuthoritiesPopulator</classname> and defaults to "ou=groups". The
  608. default filter value is "(uniqueMember={0})", which assumes that the entry is of type
  609. "groupOfUniqueNames". <literal>group-role-attribute</literal> maps to the
  610. <literal>groupRoleAttribute</literal> attribute and defaults to "cn". Similarly
  611. <literal>role-prefix</literal> maps to <literal>rolePrefix</literal> and defaults to
  612. "ROLE_". </para>
  613. </section>
  614. <section>
  615. <title>The <literal>&lt;password-compare&gt;</literal> Element</title>
  616. <para> This is used as child element to <literal>&lt;ldap-provider&gt;</literal> and
  617. switches the authentication strategy from <classname>BindAuthenticator</classname> to
  618. <classname>PasswordComparisonAuthenticator</classname>. This can optionally be
  619. supplied with a <literal>hash</literal> attribute or with a child
  620. <literal>&lt;password-encoder&gt;</literal> element to hash the password before
  621. submitting it to the directory for comparison. </para>
  622. </section>
  623. </section>
  624. <section>
  625. <title>The <literal>&lt;ldap-user-service&gt;</literal> Element</title>
  626. <para> This element configures an LDAP <interfacename>UserDetailsService</interfacename>.
  627. The class used is <classname>LdapUserDetailsService</classname> which is a combination of
  628. a <classname>FilterBasedLdapUserSearch</classname> and a
  629. <classname>DefaultAuthoritiesPopulator</classname>. The attributes it supports have the
  630. same usage as in <literal>&lt;ldap-provider&gt;</literal>. </para>
  631. </section>
  632. </section>
  633. </section>
  634. </appendix>