All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.capitalone.dashboard.auth.AuthenticationUtil Maven / Gradle / Ivy

There is a newer version: 3.4.53
Show newest version
package com.capitalone.dashboard.auth;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.capitalone.dashboard.model.AuthType;

public class AuthenticationUtil {

	public static final String AUTH_TYPE = "auth_type";
	
	public static String getUsernameFromContext() {
		Authentication authentication = getAuthentication();
		if (authentication != null) {
			return authentication.getName();
		}
		
		return null;
	}
	
	public static AuthType getAuthTypeFromContext() {
		Authentication authentication = getAuthentication();
		if (authentication != null && authentication.getDetails() instanceof String) {
			return AuthType.valueOf((String)authentication.getDetails());
		} else if (authentication != null && authentication.getDetails() instanceof AuthType) {
			return (AuthType)authentication.getDetails();
		}
		
		return null;
	}
	
	private static Authentication getAuthentication() {
		return SecurityContextHolder.getContext().getAuthentication();
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy