use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method updateApplication.
private OAuthConsumerAppDTO updateApplication() throws IdentityOAuthAdminException, IdentityApplicationManagementException {
startTenantFlow();
dummyGrantTypes.add("dummy1");
dummyGrantTypes.add("dummy2");
applicationUpdateRequest = new ApplicationUpdateRequest();
applicationUpdateRequest.setClientName(dummyClientName);
applicationUpdateRequest.setGrantTypes(dummyGrantTypes);
applicationUpdateRequest.setTokenType(dummyTokenType);
applicationUpdateRequest.setBackchannelLogoutUri(dummyBackchannelLogoutUri);
OAuthConsumerAppDTO dto = new OAuthConsumerAppDTO();
dto.setApplicationName(dummyClientName);
dto.setOauthConsumerSecret(dummyConsumerSecret);
dto.setOauthConsumerKey(dummyConsumerKey);
dto.setCallbackUrl(dummyCallbackUrl);
dto.setUsername(dummyUserName.concat("@").concat(dummyTenantDomain));
when(mockOAuthAdminService.getOAuthApplicationData(dummyConsumerKey)).thenReturn(dto);
Whitebox.setInternalState(dcrmService, "oAuthAdminService", mockOAuthAdminService);
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(dummyClientName);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
when(mockApplicationManagementService.getServiceProvider(dummyClientName, dummyTenantDomain)).thenReturn(serviceProvider);
return dto;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest 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));
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMUtils method getApplicationUpdateRequest.
public static ApplicationUpdateRequest getApplicationUpdateRequest(UpdateRequestDTO updateRequestDTO) {
ApplicationUpdateRequest applicationUpdateRequest = new ApplicationUpdateRequest();
applicationUpdateRequest.setClientName(updateRequestDTO.getClientName());
applicationUpdateRequest.setRedirectUris(updateRequestDTO.getRedirectUris());
applicationUpdateRequest.setGrantTypes(updateRequestDTO.getGrantTypes());
applicationUpdateRequest.setTokenType(updateRequestDTO.getTokenType());
applicationUpdateRequest.setBackchannelLogoutUri(updateRequestDTO.getBackchannelLogoutUri());
return applicationUpdateRequest;
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method updateApplicationTestWithIOAException.
@Test
public void updateApplicationTestWithIOAException() throws Exception {
dto = updateApplication();
doThrow(new IdentityOAuthAdminException("")).when(mockOAuthAdminService).updateConsumerApplication(dto);
try {
dcrmService.updateApplication(applicationUpdateRequest, dummyConsumerKey);
} catch (IdentityException ex) {
assertEquals(ex.getErrorCode(), DCRMConstants.ErrorMessages.FAILED_TO_UPDATE_APPLICATION.toString());
return;
}
fail("Expected IdentityException was not thrown by updateApplication method");
}
use of org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRMServiceTest method updateApplicationTest.
@Test(dataProvider = "redirectUriProvider")
public void updateApplicationTest(List<String> redirectUri1) throws Exception {
updateApplication();
applicationUpdateRequest.setRedirectUris(redirectUri1);
Application application = dcrmService.updateApplication(applicationUpdateRequest, dummyConsumerKey);
assertEquals(application.getClientId(), dummyConsumerKey);
assertEquals(application.getClientName(), dummyClientName);
assertEquals(application.getClientSecret(), dummyConsumerSecret);
}
Aggregations