JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); json = json.get(attributesNode); if (json != null) {
@Override public YahooProfile extractUserProfile(final String body) { final YahooProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { json = json.get("profile"); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "guid"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body, "profile"); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public Google2Profile extractUserProfile(final String body) { final Google2Profile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public TwitterProfile extractUserProfile(final String body) { final TwitterProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public VkProfile extractUserProfile(final String body) { final VkProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { ArrayNode array = (ArrayNode) json.get("response"); JsonNode userNode = array.get(0); if (userNode == null) { raiseProfileExtractionJsonError(body, "response"); } profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(userNode, "uid"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(userNode, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public WordPressProfile extractUserProfile(final String body) { final WordPressProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "ID"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } json = json.get("meta"); if (json != null) { final String attribute = WordPressProfileDefinition.LINKS; convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public WeiboProfile extractUserProfile(final String body) throws HttpAction { final WeiboProfile profile = new WeiboProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId( ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public GitHubProfile extractUserProfile(final String body) { final GitHubProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public WindowsLiveProfile extractUserProfile(final String body) { final WindowsLiveProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public StravaProfile extractUserProfile(String body) { final StravaProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, StravaProfileDefinition.ID))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public OkProfile extractUserProfile(String body) { final OkProfile profile = newProfile(); JsonNode userNode = JsonHelper.getFirstNode(body); if (userNode != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(userNode, OkProfileDefinition.UID))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(userNode, attribute)); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public OAuth20Profile extractUserProfile(final String body) { final OAuth20Profile profile = new OAuth20Profile(); final JsonNode json = JsonHelper.getFirstNode(body, getFirstNodePath()); if (json != null) { if (getProfileId() != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, getProfileId()))); } for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } for (final String attribute : getSecondaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } for (final Map.Entry<String, String> entry : getProfileAttributes().entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); convertAndAdd(profile, PROFILE_ATTRIBUTE, key, JsonHelper.getElement(json, value)); } } else { raiseProfileExtractionJsonError(body); } return profile; }
@Override public HiOrgServerProfile extractUserProfile(String body) { final HiOrgServerProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { logger.debug("Extracting user profile from JSON node " + json); profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, USER_ID))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } // Secondary attributes are generated from primary attributes convertAndAdd(profile, PROFILE_ATTRIBUTE, ALTERNATIVE_ID, profile.getAlternativeId()); convertAndAdd(profile, PROFILE_ATTRIBUTE, TYPED_ALTERNATIVE_ID, profile.getTypedAlternativeId()); } else { raiseProfileExtractionJsonError(body); } extractRoles(profile); return profile; }
@Override public BitbucketProfile extractUserProfile(final String body) { final BitbucketProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { json = (JsonNode) JsonHelper.getElement(json, "user"); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, Pac4jConstants.USERNAME))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } } else { raiseProfileExtractionJsonError(body, "user"); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
@Override public FoursquareProfile extractUserProfile(String body) { FoursquareProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json == null) { raiseProfileExtractionJsonError(body); } JsonNode response = (JsonNode) JsonHelper.getElement(json, "response"); if (response == null) { raiseProfileExtractionJsonError(body, "response"); } JsonNode user = (JsonNode) JsonHelper.getElement(response, "user"); if (user != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(user, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(user, attribute)); } } else { raiseProfileExtractionJsonError(body, "user"); } return profile; } }
@Override public LinkedIn2Profile extractUserProfile(final String body) { LinkedIn2Profile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json == null) { raiseProfileExtractionJsonError(body); } profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } final Object positions = JsonHelper.getElement(json, LinkedIn2ProfileDefinition.POSITIONS); if (positions != null && positions instanceof JsonNode) { convertAndAdd(profile, PROFILE_ATTRIBUTE, LinkedIn2ProfileDefinition.POSITIONS, JsonHelper.getElement((JsonNode) positions, "values")); } addUrl(profile, json, LinkedIn2ProfileDefinition.SITE_STANDARD_PROFILE_REQUEST); addUrl(profile, json, LinkedIn2ProfileDefinition.API_STANDARD_PROFILE_REQUEST); return profile; }
@Override public DropBoxProfile extractUserProfile(final String body) { final DropBoxProfile profile = newProfile(); JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "account_id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } json = (JsonNode) JsonHelper.getElement(json, "name"); if (json != null) { convertAndAdd(profile, PROFILE_ATTRIBUTE, FIRST_NAME, JsonHelper.getElement(json, "familiar_name")); convertAndAdd(profile, PROFILE_ATTRIBUTE, FAMILY_NAME, JsonHelper.getElement(json, "surname")); convertAndAdd(profile, PROFILE_ATTRIBUTE, DISPLAY_NAME, JsonHelper.getElement(json, "display_name")); } } else { raiseProfileExtractionJsonError(body); } return profile; } }
profile.setId(ProfileHelper.sanitizeIdentifier(profile, claimsSet.getSubject()));
@Override public FacebookProfile extractUserProfile(final String body) { final FacebookProfile profile = newProfile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(ProfileHelper.sanitizeIdentifier(profile, JsonHelper.getElement(json, "id"))); for (final String attribute : getPrimaryAttributes()) { convertAndAdd(profile, PROFILE_ATTRIBUTE, attribute, JsonHelper.getElement(json, attribute)); } extractData(profile, json, FacebookProfileDefinition.FRIENDS); extractData(profile, json, FacebookProfileDefinition.MOVIES); extractData(profile, json, FacebookProfileDefinition.MUSIC); extractData(profile, json, FacebookProfileDefinition.BOOKS); extractData(profile, json, FacebookProfileDefinition.LIKES); extractData(profile, json, FacebookProfileDefinition.ALBUMS); extractData(profile, json, FacebookProfileDefinition.EVENTS); extractData(profile, json, FacebookProfileDefinition.GROUPS); extractData(profile, json, FacebookProfileDefinition.MUSIC_LISTENS); extractData(profile, json, FacebookProfileDefinition.PICTURE); } else { raiseProfileExtractionJsonError(body); } return profile; }