Add SecurityContextHolderStrategy for Jaas
Issue gh-11060 Issue gh-11061
This commit is contained in:
@@ -28,6 +28,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* An implementation of {@link LoginModule} that uses a Spring Security
|
||||
@@ -55,6 +57,9 @@ public class SecurityContextLoginModule implements LoginModule {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SecurityContextLoginModule.class);
|
||||
|
||||
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
|
||||
.getContextHolderStrategy();
|
||||
|
||||
private Authentication authen;
|
||||
|
||||
private Subject subject;
|
||||
@@ -93,6 +98,17 @@ public class SecurityContextLoginModule implements LoginModule {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link SecurityContextHolderStrategy} to use. The default action is to use
|
||||
* the {@link SecurityContextHolderStrategy} stored in {@link SecurityContextHolder}.
|
||||
*
|
||||
* @since 5.8
|
||||
*/
|
||||
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) {
|
||||
Assert.notNull(securityContextHolderStrategy, "securityContextHolderStrategy cannot be null");
|
||||
this.securityContextHolderStrategy = securityContextHolderStrategy;
|
||||
}
|
||||
|
||||
Authentication getAuthentication() {
|
||||
return this.authen;
|
||||
}
|
||||
@@ -129,7 +145,7 @@ public class SecurityContextLoginModule implements LoginModule {
|
||||
*/
|
||||
@Override
|
||||
public boolean login() throws LoginException {
|
||||
this.authen = SecurityContextHolder.getContext().getAuthentication();
|
||||
this.authen = this.securityContextHolderStrategy.getContext().getAuthentication();
|
||||
if (this.authen != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user