appendix-namespace.xml 53 KB

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