[keycloak-user] Geeting user mapped attributes
Atienzar Navarro, Marcial
matienzar at umivale.es
Sun Nov 12 14:11:52 EST 2017
Hello,
I've configure wildfly adapter, and I'm trying to get access to user mapped atriubutes with this code:
private String getDniFromAccessToken() {
String dni = null;
Principal httpPrincipal = request.getUserPrincipal();
if (httpPrincipal instanceof KeycloakPrincipal) {
KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) httpPrincipal;
AccessToken token = kp.getKeycloakSecurityContext().getToken();
LOGGER.info("JWT {}",kp.getKeycloakSecurityContext().getTokenString());
LOGGER.info("JWT ID {}",kp.getKeycloakSecurityContext().getIdTokenString());
// Puede que no tengamos todavÃa el token
if (token != null) {
// LOGGER.info("Email {}",token.getEmail());
LOGGER.info("Tenemos un token de keycloak con el que podemos consultar sus atributos");
Map<String, Object> atributos = token.getOtherClaims();
if (atributos != null && !atributos.isEmpty()) {
if(LOGGER.isInfoEnabled()){
for(Map.Entry<String,Object> atts : atributos.entrySet()){
LOGGER.info("Atributos del token {} - {}",atts.getKey(),atts.getValue());
}
}
if (atributos.containsKey("dni")) {
dni = String.valueOf(atributos.get("dni"));
LOGGER.info("DINI recuperado de keycloak {}", dni);
}
} else {
LOGGER.info("No nos llegan atributos de keycloak");
}
} else {
LOGGER.info("No tenemos el ID del token de Keycloak");
}
}
return dni;
}
I've try with getIdToken and getToken, but I only retrieve client_session.
Is it possible to get this user mapped attributes?
--
Marcial Atiénzar Navarro
Desarrollo
Avda. Real Monasterio de Poblet, 20
46930 Quart de Poblet (Valencia)
Tél.: +34 96 184 92 49 (corto 1249)
Móvil: +34 629 201 240 (corto 44249)
matienzar at umivale.es<mailto:matienzar at umivale.es>
www.umivale.es<http://www.umivale.es>
More information about the keycloak-user
mailing list