Search in sources :

Example 1 with RegistrationResponse

use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpOIDCRegistrationResponseFactoryTest method testCreate.

@Test
public void testCreate() throws Exception {
    OIDCRegistrationResponseProfile registrationResponseProfile = new OIDCRegistrationResponseProfile();
    registrationResponseProfile.setClientId("client_id");
    registrationResponseProfile.setClientName("client_name");
    registrationResponseProfile.setRedirectUrls(Arrays.asList("http://example.com", "http://foo.com"));
    registrationResponseProfile.setGrantTypes(Arrays.asList("code", "implicit"));
    registrationResponseProfile.setClientSecret("cl1ent_s3cr3t");
    registrationResponseProfile.setClientSecretExpiresAt("dummyExpiry");
    RegistrationResponse mockResponse = new RegistrationResponse.DCRRegisterResponseBuilder().setRegistrationResponseProfile(registrationResponseProfile).build();
    HttpIdentityResponse identityResponse = testedResponseFactory.create(mockResponse).build();
    assertEquals(identityResponse.getStatusCode(), HttpServletResponse.SC_CREATED, "Invalid status code.");
    assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL), OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE, "Invalid cache control header.");
    assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_PRAGMA), OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE, "Invalid pragma header.");
    assertEquals(identityResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE), MediaType.APPLICATION_JSON, "Invalid content type header.");
}
Also used : OIDCRegistrationResponseProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponseProfile) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse) OIDCRegistrationResponse(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponse) Test(org.testng.annotations.Test)

Example 2 with RegistrationResponse

use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpOIDCRegistrationResponseFactory method create.

@Override
public void create(HttpIdentityResponse.HttpIdentityResponseBuilder httpIdentityResponseBuilder, IdentityResponse identityResponse) {
    RegistrationResponse registrationResponse = null;
    if (identityResponse instanceof RegistrationResponse) {
        registrationResponse = (RegistrationResponse) identityResponse;
        httpIdentityResponseBuilder.setStatusCode(HttpServletResponse.SC_CREATED);
        httpIdentityResponseBuilder.addHeader(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL, OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE);
        httpIdentityResponseBuilder.addHeader(OAuthConstants.HTTP_RESP_HEADER_PRAGMA, OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE);
        httpIdentityResponseBuilder.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        httpIdentityResponseBuilder.setBody(generateSuccessfulResponse(registrationResponse).toJSONString());
    } else {
        // This else part will not be reached from application logic.
        log.error("Can't create httpIdentityResponseBuilder. identityResponse is not an instance of " + "RegistrationResponse");
    }
}
Also used : RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)

Example 3 with RegistrationResponse

use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse in project carbon-business-process by wso2.

the class HTCoordinationContextHandler method invoke.

@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
    if (serverConfig == null || !serverConfig.isTaskRegistrationEnabled()) {
        return InvocationResponse.CONTINUE;
    }
    SOAPHeader soapHeader;
    try {
        soapHeader = messageContext.getEnvelope().getHeader();
    } catch (OMException ex) {
        throw new AxisFault("Error while extracting SOAP header", ex);
    }
    if (soapHeader == null) {
        if (log.isDebugEnabled()) {
            log.debug("No SOAP Header received. Continuing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    Iterator headers = soapHeader.getChildElements();
    SOAPHeaderBlock coordinationHeaderBlock = null;
    // Searching for WS-Coor Coordination Context
    while (headers.hasNext()) {
        SOAPHeaderBlock hb = (SOAPHeaderBlock) headers.next();
        if (hb.getLocalName().equals(Constants.WS_COOR_COORDINATION_CONTEXT) && hb.getNamespace().getNamespaceURI().equals(Constants.WS_COOR_NAMESPACE)) {
            coordinationHeaderBlock = hb;
            break;
        }
    }
    if (coordinationHeaderBlock == null) {
        if (log.isDebugEnabled()) {
            log.debug("No coordination context received. Processing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    // We have received a ws-coordination context. Now validate it for HT coordination type
    String coordinationType = SOAPUtils.getCoordinationType(coordinationHeaderBlock);
    if (!Constants.WS_HT_COORDINATION_TYPE.equals(coordinationType)) {
        // Found wrong coordination Type. We Only support http://docs.oasis-open.org/ns/bpel4people/ws-humantask/protocol/200803.
        // So we cannot allow message to go forward.
        String errorMsg = "Message aborted ! Invalid coordination type" + coordinationType + " . Support only " + Constants.WS_HT_COORDINATION_TYPE;
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    if (log.isDebugEnabled()) {
        log.debug("HT coordination context received.");
    }
    String identifier = SOAPUtils.getCoordinationIdentifier(coordinationHeaderBlock);
    String registrationService = SOAPUtils.getRegistrationService(coordinationHeaderBlock);
    // validating values. These values cannot be empty
    if (identifier == null || identifier.isEmpty() || registrationService == null || registrationService.isEmpty()) {
        String errorMsg = "Message aborted ! Invalid coordination context parameters.";
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    // Service URL of the HumanTask Coordination Protocol Handler AdminService
    String humanTaskProtocolHandlerServiceURL;
    try {
        humanTaskProtocolHandlerServiceURL = ServiceUtils.getTaskProtocolHandlerURL(messageContext.getConfigurationContext());
    } catch (HumanTaskCoordinationException e) {
        String errorMsg = "Error while generating HumanTask engine's protocol Handler Service URL.";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    // We are OK to invokeRegistrationService Registration service
    try {
        OMElement response = invokeRegistrationServiceUsingServiceClient(identifier, humanTaskProtocolHandlerServiceURL, registrationService);
        // But we are validating it for successful completion.
        if (!SOAPUtils.validateResponse(response, identifier)) {
            String errorMsg = "Message aborted ! registration response validation failed.";
            log.error(errorMsg);
            return InvocationResponse.ABORT;
        }
        // successful coordination
        if (log.isDebugEnabled()) {
            log.debug("RegistrationResponse received. Task is successfully coordinated with Task parent.");
        }
    } catch (AxisFault e) {
        String errorMsg = "Error while invoking registration service";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    return InvocationResponse.CONTINUE;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Iterator(java.util.Iterator) HumanTaskCoordinationException(org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 4 with RegistrationResponse

use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpRegistrationResponseFactory method create.

@Override
public void create(HttpIdentityResponse.HttpIdentityResponseBuilder httpIdentityResponseBuilder, IdentityResponse identityResponse) {
    RegistrationResponse registrationResponse = null;
    if (identityResponse instanceof RegistrationResponse) {
        registrationResponse = (RegistrationResponse) identityResponse;
        httpIdentityResponseBuilder.setBody(generateSuccessfulResponse(registrationResponse).toJSONString());
        httpIdentityResponseBuilder.setStatusCode(HttpServletResponse.SC_CREATED);
        httpIdentityResponseBuilder.addHeader(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL, OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE);
        httpIdentityResponseBuilder.addHeader(OAuthConstants.HTTP_RESP_HEADER_PRAGMA, OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE);
        httpIdentityResponseBuilder.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    } else {
        // This else part will not be reached from application logic.
        log.error("Can't create httpIdentityResponseBuilder. identityResponse is not an instance of " + "RegistrationResponse");
    }
}
Also used : RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)

Aggregations

RegistrationResponse (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)3 Iterator (java.util.Iterator)1 OMElement (org.apache.axiom.om.OMElement)1 OMException (org.apache.axiom.om.OMException)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)1 AxisFault (org.apache.axis2.AxisFault)1 Test (org.testng.annotations.Test)1 HumanTaskCoordinationException (org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException)1 HttpIdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse)1 OIDCRegistrationResponse (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponse)1 OIDCRegistrationResponseProfile (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponseProfile)1