You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 31, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/index.adoc
+46-3Lines changed: 46 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -238,12 +238,55 @@ OAuth2 resources are protected by a filter chain with order
238
238
239
239
By default the filters in `AuthorizationServerConfigurerAdapter` come first, followed by those in `ResourceServerConfigurerAdapter`, followed by those in `WebSecurityConfigurerAdapter`.
240
240
241
-
This means that all application endpoints will require bearer token authentication unless one of two things happens:
241
+
This means that *all application endpoints will require bearer token authentication* unless one of two things happens:
242
242
243
-
1. The filter order is changed or
244
-
2. The `ResourceServerConfigurerAdapter`'s set of authorized requests is narrowed
243
+
1. The filter chain order is changed or
244
+
2. The `ResourceServerConfigurerAdapter` set of authorized requests is narrowed
245
245
246
+
The first, changing the filter chain order, can be done by moving `WebSecurityConfigurerAdapter` in front of `ResourceServerConfigurerAdapter` like so:
246
247
248
+
====
249
+
[source,java]
250
+
----
251
+
@Order(2)
252
+
@EnableWebSecurity
253
+
public WebSecurityConfig extends WebSecurityConfigurerAdapter {
254
+
// ...
255
+
}
256
+
----
257
+
====
258
+
259
+
[NOTE]
260
+
Resource Server's default `@Order` value is 3 which is why the example sets Web's `@Order` to 2, so that it's evaluated earlier.
261
+
262
+
While this may work, it's a little odd since we may simply trade one problem:
263
+
264
+
> `ResourceServerConfigurerAdapter` is handling requests it shouldn't
265
+
266
+
For another:
267
+
268
+
> `WebSecurityConfigurerAdapter` is handling requests it shouldn't
269
+
270
+
The more robust solution, then, is to indicate to `ResourceServerConfigurerAdapter` which endpoints should be secured by bearer token authentication.
271
+
272
+
For example, the following configures Resource Server to secure the web application endpoints that begin with `/rest`:
273
+
274
+
====
275
+
[source,java]
276
+
----
277
+
@EnableResourceServer
278
+
public ResourceServerConfig extends ResourceServerConfigurerAdapter {
0 commit comments