Java Code Examples for org.apache.oltu.oauth2.client.response.OAuthClientResponse#getParam()

The following examples show how to use org.apache.oltu.oauth2.client.response.OAuthClientResponse#getParam() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuthClientValidator.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
public void validateRequiredParameters(OAuthClientResponse response) throws OAuthProblemException {
    Set<String> missingParameters = new HashSet<String>();

    for (Map.Entry<String, String[]> requiredParam : requiredParams.entrySet()) {
        String paramName = requiredParam.getKey();
        String val = response.getParam(paramName);
        if (OAuthUtils.isEmpty(val)) {
            missingParameters.add(paramName);
        } else {
            String[] dependentParams = requiredParam.getValue();
            if (!OAuthUtils.hasEmptyValues(dependentParams)) {
                for (String dependentParam : dependentParams) {
                    val = response.getParam(dependentParam);
                    if (OAuthUtils.isEmpty(val)) {
                        missingParameters.add(dependentParam);
                    }
                }
            }
        }
    }

    if (!missingParameters.isEmpty()) {
        throw OAuthUtils.handleMissingParameters(missingParameters);
    }
}
 
Example 2
Source File: OAuthClientValidator.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public void validateErrorResponse(OAuthClientResponse response) throws OAuthProblemException {
    String error = response.getParam(OAuthError.OAUTH_ERROR);
    if (!OAuthUtils.isEmpty(error)) {
        String errorDesc = response.getParam(OAuthError.OAUTH_ERROR_DESCRIPTION);
        String errorUri = response.getParam(OAuthError.OAUTH_ERROR_URI);
        String state = response.getParam(OAuth.OAUTH_STATE);
        throw OAuthProblemException.error(error).description(errorDesc).uri(errorUri).state(state);
    }
}
 
Example 3
Source File: OAuthClientValidator.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public void validateNotAllowedParameters(OAuthClientResponse response) throws OAuthProblemException {
    List<String> notAllowedParameters = new ArrayList<String>();
    for (String requiredParam : notAllowedParams) {
        String val = response.getParam(requiredParam);
        if (!OAuthUtils.isEmpty(val)) {
            notAllowedParameters.add(requiredParam);
        }
    }
    if (!notAllowedParameters.isEmpty()) {
        throw OAuthUtils.handleNotAllowedParametersOAuthException(notAllowedParameters);
    }
}
 
Example 4
Source File: YahooOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get the user info endpoint.
 *
 * @param token OAuth client response.
 * @return User info endpoint.
 */
@Override
protected String getUserInfoEndpoint(OAuthClientResponse token, Map<String, String> authenticatorProperties) {

    String userGUID = token.getParam(YahooOAuth2AuthenticatorConstants.USER_GUID);
    return getUserInfoURL() + userGUID + YahooOAuth2AuthenticatorConstants.YAHOO_USER_DETAILS_JSON;
}
 
Example 5
Source File: OpenIDConnectAuthenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Get subject attributes.
 * @param token OAuthClientResponse
 * @param authenticatorProperties Map<String, String> (Authenticator property, Property value)
 * @return Map<ClaimMapping, String> Claim mappings.
 */
protected Map<ClaimMapping, String> getSubjectAttributes(OAuthClientResponse token,
                                                         Map<String, String> authenticatorProperties) {

    Map<ClaimMapping, String> claims = new HashMap<>();

    try {
        String accessToken = token.getParam(OIDCAuthenticatorConstants.ACCESS_TOKEN);
        String url = getUserInfoEndpoint(token, authenticatorProperties);
        String json = sendRequest(url, accessToken);

        if (StringUtils.isBlank(json)) {
            if(log.isDebugEnabled()) {
                log.debug("Empty JSON response from user info endpoint. Unable to fetch user claims." +
                        " Proceeding without user claims");
            }
            return claims;
        }

        Map<String, Object> jsonObject = JSONUtils.parseJSON(json);

        for (Map.Entry<String, Object> data : jsonObject.entrySet()) {
            String key = data.getKey();
            Object value = data.getValue();

            if (value != null) {
                claims.put(ClaimMapping.build(key, key, null, false), value.toString());
            }

            if (log.isDebugEnabled() &&
                    IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
                log.debug("Adding claims from end-point data mapping : " + key + " - " +
                        jsonObject.get(key).toString());
            }
        }
    } catch (IOException e) {
        log.error("Communication error occurred while accessing user info endpoint", e);
    }

    return claims;
}
 
Example 6
Source File: YahooOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Get subject attributes.
 *
 * @param token                   OAuthClientResponse
 * @param authenticatorProperties Map<String, String>
 * @return Map<ClaimMapping, String> Claim mappings.
 */
protected Map<ClaimMapping, String> getSubjectAttributes(OAuthClientResponse token,
                                                         Map<String, String> authenticatorProperties) {

    Map<ClaimMapping, String> claims = new HashMap<>();

    try {
        String accessToken = token.getParam(OIDCAuthenticatorConstants.ACCESS_TOKEN);
        String url = getUserInfoEndpoint(token, authenticatorProperties);
        String json = sendRequest(url, accessToken);

        if (StringUtils.isBlank(json)) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to fetch user claims. Proceeding without user claims");
            }
            return claims;
        }

        Map<String, Object> jsonObject = JSONUtils.parseJSON(json);
        Map<String, Object> profile = null;

        if (!jsonObject.isEmpty()) {

            // Extract the inner profile JSON object.
            profile = JSONUtils.parseJSON(jsonObject.entrySet().iterator().next().getValue().toString());
        }

        if (profile == null) {
            if (log.isDebugEnabled()) {
                log.debug("Invalid user profile object. Proceeding without user claims");
            }
            return claims;
        }

        for (Map.Entry<String, Object> data : profile.entrySet()) {
            String key = data.getKey();
            claims.put(ClaimMapping.build(key, key, null, false), profile.get(key).toString());

            if (log.isDebugEnabled()
                    && IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
                log.debug("Adding claims from end-point data mapping : " + key + " - " +
                        profile.get(key).toString());
            }
        }
    } catch (IOException e) {
        log.error("Communication error occurred while accessing user info endpoint", e);
    }
    return claims;
}
 
Example 7
Source File: WindowsLiveOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param token
 * @return
 */
@Override
protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) {
    return token.getParam(WindowsLiveOAuth2AuthenticatorConstants.USER_ID);
}
 
Example 8
Source File: YahooOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 2 votes vote down vote up
/**
 * Get Authenticated User
 *
 * @param token OAuth client response.
 * @return GUID of the authenticated user.
 */
@Override
protected String getAuthenticateUser(AuthenticationContext context, Map<String, Object> jsonObject, OAuthClientResponse token) {

    return token.getParam(YahooOAuth2AuthenticatorConstants.USER_GUID);
}