Move FACTOR_X509 into PreAuthenticatedAuthenticationProvider
Issue gh-17933
This commit is contained in:
+19
-1
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.security.web.authentication.preauth;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
@@ -28,6 +33,7 @@ import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsChecker;
|
||||
@@ -57,6 +63,8 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
|
||||
private UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker();
|
||||
|
||||
private Supplier<Collection<GrantedAuthority>> grantedAuthoritySupplier = List::of;
|
||||
|
||||
private boolean throwExceptionWhenTokenRejected;
|
||||
|
||||
private int order = -1; // default: same as non-ordered
|
||||
@@ -98,8 +106,10 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
UserDetails userDetails = this.preAuthenticatedUserDetailsService
|
||||
.loadUserDetails((PreAuthenticatedAuthenticationToken) authentication);
|
||||
this.userDetailsChecker.check(userDetails);
|
||||
Collection<GrantedAuthority> authorities = new LinkedHashSet<>(userDetails.getAuthorities());
|
||||
authorities.addAll(this.grantedAuthoritySupplier.get());
|
||||
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(userDetails,
|
||||
authentication.getCredentials(), userDetails.getAuthorities());
|
||||
authentication.getCredentials(), authorities);
|
||||
result.setDetails(authentication.getDetails());
|
||||
return result;
|
||||
}
|
||||
@@ -142,6 +152,14 @@ public class PreAuthenticatedAuthenticationProvider implements AuthenticationPro
|
||||
this.userDetailsChecker = userDetailsChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets authorities that this provider should grant once authentication completes
|
||||
* @param grantedAuthoritySupplier the supplier that grants authorities
|
||||
*/
|
||||
public void setGrantedAuthoritySupplier(Supplier<Collection<GrantedAuthority>> grantedAuthoritySupplier) {
|
||||
this.grantedAuthoritySupplier = grantedAuthoritySupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
|
||||
Reference in New Issue
Block a user