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());
}
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());
}
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);
}
}
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));
}
}
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");
}
Aggregations