appendix-namespace.xml 50 KB

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