Search in sources :

Example 1 with RequestParameter

use of org.wso2.carbon.identity.oauth2.model.RequestParameter in project carbon-apimgt by wso2.

the class SystemScopesIssuer method getSignedJWT.

/**
 * Method to parse the assertion and retrieve the signed JWT
 *
 * @param tokReqMsgCtx request
 * @return SignedJWT object
 * @throws IdentityOAuth2Exception exception thrown due to a parsing error
 */
private SignedJWT getSignedJWT(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
    RequestParameter[] params = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getRequestParameters();
    String assertion = null;
    SignedJWT signedJWT;
    for (RequestParameter param : params) {
        if (param.getKey().equals(APIConstants.SystemScopeConstants.OAUTH_JWT_ASSERTION)) {
            assertion = param.getValue()[0];
            break;
        }
    }
    if (StringUtils.isEmpty(assertion)) {
        String errorMessage = "Error while retrieving assertion";
        throw new IdentityOAuth2Exception(errorMessage);
    }
    try {
        signedJWT = SignedJWT.parse(assertion);
        if (log.isDebugEnabled()) {
            log.debug(signedJWT);
        }
    } catch (ParseException e) {
        String errorMessage = "Error while parsing the JWT.";
        throw new IdentityOAuth2Exception(errorMessage, e);
    }
    return signedJWT;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) RequestParameter(org.wso2.carbon.identity.oauth2.model.RequestParameter) SignedJWT(com.nimbusds.jwt.SignedJWT) ParseException(java.text.ParseException)

Aggregations

SignedJWT (com.nimbusds.jwt.SignedJWT)1 ParseException (java.text.ParseException)1 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)1 RequestParameter (org.wso2.carbon.identity.oauth2.model.RequestParameter)1