org.openl.rules.webstudio.security.AuthenticationHolder Maven / Gradle / Ivy
package org.openl.rules.webstudio.security;
import org.springframework.security.core.Authentication;
/**
* Is intended to hold current user credentials during authentication process. Cleared after authentication process is
* finished.
*
*
* Difference from SecurityContextHolder:
*
* - SecurityContextHolder holds Authentication object only after successful authentication. In some
* cases it does not contain password (for example in AD).
* - AuthenticationHolder holds Authentication object during authentication process, and after it
* does not hold. Should contain password.
*
*
*
* For example needed to easily access user password while filling UserDetails and user authorities in AD.
*/
public final class AuthenticationHolder {
private AuthenticationHolder() {
}
private static final ThreadLocal AUTHENTICATION_HOLDER = new ThreadLocal<>();
public static void setAuthentication(Authentication authentication) {
AUTHENTICATION_HOLDER.set(authentication);
}
public static Authentication getAuthentication() {
return AUTHENTICATION_HOLDER.get();
}
public static void clear() {
AUTHENTICATION_HOLDER.remove();
}
}