Skip to content

Commit ba8f344

Browse files
committed
Add AuthenticationServiceException Reactive Preparation Steps
Issue gh-9429 Issue gh-12132
1 parent 3192618 commit ba8f344

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

docs/modules/ROOT/pages/migration.adoc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,3 +1950,87 @@ to:
19501950
@EnableReactiveMethodSecurity(useAuthorizationManager = false)
19511951
----
19521952
====
1953+
1954+
=== Propagate ``AuthenticationServiceException``s
1955+
1956+
{security-api-url}org/springframework/security/web/server/Webauthentication/AuthenticationWebFilter.html[`AuthenticationFilter`] propagates {security-api-url}org/springframework/security/authentication/AuthenticationServiceException.html[``AuthenticationServiceException``]s to the {security-api-url}org/springframework/security/web/server/ServerAuthenticationEntryPoint.html[`ServerAuthenticationEntryPoint`].
1957+
Because ``AuthenticationServiceException``s represent a server-side error instead of a client-side error, in 6.0, this changes to propagate them to the container.
1958+
1959+
==== Configure `ServerAuthenticationFailureHandler` to rethrow ``AuthenticationServiceException``s
1960+
1961+
To prepare for the 6.0 default, `httpBasic` and `oauth2ResourceServer` should be configured to rethrow ``AuthenticationServiceException``s.
1962+
1963+
For each, construct the appropriate authentication entry point for `httpBasic` and for `oauth2ResourceServer`:
1964+
1965+
====
1966+
.Java
1967+
[source,java,role="primary"]
1968+
----
1969+
ServerAuthenticationEntryPoint bearerEntryPoint = new BearerTokenServerAuthenticationEntryPoint();
1970+
ServerAuthenticationEntryPoint basicEntryPoint = new HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED);
1971+
----
1972+
1973+
.Kotlin
1974+
[source,kotlin,role="secondary"]
1975+
----
1976+
val bearerEntryPoint: ServerAuthenticationEntryPoint = BearerTokenServerAuthenticationEntryPoint()
1977+
val basicEntryPoint: ServerAuthenticationEntryPoint = HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED)
1978+
----
1979+
====
1980+
1981+
[NOTE]
1982+
====
1983+
If you use a custom `AuthenticationEntryPoint` for either or both mechanisms, use that one instead for the remaining steps.
1984+
====
1985+
1986+
Then, construct and configure a `ServerAuthenticationEntryPointFailureHandler` for each one:
1987+
1988+
====
1989+
.Java
1990+
[source,java,role="primary"]
1991+
----
1992+
AuthenticationFailureHandler bearerFailureHandler = new ServerAuthenticationEntryPointFailureHandler(bearerEntryPoint);
1993+
bearerFailureHandler.setRethrowAuthenticationServiceException(true);
1994+
AuthenticationFailureHandler basicFailureHandler = new ServerAuthenticationEntryPointFailureHandler(basicEntryPoint);
1995+
basicFailureHandler.setRethrowAuthenticationServiceException(true)
1996+
----
1997+
1998+
.Kotlin
1999+
[source,kotlin,role="secondary"]
2000+
----
2001+
val bearerFailureHandler: AuthenticationFailureHandler = ServerAuthenticationEntryPointFailureHandler(bearerEntryPoint)
2002+
bearerFailureHandler.setRethrowAuthenticationServiceException(true)
2003+
val basicFailureHandler: AuthenticationFailureHandler = ServerAuthenticationEntryPointFailureHandler(basicEntryPoint)
2004+
basicFailureHandler.setRethrowAuthenticationServiceException(true)
2005+
----
2006+
====
2007+
2008+
Finally, wire each authentication failure handler into the DSL, like so:
2009+
2010+
====
2011+
.Java
2012+
[source,java,role="primary"]
2013+
----
2014+
http
2015+
.httpBasic((basic) -> basic.authenticationFailureHandler(basicFailureHandler))
2016+
.oauth2ResourceServer((oauth2) -> oauth2.authenticationFailureHandler(bearerFailureHandler))
2017+
----
2018+
2019+
.Kotlin
2020+
[source,kotlin,role="secondary"]
2021+
----
2022+
http {
2023+
httpBasic {
2024+
authenticationFailureHandler = basicFailureHandler
2025+
}
2026+
oauth2ResourceServer {
2027+
authenticationFailureHandler = bearerFailureHandler
2028+
}
2029+
}
2030+
----
2031+
====
2032+
2033+
[[reactive-authenticationfailurehandler-opt-out]]
2034+
==== Opt-out Steps
2035+
2036+
To opt-out of the 6.0 defaults and instead continue to pass `AuthenticationServiceException` on to ``ServerAuthenticationEntryPoint``s, you can follow the same steps as above, except set `rethrowAuthenticationServiceException` to false.

0 commit comments

Comments
 (0)