Search in sources :

Example 1 with DCRMService

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

the class RegisterApiServiceImplTest method testUpdateApplication.

@Test
public void testUpdateApplication() throws Exception {
    UpdateRequestDTO updateRequestDTO1 = new UpdateRequestDTO();
    updateRequestDTO1.setClientName("Client1");
    String clientID = "clientID1";
    DCRMUtils.setOAuth2DCRMService(dcrmService);
    when(dcrmService.updateApplication(DCRMUtils.getApplicationUpdateRequest(updateRequestDTO1), clientID)).thenReturn(application);
    Assert.assertEquals(registerApiService.updateApplication(updateRequestDTO1, clientID).getStatus(), Response.Status.OK.getStatusCode());
}
Also used : UpdateRequestDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with DCRMService

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

the class RegisterApiServiceImplTest method testRegisterApplication.

@Test
public void testRegisterApplication() throws Exception {
    RegistrationRequestDTO registrationRequestDTO = new RegistrationRequestDTO();
    registrationRequestDTO.setClientName("app1");
    DCRMUtils.setOAuth2DCRMService(dcrmService);
    when(dcrmService.registerApplication(DCRMUtils.getApplicationRegistrationRequest(registrationRequestDTO))).thenReturn(application);
    Assert.assertEquals(registerApiService.registerApplication(registrationRequestDTO).getStatus(), Response.Status.CREATED.getStatusCode());
}
Also used : RegistrationRequestDTO(org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.RegistrationRequestDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with DCRMService

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

the class DCRServiceComponent method activate.

@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
    try {
        componentContext.getBundleContext().registerService(IdentityProcessor.class.getName(), new DCRProcessor(), null);
        componentContext.getBundleContext().registerService(HttpIdentityRequestFactory.class.getName(), new RegistrationRequestFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityResponseFactory.class.getName(), new HttpRegistrationResponseFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityRequestFactory.class.getName(), new UnregistrationRequestFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityResponseFactory.class.getName(), new HttpUnregistrationResponseFactory(), null);
        componentContext.getBundleContext().registerService(RegistrationHandler.class.getName(), new RegistrationHandler(), null);
        componentContext.getBundleContext().registerService(UnRegistrationHandler.class.getName(), new UnRegistrationHandler(), null);
        componentContext.getBundleContext().registerService(DCRMService.class.getName(), new DCRMService(), null);
    } catch (Throwable e) {
        log.error("Error occurred while activating DCRServiceComponent", e);
    }
}
Also used : DCRMService(org.wso2.carbon.identity.oauth.dcr.service.DCRMService) HttpUnregistrationResponseFactory(org.wso2.carbon.identity.oauth.dcr.factory.HttpUnregistrationResponseFactory) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) UnregistrationRequestFactory(org.wso2.carbon.identity.oauth.dcr.factory.UnregistrationRequestFactory) RegistrationRequestFactory(org.wso2.carbon.identity.oauth.dcr.factory.RegistrationRequestFactory) HttpRegistrationResponseFactory(org.wso2.carbon.identity.oauth.dcr.factory.HttpRegistrationResponseFactory) IdentityProcessor(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityProcessor) RegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) DCRProcessor(org.wso2.carbon.identity.oauth.dcr.processor.DCRProcessor) HttpIdentityResponseFactory(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponseFactory) HttpIdentityRequestFactory(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory)

Example 4 with DCRMService

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

the class DCRMServiceTest method registerApplicationTestWithRedirectURls.

@Test(dataProvider = "redirectUriWithQueryParamsProvider")
public void registerApplicationTestWithRedirectURls(List<String> redirectUri, List<String> validCallbackList, List<String> invalidCallbackList) throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    String grantType = StringUtils.join(applicationRegistrationRequest.getGrantTypes(), " ");
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    OAuthConsumerAppDTO oAuthConsumerApp = new OAuthConsumerAppDTO();
    oAuthConsumerApp.setApplicationName(dummyClientName);
    oAuthConsumerApp.setGrantTypes(grantType);
    oAuthConsumerApp.setOAuthVersion(OAUTH_VERSION);
    oAuthConsumerApp.setCallbackUrl(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX + dcrmService.createRegexPattern(redirectUri));
    when(mockOAuthAdminService.getOAuthApplicationDataByAppName(dummyClientName)).thenReturn(oAuthConsumerApp);
    when(mockOAuthAdminService.registerAndRetrieveOAuthApplicationData(any(OAuthConsumerAppDTO.class))).thenReturn(oAuthConsumerApp);
    Application application = dcrmService.registerApplication(applicationRegistrationRequest);
    assertEquals(application.getClientName(), dummyClientName);
    String regexp = application.getRedirectUris().get(0).substring(OAuthConstants.CALLBACK_URL_REGEXP_PREFIX.length());
    for (String validCallback : validCallbackList) {
        assertTrue(validCallback.matches(regexp));
    }
    for (String invalidCallback : invalidCallbackList) {
        assertFalse(invalidCallback.matches(regexp));
    }
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) Application(org.wso2.carbon.identity.oauth.dcr.bean.Application) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with DCRMService

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

the class DCRMServiceTest method isClientIdExistTestWithIdentityOAuthAdminException.

@Test
public void isClientIdExistTestWithIdentityOAuthAdminException() throws Exception {
    registerApplicationTestWithFailedToUpdateSP();
    List<String> redirectUri = new ArrayList<>();
    redirectUri.add("redirectUri1");
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    applicationRegistrationRequest.setConsumerKey(dummyConsumerKey);
    OAuthAdminService mockOAuthAdminService = mock(OAuthAdminService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    whenNew(OAuthAdminService.class).withNoArguments().thenReturn(mockOAuthAdminService);
    IdentityOAuthAdminException identityOAuthAdminException = mock(IdentityOAuthAdminException.class);
    doThrow(identityOAuthAdminException).when(mockOAuthAdminService).getOAuthApplicationData(dummyConsumerKey);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_GET_APPLICATION_BY_ID.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) OAuthAdminService(org.wso2.carbon.identity.oauth.OAuthAdminService) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 Test (org.testng.annotations.Test)18 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)13 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)12 IdentityException (org.wso2.carbon.identity.base.IdentityException)11 Matchers.anyString (org.mockito.Matchers.anyString)10 DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)10 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)9 IdentityOAuthAdminException (org.wso2.carbon.identity.oauth.IdentityOAuthAdminException)6 Application (org.wso2.carbon.identity.oauth.dcr.bean.Application)5 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 ArrayList (java.util.ArrayList)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 OAuthAdminService (org.wso2.carbon.identity.oauth.OAuthAdminService)2 InvalidOAuthClientException (org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)2 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)2 ApplicationUpdateRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)2 UpdateRequestDTO (org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO)2 HttpIdentityRequestFactory (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory)1 HttpIdentityResponseFactory (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponseFactory)1