Search in sources :

Example 6 with ApplicationRegistrationRequest

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

the class DCRMServiceTest method registerApplicationTestWithDeleteCreatedSP.

@Test(dataProvider = "redirectUriProvider")
public void registerApplicationTestWithDeleteCreatedSP(List<String> redirectUri) throws Exception {
    mockStatic(IdentityProviderManager.class);
    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);
    whenNew(OAuthConsumerAppDTO.class).withNoArguments().thenReturn(oAuthConsumerApp);
    doThrow(new IdentityOAuthAdminException("")).when(mockOAuthAdminService).registerOAuthApplicationData(oAuthConsumerApp);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_APPLICATION.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) 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) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ApplicationRegistrationRequest

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

the class DCRMUtils method getApplicationRegistrationRequest.

public static ApplicationRegistrationRequest getApplicationRegistrationRequest(RegistrationRequestDTO registrationRequestDTO) {
    ApplicationRegistrationRequest appRegistrationRequest = new ApplicationRegistrationRequest();
    appRegistrationRequest.setClientName(registrationRequestDTO.getClientName());
    appRegistrationRequest.setRedirectUris(registrationRequestDTO.getRedirectUris());
    appRegistrationRequest.setGrantTypes(registrationRequestDTO.getGrantTypes());
    appRegistrationRequest.setTokenType(registrationRequestDTO.getTokenType());
    appRegistrationRequest.setConsumerKey(registrationRequestDTO.getClientId());
    appRegistrationRequest.setConsumerSecret(registrationRequestDTO.getClientSecret());
    appRegistrationRequest.setSpTemplateName(registrationRequestDTO.getSpTemplateName());
    appRegistrationRequest.setBackchannelLogoutUri(registrationRequestDTO.getBackchannelLogoutUri());
    return appRegistrationRequest;
}
Also used : ApplicationRegistrationRequest(org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest)

Example 8 with ApplicationRegistrationRequest

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

the class DCRMServiceTest method registerApplicationTestWithFailedToGetSP.

@Test
public void registerApplicationTestWithFailedToGetSP() throws DCRMException, IdentityApplicationManagementException {
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).getServiceProvider(dummyClientName, dummyTenantDomain);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_GET_SP.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with ApplicationRegistrationRequest

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

the class DCRMServiceTest method registerApplicationTestWithFailedToRegisterSP.

@Test
public void registerApplicationTestWithFailedToRegisterSP() throws Exception {
    dummyGrantTypes.add("dummy1");
    dummyGrantTypes.add("dummy2");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    startTenantFlow();
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_SP.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with ApplicationRegistrationRequest

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

the class DCRMServiceTest method registerApplicationTestWithErrorCreataingSPTenantTest.

@Test(dataProvider = "redirectUriProvider")
public void registerApplicationTestWithErrorCreataingSPTenantTest(List<String> redirectUri) throws Exception {
    mockApplicationManagementService = mock(ApplicationManagementService.class);
    Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
    startTenantFlow();
    dummyGrantTypes.add("implicit");
    applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
    ServiceProvider serviceProvider = new ServiceProvider();
    DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
    dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
    when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(null, serviceProvider);
    applicationRegistrationRequest.setRedirectUris(redirectUri);
    applicationRegistrationRequest.setSpTemplateName(dummyTemplateName);
    whenNew(ServiceProvider.class).withNoArguments().thenReturn(serviceProvider);
    when(mockApplicationManagementService.isExistingApplicationTemplate(dummyTemplateName, dummyTenantDomain)).thenReturn(true);
    doThrow(new IdentityApplicationManagementException("")).when(mockApplicationManagementService).createApplicationWithTemplate(serviceProvider, dummyTenantDomain, dummyUserName, dummyTemplateName);
    try {
        dcrmService.registerApplication(applicationRegistrationRequest);
    } catch (IdentityException ex) {
        assertEquals(ex.getErrorCode(), ErrorCodes.BAD_REQUEST.toString());
        return;
    }
    fail("Expected IdentityException was not thrown by registerApplication method");
}
Also used : DCRDataHolder(org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) 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)12 Test (org.testng.annotations.Test)12 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)11 DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)11 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)10 IdentityException (org.wso2.carbon.identity.base.IdentityException)10 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)9 Matchers.anyString (org.mockito.Matchers.anyString)7 IdentityOAuthAdminException (org.wso2.carbon.identity.oauth.IdentityOAuthAdminException)5 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 ArrayList (java.util.ArrayList)2 OAuthAdminService (org.wso2.carbon.identity.oauth.OAuthAdminService)2 OAuthServerConfiguration (org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration)2 Application (org.wso2.carbon.identity.oauth.dcr.bean.Application)2 ApplicationRegistrationRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest)2 BeforeMethod (org.testng.annotations.BeforeMethod)1 DCRMException (org.wso2.carbon.identity.oauth.dcr.exception.DCRMException)1 UserRealm (org.wso2.carbon.user.api.UserRealm)1 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)1