@ -17,8 +17,6 @@
package org.springframework.security.web.authentication.preauth ;
package org.springframework.security.web.authentication.preauth ;
import java.io.IOException ;
import java.io.IOException ;
import java.util.Set ;
import java.util.stream.Collectors ;
import jakarta.servlet.FilterChain ;
import jakarta.servlet.FilterChain ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.ServletException ;
@ -38,7 +36,6 @@ import org.springframework.security.authentication.event.InteractiveAuthenticati
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.AuthenticationException ;
import org.springframework.security.core.AuthenticationException ;
import org.springframework.security.core.BuildableAuthentication ;
import org.springframework.security.core.BuildableAuthentication ;
import org.springframework.security.core.GrantedAuthority ;
import org.springframework.security.core.context.SecurityContext ;
import org.springframework.security.core.context.SecurityContext ;
import org.springframework.security.core.context.SecurityContextHolder ;
import org.springframework.security.core.context.SecurityContextHolder ;
import org.springframework.security.core.context.SecurityContextHolderStrategy ;
import org.springframework.security.core.context.SecurityContextHolderStrategy ;
@ -211,20 +208,7 @@ public abstract class AbstractPreAuthenticatedProcessingFilter extends GenericFi
Authentication current = this . securityContextHolderStrategy . getContext ( ) . getAuthentication ( ) ;
Authentication current = this . securityContextHolderStrategy . getContext ( ) . getAuthentication ( ) ;
if ( current ! = null & & current . isAuthenticated ( ) ) {
if ( current ! = null & & current . isAuthenticated ( ) ) {
if ( authenticationResult instanceof BuildableAuthentication buildable ) {
if ( authenticationResult instanceof BuildableAuthentication buildable ) {
authenticationResult = buildable . toBuilder ( )
authenticationResult = buildable . toBuilder ( ) . authentication ( current ) . build ( ) ;
// @formatter:off
. authorities ( ( a ) - > {
Set < String > newAuthorities = a . stream ( )
. map ( GrantedAuthority : : getAuthority )
. collect ( Collectors . toUnmodifiableSet ( ) ) ;
for ( GrantedAuthority currentAuthority : current . getAuthorities ( ) ) {
if ( ! newAuthorities . contains ( currentAuthority . getAuthority ( ) ) ) {
a . add ( currentAuthority ) ;
}
}
} )
. build ( ) ;
// @formatter:on
}
}
}
}
successfulAuthentication ( request , response , authenticationResult ) ;
successfulAuthentication ( request , response , authenticationResult ) ;