Search in sources :

Example 1 with RequestParameter

use of org.wso2.carbon.identity.workflow.mgt.bean.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)

Example 2 with RequestParameter

use of org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter in project carbon-identity-framework by wso2.

the class AbstractWorkflowRequestHandler method getParameter.

/**
 * Wraps the parameters to the WorkflowParameter
 *
 * @param name     Name of the parameter
 * @param value    Value of the parameter
 * @param required Whether it is required to sent to the workflow executor
 * @return
 */
protected RequestParameter getParameter(String name, Object value, boolean required) throws WorkflowRuntimeException {
    RequestParameter parameter = new RequestParameter();
    parameter.setName(name);
    parameter.setValue(value);
    parameter.setRequiredInWorkflow(required);
    String valueType = getParamDefinitions().get(name);
    if (valueType == null || value == null) {
        // null value as param, or undefined param
        parameter.setValueType(WorkflowDataType.OTHER_TYPE);
    } else {
        if (isValueValid(name, value, valueType)) {
            parameter.setValueType(valueType);
        } else {
            throw new WorkflowRuntimeException("Invalid value for '" + name + "', Expected: '" + valueType + "', " + "but was of " + value.getClass().getName());
        }
    }
    return parameter;
}
Also used : RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter) WorkflowRuntimeException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowRuntimeException)

Example 3 with RequestParameter

use of org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter in project carbon-identity-framework by wso2.

the class WorkflowRequestBuilder method buildXMLRequest.

/**
 * Create OM Element from workflow request parameters.
 *
 * @param workFlowRequest Workflow parameters
 * @param initParams      Non workflow parameters
 * @return
 * @throws WorkflowRuntimeException
 */
public static OMElement buildXMLRequest(WorkflowRequest workFlowRequest, Map<String, Object> initParams) throws WorkflowRuntimeException {
    WorkflowRequestBuilder requestBuilder = new WorkflowRequestBuilder(workFlowRequest.getUuid(), workFlowRequest.getEventType());
    for (RequestParameter parameter : workFlowRequest.getRequestParameters()) {
        if (parameter.isRequiredInWorkflow()) {
            switch(parameter.getValueType()) {
                case WorkflowDataType.BOOLEAN_TYPE:
                case WorkflowDataType.STRING_TYPE:
                case WorkflowDataType.INTEGER_TYPE:
                case WorkflowDataType.DOUBLE_TYPE:
                    requestBuilder.addSingleValuedParam(parameter.getName(), parameter.getValue());
                    break;
                case WorkflowDataType.STRING_LIST_TYPE:
                case WorkflowDataType.DOUBLE_LIST_TYPE:
                case WorkflowDataType.INTEGER_LIST_TYPE:
                case WorkflowDataType.BOOLEAN_LIST_TYPE:
                    requestBuilder.addListTypeParam(parameter.getName(), (List<Object>) parameter.getValue());
                    break;
                case WorkflowDataType.STRING_STRING_MAP_TYPE:
                    requestBuilder.addMapTypeParam(parameter.getName(), (Map<String, Object>) parameter.getValue());
                    break;
            }
        }
    }
    requestBuilder.setInitParams(initParams);
    return requestBuilder.buildRequest();
}
Also used : RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter)

Example 4 with RequestParameter

use of org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter in project carbon-identity-framework by wso2.

the class AbstractWorkflowRequestHandler method startWorkFlow.

/**
 * Start a new workflow.
 *
 * @param wfParams    Parameters related to workflow
 * @param nonWfParams Other parameters
 * @param uuid        Unique ID of request
 * @return
 * @throws WorkflowException
 */
public WorkflowExecutorResult startWorkFlow(Map<String, Object> wfParams, Map<String, Object> nonWfParams, String uuid) throws WorkflowException {
    if (isWorkflowCompleted()) {
        return new WorkflowExecutorResult(ExecutorResultState.COMPLETED);
    }
    if (!isAssociated()) {
        return new WorkflowExecutorResult(ExecutorResultState.NO_ASSOCIATION);
    }
    WorkflowRequest workFlowRequest = new WorkflowRequest();
    List<RequestParameter> parameters = new ArrayList<RequestParameter>(wfParams.size() + nonWfParams.size() + 1);
    for (Map.Entry<String, Object> paramEntry : wfParams.entrySet()) {
        parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), true));
    }
    for (Map.Entry<String, Object> paramEntry : nonWfParams.entrySet()) {
        parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), false));
    }
    RequestParameter uuidParameter = new RequestParameter();
    uuidParameter.setName(WFConstant.REQUEST_ID);
    uuidParameter.setValue(uuid);
    uuidParameter.setRequiredInWorkflow(true);
    uuidParameter.setValueType(WorkflowDataType.STRING_TYPE);
    parameters.add(uuidParameter);
    workFlowRequest.setRequestParameters(parameters);
    workFlowRequest.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    workFlowRequest.setUuid(uuid);
    engageWorkflow(workFlowRequest);
    WorkflowExecutorResult workflowExecutorResult = WorkFlowExecutorManager.getInstance().executeWorkflow(workFlowRequest);
    if (workflowExecutorResult.getExecutorResultState() == ExecutorResultState.FAILED) {
        throw new WorkflowException(workflowExecutorResult.getMessage());
    }
    return workflowExecutorResult;
}
Also used : WorkflowExecutorResult(org.wso2.carbon.identity.workflow.mgt.WorkflowExecutorResult) RequestParameter(org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowRequest(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowRequest)

Example 5 with RequestParameter

use of org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter in project identity-inbound-auth-oauth by wso2-extensions.

the class CibaGrantHandler method getAuthReqId.

/**
 * Checks whether ciba authentication request identifier exists and .
 *
 * @param tokReqMsgCtx Authentication Request Identifier as JSON.
 * @return String Authentication Request Identifier from the request.
 * @throws IdentityOAuth2Exception Exception thrown regarding IdentityOAuth
 */
protected String getAuthReqId(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
    // Initiating auth_req_id.
    String authReqId = null;
    RequestParameter[] parameters = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getRequestParameters();
    // Obtaining auth_req_id from request.
    for (RequestParameter parameter : parameters) {
        if (AUTH_REQ_ID.equals(parameter.getKey())) {
            if (parameter.getValue() != null && parameter.getValue().length > 0) {
                authReqId = parameter.getValue()[0];
            }
        }
    }
    if (authReqId == null) {
        if (log.isDebugEnabled()) {
            log.debug("token request misses mandated parameter (auth_req_id).");
        }
        throw new IdentityOAuth2Exception(MISSING_AUTH_REQ_ID);
    }
    return authReqId;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) RequestParameter(org.wso2.carbon.identity.oauth2.model.RequestParameter)

Aggregations

RequestParameter (org.wso2.carbon.identity.oauth2.model.RequestParameter)5 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)4 RequestParameter (org.wso2.carbon.identity.workflow.mgt.bean.RequestParameter)4 HashMap (java.util.HashMap)3 X509Certificate (java.security.cert.X509Certificate)2 SignedJWT (com.nimbusds.jwt.SignedJWT)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateException (java.security.cert.CertificateException)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DateTime (org.joda.time.DateTime)1 XMLObject (org.opensaml.core.xml.XMLObject)1 Assertion (org.opensaml.saml.saml1.core.Assertion)1 Audience (org.opensaml.saml.saml1.core.Audience)1 AudienceRestrictionCondition (org.opensaml.saml.saml1.core.AudienceRestrictionCondition)1