Search in sources :

Example 1 with IdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpUnRegistrationResponseFactoryTest method testCanHandle.

@Test
public void testCanHandle() throws Exception {
    IdentityResponse identityResponse = mock(IdentityResponse.class);
    assertFalse(httpUnregistrationResponseFactory.canHandle(identityResponse));
}
Also used : IdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with IdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse in project identity-inbound-auth-oauth by wso2-extensions.

the class HttpRegistrationResponseFactoryTest method testCanHandle.

@Test
public void testCanHandle() throws Exception {
    IdentityResponse identityResponse = mock(IdentityResponse.class);
    assertFalse(httpRegistrationResponseFactory.canHandle(identityResponse));
}
Also used : IdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with IdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse 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 4 with IdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse 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 5 with IdentityResponse

use of org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse 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

Test (org.testng.annotations.Test)3 HttpIdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse)3 RegistrationResponse (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse)2 OIDCRegistrationResponse (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponse)1 OIDCRegistrationResponseProfile (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationResponseProfile)1