|
133 | 133 | <section xml:id="ns-minimal">
|
134 | 134 | <title>A Minimal <literal><http></literal> Configuration</title>
|
135 | 135 | <para> All you need to enable web security to begin with is <programlisting language="xml"><![CDATA[
|
136 |
| - <http auto-config='true'> |
| 136 | + <http> |
137 | 137 | <intercept-url pattern="/**" access="ROLE_USER" />
|
| 138 | + <form-login /> |
| 139 | + <logout /> |
138 | 140 | </http>
|
139 | 141 | ]]>
|
140 | 142 | </programlisting> Which says that we want all URLs within our application to be secured,
|
141 |
| - requiring the role <literal>ROLE_USER</literal> to access them. The |
| 143 | + requiring the role <literal>ROLE_USER</literal> to access them, we want to log in to |
| 144 | + the application using a form with username and password, and that we want a logout URL |
| 145 | + registered which will allow us to log out of the application. |
142 | 146 | <literal><http></literal> element is the parent for all web-related namespace
|
143 | 147 | functionality. The <literal><intercept-url></literal> element defines a
|
144 | 148 | <literal>pattern</literal> which is matched against the URLs of incoming requests
|
|
216 | 220 | turn.</para>
|
217 | 221 | <para> At this point you should be able to start up your application and you will be
|
218 | 222 | required to log in to proceed. Try it out, or try experimenting with the
|
219 |
| - <quote>tutorial</quote> sample application that comes with the project. The above |
220 |
| - configuration actually adds quite a few services to the application because we have |
221 |
| - used the <literal>auto-config</literal> attribute. For example, form-based login |
222 |
| - processing is automatically enabled. </para> |
223 |
| - <section xml:id="ns-auto-config"> |
224 |
| - <title>What does <literal>auto-config</literal> Include?</title> |
225 |
| - <para> The <literal>auto-config</literal> attribute, as we have used it above, is |
226 |
| - just a shorthand syntax for: <programlisting language="xml"><![CDATA[ |
227 |
| - <http> |
228 |
| - <form-login /> |
229 |
| - <http-basic /> |
230 |
| - <logout /> |
231 |
| - </http> |
232 |
| - ]]></programlisting> These other elements are responsible for setting up form-login, basic |
233 |
| - authentication and logout handling services respectively <footnote> |
234 |
| - <para>In versions prior to 3.0, this list also included remember-me |
235 |
| - functionality. This could cause some confusing errors with some |
236 |
| - configurations and was removed in 3.0. In 3.0, the addition of an |
237 |
| - <classname>AnonymousAuthenticationFilter</classname> is part of the default |
238 |
| - <literal><http></literal> configuration, so the <literal><anonymous |
239 |
| - /></literal> element is added regardless of whether |
240 |
| - <literal>auto-config</literal> is enabled.</para> |
241 |
| - </footnote>. They each have attributes which can be used to alter their |
242 |
| - behaviour. In anything other than very basic scenarios, it is probably better to |
243 |
| - omit the <literal>auto-config</literal> attribute and configure what you require |
244 |
| - explicitly in the interest of clarity.</para> |
245 |
| - </section> |
| 223 | + <quote>tutorial</quote> sample application that comes with the project.</para> |
246 | 224 | </section>
|
247 | 225 | <section xml:id="ns-form-and-basic">
|
248 | 226 | <title>Form and Basic Login Options</title>
|
|
251 | 229 | explicitly set a URL for the login page, Spring Security generates one
|
252 | 230 | automatically, based on the features that are enabled and using standard values for
|
253 | 231 | the URL which processes the submitted login, the default target URL the user will be
|
254 |
| - sent to after loggin in and so on. However, the namespace offers plenty of support |
| 232 | + sent to after logging in and so on. However, the namespace offers plenty of support |
255 | 233 | to allow you to customize these options. For example, if you want to supply your own
|
256 | 234 | login page, you could use: <programlisting language="xml"><![CDATA[
|
257 |
| - <http auto-config='true'> |
| 235 | + <http> |
258 | 236 | <intercept-url pattern="/login.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
|
259 | 237 | <intercept-url pattern="/**" access="ROLE_USER" />
|
260 | 238 | <form-login login-page='/login.jsp'/>
|
261 | 239 | </http>
|
262 | 240 | ]]>
|
263 |
| - </programlisting> Note that you can still use <literal>auto-config</literal>. The |
264 |
| - <literal>form-login</literal> element just overrides the default settings. Also note |
| 241 | + </programlisting> Also note |
265 | 242 | that we've added an extra <literal>intercept-url</literal> element to say that any
|
266 | 243 | requests for the login page should be available to anonymous users <footnote>
|
267 | 244 | <para>See the chapter on <link xlink:href="#anonymous">anonymous
|
|
278 | 255 | <http pattern="/css/**" security="none"/>
|
279 | 256 | <http pattern="/login.jsp*" security="none"/>
|
280 | 257 |
|
281 |
| - <http auto-config='true'> |
| 258 | + <http> |
282 | 259 | <intercept-url pattern="/**" access="ROLE_USER" />
|
283 | 260 | <form-login login-page='/login.jsp'/>
|
284 | 261 | </http>
|
|
305 | 282 | still want the security filter chain to be applied.</para>
|
306 | 283 | <para>If you want to use basic authentication instead of form login, then change the
|
307 | 284 | configuration to <programlisting language="xml"><![CDATA[
|
308 |
| - <http auto-config='true'> |
| 285 | + <http> |
309 | 286 | <intercept-url pattern="/**" access="ROLE_USER" />
|
310 | 287 | <http-basic />
|
311 | 288 | </http>
|
@@ -777,8 +754,7 @@ List<OpenIDAttribute> attributes = token.getAttributes();</programlisting>The
|
777 | 754 | <title>Avoiding filter position conflicts</title>
|
778 | 755 | <para> If you are inserting a custom filter which may occupy the same position as
|
779 | 756 | one of the standard filters created by the namespace then it's important that
|
780 |
| - you don't include the namespace versions by mistake. Avoid using the |
781 |
| - <literal>auto-config</literal> attribute and remove any elements which create |
| 757 | + you don't include the namespace versions by mistake. Remove any elements which create |
782 | 758 | filters whose functionality you want to replace. </para>
|
783 | 759 | <para> Note that you can't replace filters which are created by the use of the
|
784 | 760 | <literal><http></literal> element itself -
|
|
0 commit comments