Search in sources :

Example 1 with CommonProfile

use of org.gluu.oxauth.client.auth.user.CommonProfile 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;
}
Also used : CommunicationException(org.gluu.oxauth.client.exception.CommunicationException) CommonProfile(org.gluu.oxauth.client.auth.user.CommonProfile) ClaimToAttributeMapping(org.gluu.oxauth.client.conf.ClaimToAttributeMapping)

Example 2 with CommonProfile

use of org.gluu.oxauth.client.auth.user.CommonProfile 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;
}
Also used : CommonProfile(org.gluu.oxauth.client.auth.user.CommonProfile) ClaimToAttributeMapping(org.gluu.oxauth.client.conf.ClaimToAttributeMapping)

Aggregations

CommonProfile (org.gluu.oxauth.client.auth.user.CommonProfile)2 ClaimToAttributeMapping (org.gluu.oxauth.client.conf.ClaimToAttributeMapping)2 CommunicationException (org.gluu.oxauth.client.exception.CommunicationException)1