From 39f4fcd5f2cb0a7fdd0fef0debe13fdc8bc3b828 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 31 Oct 2022 16:33:25 -0600 Subject: [PATCH] Add AuthenticationEntryPointFailureHandler Preparation Steps Issue gh-9429 --- docs/modules/ROOT/pages/migration.adoc | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/docs/modules/ROOT/pages/migration.adoc b/docs/modules/ROOT/pages/migration.adoc index a6b81413d9..ff2e513910 100644 --- a/docs/modules/ROOT/pages/migration.adoc +++ b/docs/modules/ROOT/pages/migration.adoc @@ -1623,6 +1623,86 @@ Second, if you still need your custom `access-decision-manager-ref` or have some ---- ==== +=== Propagate ``AuthenticationServiceException``s + +{security-api-url}org/springframework/security/web/authentication/AuthenticationFilter.html[`AuthenticationFilter`] propagates {security-api-url}org/springframework/security/authentication/AuthenticationServiceException.html[``AuthenticationServiceException``]s to the {security-api-url}org/springframework/security/authentication/AuthenticationEntryPoint.html[`AuthenticationEntryPoint`]. +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. + +==== Configure `AuthenticationFailureHandler` to rethrow ``AuthenticationServiceException``s + +To prepare for the 6.0 default, wire `AuthenticationFilter` instances with a `AuthenticationFailureHandler` that rethrows ``AuthenticationServiceException``s, like so: + +==== +.Java +[source,java,role="primary"] +---- +AuthenticationFilter authenticationFilter = new AuthenticationFilter(...); +AuthenticationEntryPointFailureHandler handler = new AuthenticationEntryPointFailureHandler(...); +handler.setRethrowAuthenticationServiceException(true); +authenticationFilter.setAuthenticationFailureHandler(handler); +---- + +.Kotlin +[source,kotlin,role="secondary"] +---- +val authenticationFilter: AuthenticationFilter = new AuthenticationFilter(...) +val handler: AuthenticationEntryPointFailureHandler = new AuthenticationEntryPointFailureHandler(...) +handler.setRethrowAuthenticationServiceException(true) +authenticationFilter.setAuthenticationFailureHandler(handler) +---- + +.Xml +[source,xml,role="secondary"] +---- + + + + + + + + +---- +==== + +[[servlet-authenticationfailurehandler-opt-out]] +==== Opt-out Steps + +If rethrowing ``AuthenticationServiceException``s gives you trouble, you can set the value to false instead of taking the 6.0 default, like so: + +==== +.Java +[source,java,role="primary"] +---- +AuthenticationFilter authenticationFilter = new AuthenticationFilter(...); +AuthenticationEntryPointFailureHandler handler = new AuthenticationEntryPointFailureHandler(...); +handler.setRethrowAuthenticationServiceException(false); +authenticationFilter.setAuthenticationFailureHandler(handler); +---- + +.Kotlin +[source,kotlin,role="secondary"] +---- +val authenticationFilter: AuthenticationFilter = new AuthenticationFilter(...) +val handler: AuthenticationEntryPointFailureHandler = new AuthenticationEntryPointFailureHandler(...) +handler.setRethrowAuthenticationServiceException(false) +authenticationFilter.setAuthenticationFailureHandler(handler) +---- + +.Xml +[source,xml,role="secondary"] +---- + + + + + + + + +---- +==== + == Reactive === Use `AuthorizationManager` for Method Security