appendix-namespace.xml 54 KB

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