Search in sources :

Example 1 with RegistrationResponseProfile

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

the class RegistrationHandler method handle.

@Override
public IdentityResponse.IdentityResponseBuilder handle(DCRMessageContext dcrMessageContext) throws DCRException {
    if (log.isDebugEnabled()) {
        log.debug("Request processing started by RegistrationRequestProcessor.");
    }
    RegistrationResponse.DCRRegisterResponseBuilder dcrRegisterResponseBuilder = null;
    RegistrationRequest registerRequest = (RegistrationRequest) dcrMessageContext.getIdentityRequest();
    RegistrationRequestProfile registrationRequestProfile = registerRequest.getRegistrationRequestProfile();
    registrationRequestProfile.setTenantDomain(registerRequest.getTenantDomain());
    RegistrationResponseProfile registrationResponseProfile = DCRManagementService.getInstance().registerOAuthApplication(registrationRequestProfile);
    dcrRegisterResponseBuilder = new RegistrationResponse.DCRRegisterResponseBuilder();
    dcrRegisterResponseBuilder.setRegistrationResponseProfile(registrationResponseProfile);
    return dcrRegisterResponseBuilder;
}
Also used : RegistrationRequestProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)

Example 2 with RegistrationResponseProfile

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

the class HttpRegistrationResponseFactoryTest method testGenerateSuccessfulResponse.

@Test
public void testGenerateSuccessfulResponse() throws Exception {
    grantType.add("dummyGrantType");
    redirectUrl.add("dummyRedirectUrl");
    RegistrationResponseProfile registrationRequestProfile = mock(RegistrationResponseProfile.class);
    when(mockRegistrationResponse.getRegistrationResponseProfile()).thenReturn(registrationRequestProfile);
    String dummyClientId = "dummyClientId";
    when(registrationRequestProfile.getClientId()).thenReturn(dummyClientId);
    String dummyClientName = "dummyClientName";
    when(registrationRequestProfile.getClientName()).thenReturn(dummyClientName);
    when(registrationRequestProfile.getGrantTypes()).thenReturn(grantType);
    when(registrationRequestProfile.getRedirectUrls()).thenReturn(redirectUrl);
    String dummySecret = "dummySecret";
    when(registrationRequestProfile.getClientSecret()).thenReturn(dummySecret);
    String dummyTime = "dummyTime";
    when(registrationRequestProfile.getClientSecretExpiresAt()).thenReturn(dummyTime);
    JSONObject jsonObject = httpRegistrationResponseFactory.generateSuccessfulResponse(mockRegistrationResponse);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_ID), dummyClientId);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_NAME), dummyClientName);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_SECRET_EXPIRES_AT), dummyTime);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_SECRET), dummySecret);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.GRANT_TYPES), grantType);
    assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.REDIRECT_URIS), redirectUrl);
}
Also used : JSONObject(org.json.simple.JSONObject) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with RegistrationResponseProfile

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

the class HttpRegistrationResponseFactoryTest method testCreate.

@Test(dataProvider = "instanceDataProvider")
public void testCreate(Object builder) throws Exception {
    if (builder == null) {
        mockHttpIdentityResponseBuilder = mock(HttpIdentityResponse.HttpIdentityResponseBuilder.class);
    } else {
        mockHttpIdentityResponseBuilder = (HttpIdentityResponse.HttpIdentityResponseBuilder) builder;
    }
    RegistrationResponseProfile registrationRequestProfile = mock(RegistrationResponseProfile.class);
    whenNew(HttpIdentityResponse.HttpIdentityResponseBuilder.class).withNoArguments().thenReturn(mockHttpIdentityResponseBuilder);
    when((mockRegistrationResponse).getRegistrationResponseProfile()).thenReturn(registrationRequestProfile);
    final Integer[] statusCode = new Integer[1];
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            statusCode[0] = (Integer) invocation.getArguments()[0];
            return null;
        }
    }).when(mockHttpIdentityResponseBuilder).setStatusCode(anyInt());
    final String[] header = new String[1];
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            header[0] = (String) invocation.getArguments()[1];
            return null;
        }
    }).when(mockHttpIdentityResponseBuilder).addHeader(anyString(), anyString());
    if (builder == null) {
        httpRegistrationResponseFactory.create(mockRegistrationResponse);
    } else {
        httpRegistrationResponseFactory.create((HttpIdentityResponse.HttpIdentityResponseBuilder) builder, (mockRegistrationResponse));
    }
    assertEquals((int) statusCode[0], HttpServletResponse.SC_CREATED);
    assertEquals(header[0], MediaType.APPLICATION_JSON);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) JSONObject(org.json.simple.JSONObject) HttpIdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with RegistrationResponseProfile

use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile 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 5 with RegistrationResponseProfile

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

the class OIDCRegistrationHandler method handle.

@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public IdentityResponse.IdentityResponseBuilder handle(DCRMessageContext dcrMessageContext) throws DCRException {
    if (log.isDebugEnabled()) {
        log.debug("Request processing started by RegistrationRequestProcessor.");
    }
    RegistrationResponse.DCRRegisterResponseBuilder dcrRegisterResponseBuilder;
    RegistrationRequest registerRequest;
    if (dcrMessageContext.getIdentityRequest() instanceof RegistrationRequest) {
        registerRequest = (RegistrationRequest) dcrMessageContext.getIdentityRequest();
    } else {
        throw new DCRException("Error while retrieving the registration request.");
    }
    RegistrationRequestProfile registrationRequestProfile = registerRequest.getRegistrationRequestProfile();
    registrationRequestProfile.setTenantDomain(registerRequest.getTenantDomain());
    RegistrationResponseProfile registrationResponseProfile = DCRManagementService.getInstance().registerOAuthApplication(registrationRequestProfile);
    dcrRegisterResponseBuilder = new RegistrationResponse.DCRRegisterResponseBuilder();
    dcrRegisterResponseBuilder.setRegistrationResponseProfile(registrationResponseProfile);
    return dcrRegisterResponseBuilder;
}
Also used : RegistrationRequestProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest) DCRException(org.wso2.carbon.identity.oauth.dcr.DCRException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

RegistrationResponseProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile)7 Test (org.testng.annotations.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 DCRException (org.wso2.carbon.identity.oauth.dcr.DCRException)3 RegistrationResponse (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)3 JSONObject (org.json.simple.JSONObject)2 Matchers.anyString (org.mockito.Matchers.anyString)2 HttpIdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponse)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)2 OAuthAdminService (org.wso2.carbon.identity.oauth.OAuthAdminService)2 RegistrationRequest (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)2 RegistrationRequestProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile)2 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 BeforeTest (org.testng.annotations.BeforeTest)1 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)1 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig)1