Search in sources :

Example 1 with ApplicationUpdateRequest

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;
}
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) ApplicationUpdateRequest(org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)

Example 2 with ApplicationUpdateRequest

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));
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)

Example 3 with ApplicationUpdateRequest

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;
}
Also used : ApplicationUpdateRequest(org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)

Example 4 with 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");
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) IdentityException(org.wso2.carbon.identity.base.IdentityException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ApplicationUpdateRequest

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);
}
Also used : Application(org.wso2.carbon.identity.oauth.dcr.bean.Application) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)3 IdentityException (org.wso2.carbon.identity.base.IdentityException)2 IdentityOAuthAdminException (org.wso2.carbon.identity.oauth.IdentityOAuthAdminException)2 ApplicationUpdateRequest (org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest)2 DCRDataHolder (org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder)2 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO)2 Application (org.wso2.carbon.identity.oauth.dcr.bean.Application)1