use of com.vsct.vboard.config.cognito.JsonWebTokenAuthentication in project vboard by voyages-sncf-technologies.
the class AuthenticationController method getUserEmailFromAuth.
private static String getUserEmailFromAuth(Authentication auth) {
if (auth instanceof JsonWebTokenAuthentication) {
return ((JsonWebTokenAuthentication) auth).getEmail();
}
final KeycloakPrincipal userDetails = (KeycloakPrincipal) auth.getPrincipal();
final IDToken idToken = userDetails.getKeycloakSecurityContext().getToken();
return idToken.getEmail();
}
use of com.vsct.vboard.config.cognito.JsonWebTokenAuthentication in project vboard by voyages-sncf-technologies.
the class AuthenticationController method createUserFromAuth.
@NotNull
@SuppressFBWarnings("CLI_CONSTANT_LIST_INDEX")
private static User createUserFromAuth(Authentication auth) {
if (auth instanceof JsonWebTokenAuthentication) {
JsonWebTokenAuthentication jwtAuth = ((JsonWebTokenAuthentication) auth);
String username = jwtAuth.getName();
String[] parts = StringUtils.split(username, "\\");
if (parts != null) {
username = parts[1];
}
parts = StringUtils.split(username, "_");
if (parts == null) {
throw new IllegalArgumentException("The username in the JWT token provided does not contain a '_'");
}
String firstName = StringUtils.capitalize(parts[0]);
String lastName = StringUtils.capitalize(parts[1]);
LOGGER.info("createUserFromAuth/JWT: email={} firstName={} lastName={}", jwtAuth.getEmail(), firstName, lastName);
return new User(jwtAuth.getEmail(), firstName, lastName);
}
final KeycloakPrincipal userDetails = (KeycloakPrincipal) auth.getPrincipal();
final IDToken idToken = userDetails.getKeycloakSecurityContext().getToken();
LOGGER.info("createUserFromAuth/Keycloak: email={} firstName={} lastName={}", idToken.getEmail(), idToken.getGivenName(), idToken.getFamilyName());
return new User(idToken.getEmail(), idToken.getGivenName(), idToken.getFamilyName());
}
Aggregations