com.icthh.xm.commons.security.internal.SpringSecurityXmAuthenticationContext Maven / Gradle / Ivy
package com.icthh.xm.commons.security.internal;
import com.icthh.xm.commons.security.XmAuthenticationConstants;
import com.icthh.xm.commons.security.XmAuthenticationContext;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
/**
* The {@link SpringSecurityXmAuthenticationContext} class.
*/
class SpringSecurityXmAuthenticationContext implements XmAuthenticationContext {
private static final Class> ANONYMOUS_AUTH_CLASS = AnonymousAuthenticationToken.class;
private static final Class> REMEMBER_ME_AUTH_CLASS = RememberMeAuthenticationToken.class;
private final SecurityContext securityContext;
SpringSecurityXmAuthenticationContext(SecurityContext securityContext) {
this.securityContext = Objects.requireNonNull(securityContext, "securityContext can't be null");
}
public Optional getAuthentication() {
return Optional.ofNullable(securityContext.getAuthentication());
}
private Optional