use of org.gluu.conf.model.ClaimToAttributeMapping in project oxTrust by GluuFederation.
the class OpenIdClient method retrieveUserProfileFromUserInfoResponse.
protected CommonProfile retrieveUserProfileFromUserInfoResponse(final WebContext context, final Jwt jwt, final UserInfoResponse userInfoResponse) {
final CommonProfile profile = new CommonProfile();
String nonceResponse = (String) jwt.getClaims().getClaim(JwtClaimName.NONCE);
final String nonceSession = (String) context.getSessionAttribute(getName() + SESSION_NONCE_PARAMETER);
logger.debug("Session nonce: '{}'", nonceSession);
if (!StringHelper.equals(nonceSession, nonceResponse)) {
logger.error("User info response: nonce is not matching.");
throw new CommunicationException("Nonce is not match" + nonceResponse + " : " + nonceSession);
}
String id = getFirstClaim(userInfoResponse, JwtClaimName.USER_NAME);
if (StringHelper.isEmpty(id)) {
id = getFirstClaim(userInfoResponse, JwtClaimName.SUBJECT_IDENTIFIER);
}
profile.setId(id);
String acrResponse = (String) jwt.getClaims().getClaim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE);
logger.debug("Authentication ACR: '{}'", acrResponse);
profile.setUsedAcr(acrResponse);
List<ClaimToAttributeMapping> claimMappings = this.appConfiguration.getOpenIdClaimMapping();
if ((claimMappings == null) || (claimMappings.size() == 0)) {
logger.info("Using default claims to attributes mapping");
profile.setUserName(id);
profile.setEmail(getFirstClaim(userInfoResponse, JwtClaimName.EMAIL));
profile.setDisplayName(getFirstClaim(userInfoResponse, JwtClaimName.NAME));
profile.setFirstName(getFirstClaim(userInfoResponse, JwtClaimName.GIVEN_NAME));
profile.setFamilyName(getFirstClaim(userInfoResponse, JwtClaimName.FAMILY_NAME));
profile.setZone(getFirstClaim(userInfoResponse, JwtClaimName.ZONEINFO));
profile.setLocale(getFirstClaim(userInfoResponse, JwtClaimName.LOCALE));
} else {
for (ClaimToAttributeMapping mapping : claimMappings) {
String attribute = mapping.getAttribute();
String value = getFirstClaim(userInfoResponse, mapping.getClaim());
profile.addAttribute(attribute, value);
logger.trace("Adding attribute '{}' with value '{}'", attribute, value);
}
}
return profile;
}
Aggregations