use of org.gluu.oxauth.client.conf.ClaimToAttributeMapping in project oxTrust by GluuFederation.
the class OpenIdClient method retrieveUserProfileFromUserInfoResponse.
protected CommonProfile retrieveUserProfileFromUserInfoResponse(final WebContext context, final UserInfoResponse userInfoResponse) {
final CommonProfile profile = new CommonProfile();
String nonceResponse = getFirstClaim(userInfoResponse, JwtClaimName.NONCE);
final String nonceSession = (String) context.getSessionAttribute(getName() + 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");
}
String id = getFirstClaim(userInfoResponse, JwtClaimName.USER_NAME);
if (StringHelper.isEmpty(id)) {
id = getFirstClaim(userInfoResponse, JwtClaimName.SUBJECT_IDENTIFIER);
}
profile.setId(id);
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;
}
use of org.gluu.oxauth.client.conf.ClaimToAttributeMapping in project oxTrust by GluuFederation.
the class OpenIdClient method retrieveUserProfileFromUserInfoResponse.
protected CommonProfile retrieveUserProfileFromUserInfoResponse(final UserInfoResponse userInfoResponse) {
final CommonProfile profile = new CommonProfile();
String id = getFirstClaim(userInfoResponse, JwtClaimName.USER_NAME);
if (StringHelper.isEmpty(id)) {
id = getFirstClaim(userInfoResponse, JwtClaimName.SUBJECT_IDENTIFIER);
}
profile.setId(id);
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