use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method registerApplicationTestWithExistSP.
@Test
public void registerApplicationTestWithExistSP() throws DCRMException, IdentityApplicationManagementException {
dummyGrantTypes.add("dummy1");
dummyGrantTypes.add("dummy2");
applicationRegistrationRequest.setGrantTypes(dummyGrantTypes);
startTenantFlow();
mockApplicationManagementService = mock(ApplicationManagementService.class);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(new ServiceProvider());
try {
dcrmService.registerApplication(applicationRegistrationRequest);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.CONFLICT_EXISTING_APPLICATION.toString());
return;
}
fail("Expected IdentityException was not thrown by registerApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method validateRequestTenantDomainTestWitInvalidOAuthClientException.
@Test
public void validateRequestTenantDomainTestWitInvalidOAuthClientException() throws IdentityOAuth2Exception, InvalidOAuthClientException {
when(OAuth2Util.getTenantDomainOfOauthApp(dummyConsumerKey)).thenThrow(new InvalidOAuthClientException(""));
try {
dcrmService.getApplication(dummyConsumerKey);
} catch (DCRMException ex) {
assertEquals(ex.getMessage(), String.format(DCRMConstants.ErrorMessages.TENANT_DOMAIN_MISMATCH.getMessage(), dummyConsumerKey));
return;
}
fail("Expected IdentityException was not thrown by getApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method validateRequestTenantDomainTestWitIdentityOAuth2Exception.
@Test
public void validateRequestTenantDomainTestWitIdentityOAuth2Exception() throws IdentityOAuth2Exception, InvalidOAuthClientException {
when(OAuth2Util.getTenantDomainOfOauthApp(dummyConsumerKey)).thenThrow(new IdentityOAuth2Exception(""));
try {
dcrmService.getApplication(dummyConsumerKey);
} catch (DCRMException ex) {
assertEquals(ex.getMessage(), String.format(DCRMConstants.ErrorMessages.FAILED_TO_VALIDATE_TENANT_DOMAIN.getMessage(), dummyConsumerKey));
return;
}
fail("Expected DCRMException was not thrown by getApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMService method createServiceProvider.
private ServiceProvider createServiceProvider(String applicationOwner, String tenantDomain, String spName, String templateName) throws DCRMException {
// Create the Service Provider
ServiceProvider sp = new ServiceProvider();
sp.setApplicationName(spName);
User user = new User();
user.setUserName(applicationOwner);
user.setTenantDomain(tenantDomain);
sp.setOwner(user);
sp.setDescription("Service Provider for application " + spName);
createServiceProvider(sp, tenantDomain, applicationOwner, templateName);
// Get created service provider.
ServiceProvider clientSP = getServiceProvider(spName, tenantDomain);
if (clientSP == null) {
throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.FAILED_TO_REGISTER_SP, spName);
}
return clientSP;
}
use of org.wso2.carbon.identity.oauth.dcr.exception.DCRMException in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMService method updateApplication.
/**
* Update OAuth/OIDC application.
*
* @param updateRequest
* @param clientId
* @return
* @throws DCRMException
*/
public Application updateApplication(ApplicationUpdateRequest updateRequest, String clientId) throws DCRMException {
validateRequestTenantDomain(clientId);
OAuthConsumerAppDTO appDTO = getApplicationById(clientId);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String applicationOwner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String clientName = updateRequest.getClientName();
// Update Service Provider
ServiceProvider sp = getServiceProvider(appDTO.getApplicationName(), tenantDomain);
if (StringUtils.isNotEmpty(clientName)) {
// to register the OAuth app with.
if (!appDTO.getApplicationName().equals(clientName) && isServiceProviderExist(clientName, tenantDomain)) {
throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.CONFLICT_EXISTING_APPLICATION, clientName);
}
// Regex validation of the application name.
if (!DCRMUtils.isRegexValidated(clientName)) {
throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.BAD_REQUEST_INVALID_SP_NAME, DCRMUtils.getSPValidatorRegex(), null);
}
if (sp == null) {
throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.FAILED_TO_GET_SP, appDTO.getApplicationName(), null);
}
// Need to create a deep clone, since modifying the fields of the original object,
// will modify the cached SP object.
ServiceProvider clonedSP = cloneServiceProvider(sp);
clonedSP.setApplicationName(clientName);
updateServiceProvider(clonedSP, tenantDomain, applicationOwner);
}
// Update application
try {
if (StringUtils.isNotEmpty(clientName)) {
// Regex validation of the application name.
if (!DCRMUtils.isRegexValidated(clientName)) {
throw DCRMUtils.generateClientException(DCRMConstants.ErrorMessages.BAD_REQUEST_INVALID_SP_NAME, DCRMUtils.getSPValidatorRegex(), null);
}
appDTO.setApplicationName(clientName);
}
if (!updateRequest.getGrantTypes().isEmpty()) {
String grantType = StringUtils.join(updateRequest.getGrantTypes(), GRANT_TYPE_SEPARATOR);
appDTO.setGrantTypes(grantType);
}
if (!updateRequest.getRedirectUris().isEmpty()) {
String callbackUrl = validateAndSetCallbackURIs(updateRequest.getRedirectUris(), updateRequest.getGrantTypes());
appDTO.setCallbackUrl(callbackUrl);
}
if (updateRequest.getTokenType() != null) {
appDTO.setTokenType(updateRequest.getTokenType());
}
if (StringUtils.isNotEmpty(updateRequest.getBackchannelLogoutUri())) {
String backChannelLogoutUri = validateBackchannelLogoutURI(updateRequest.getBackchannelLogoutUri());
appDTO.setBackChannelLogoutUrl(backChannelLogoutUri);
}
oAuthAdminService.updateConsumerApplication(appDTO);
} catch (IdentityOAuthAdminException e) {
throw DCRMUtils.generateServerException(DCRMConstants.ErrorMessages.FAILED_TO_UPDATE_APPLICATION, clientId, e);
}
return buildResponse(getApplicationById(clientId));
}
Aggregations