Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit 337b46b

Browse files
committed
Additional Filter Order Documentation
Issue gh-144
1 parent 43c2737 commit 337b46b

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

docs/src/docs/asciidoc/index.adoc

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,55 @@ OAuth2 resources are protected by a filter chain with order
238238

239239
By default the filters in `AuthorizationServerConfigurerAdapter` come first, followed by those in `ResourceServerConfigurerAdapter`, followed by those in `WebSecurityConfigurerAdapter`.
240240

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:
242242

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
245245

246+
The first, changing the filter chain order, can be done by moving `WebSecurityConfigurerAdapter` in front of `ResourceServerConfigurerAdapter` like so:
246247

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 {
279+
@Override
280+
protected void configure(HttpSecurity http) {
281+
http
282+
.requestMatchers()
283+
.antMatchers("/rest/**")
284+
.authorizeRequests()
285+
.anyRequest().authenticated();
286+
}
287+
}
288+
----
289+
====
247290

248291
[[boot-features-security-oauth2-token-type]]
249292
= Token Type in User Info

0 commit comments

Comments
 (0)