Search in sources :

Example 26 with RequestObjectException

use of org.wso2.carbon.identity.oauth2.RequestObjectException in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCRequestObjectUtil method buildRequestObject.

/**
 * Fetch and invoke the matched request builder class based on the identity.xml configurations.
 * Build and validate the Request Object extracted from request information
 *
 * @param oauthRequest authorization request
 * @throws RequestObjectException
 */
public static RequestObject buildRequestObject(OAuthAuthzRequest oauthRequest, OAuth2Parameters oAuth2Parameters) throws RequestObjectException {
    /*
          So that the request is a valid OAuth 2.0 Authorization Request, values for the response_type and client_id
          parameters MUST be included using the OAuth 2.0 request syntax, since they are REQUIRED by OAuth 2.0.
          The values for these parameters MUST match those in the Request Object, if present
         */
    RequestObject requestObject;
    RequestObjectBuilder requestObjectBuilder;
    String requestObjType;
    if (isRequestParameter(oauthRequest)) {
        requestObjectBuilder = getRequestObjectBuilder(REQUEST_PARAM_VALUE_BUILDER);
        requestObjType = REQUEST;
    } else if (isRequestUri(oauthRequest)) {
        requestObjectBuilder = getRequestObjectBuilder(REQUEST_URI_PARAM_VALUE_BUILDER);
        requestObjType = REQUEST_URI;
    } else {
        // Unsupported request object type.
        return null;
    }
    if (requestObjectBuilder == null) {
        String error = "Unable to build the OIDC Request Object from:";
        if (LoggerUtils.isDiagnosticLogsEnabled()) {
            Map<String, Object> params = new HashMap<>();
            params.put(REQUEST, oauthRequest.getParam(REQUEST));
            params.put(REQUEST_URI, oauthRequest.getParam(REQUEST_URI));
            LoggerUtils.triggerDiagnosticLogEvent(OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, params, OAuthConstants.LogConstants.FAILED, "Server error occurred.", "parse-request-object", null);
        }
        throw new RequestObjectException(OAuth2ErrorCodes.SERVER_ERROR, error + requestObjType);
    }
    requestObject = requestObjectBuilder.buildRequestObject(oauthRequest.getParam(requestObjType), oAuth2Parameters);
    RequestObjectValidator requestObjectValidator = OAuthServerConfiguration.getInstance().getRequestObjectValidator();
    validateRequestObjectSignature(oAuth2Parameters, requestObject, requestObjectValidator);
    if (!requestObjectValidator.validateRequestObject(requestObject, oAuth2Parameters)) {
        throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST, "Invalid parameters " + "found in the Request Object.");
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully build and and validated request Object for: " + requestObjType);
    }
    return requestObject;
}
Also used : RequestObjectException(org.wso2.carbon.identity.oauth2.RequestObjectException) HashMap(java.util.HashMap) RequestObject(org.wso2.carbon.identity.openidconnect.model.RequestObject) RequestObject(org.wso2.carbon.identity.openidconnect.model.RequestObject)

Aggregations

RequestObjectException (org.wso2.carbon.identity.oauth2.RequestObjectException)23 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)9 HashMap (java.util.HashMap)7 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)6 JOSEException (com.nimbusds.jose.JOSEException)4 ArrayList (java.util.ArrayList)4 OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)4 SignedJWT (com.nimbusds.jwt.SignedJWT)3 ParseException (java.text.ParseException)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 JSONObject (net.minidev.json.JSONObject)3 ClaimMetaData (org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.ClaimMetaData)3 RequestedClaim (org.wso2.carbon.identity.openidconnect.model.RequestedClaim)3 JWEHeader (com.nimbusds.jose.JWEHeader)2 JWEObject (com.nimbusds.jose.JWEObject)2 RSAEncrypter (com.nimbusds.jose.crypto.RSAEncrypter)2 EncryptedJWT (com.nimbusds.jwt.EncryptedJWT)2 List (java.util.List)2 JSONObject (org.json.JSONObject)2