Search in sources :

Example 1 with UpdateServiceProvider

use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider 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 2 with UpdateServiceProvider

use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider in project product-is by wso2.

the class OIDCFederatedIdpInitLogoutTest method createServiceProviderInSecondaryIS.

private void createServiceProviderInSecondaryIS() throws Exception {
    super.addServiceProvider(PORT_OFFSET_1, FEDERATED_IS_SP_NAME);
    ServiceProvider serviceProvider = getServiceProvider(PORT_OFFSET_1, FEDERATED_IS_SP_NAME);
    Assert.assertNotNull(serviceProvider, "Failed to create service provider 'travelocity' in primary IS");
    updateServiceProviderWithSAMLConfigs(PORT_OFFSET_1, FEDERATED_IS_SAML_ISSUER_NAME, FEDERATED_IS_SAML_ACS_URL, serviceProvider);
    updateServiceProvider(PORT_OFFSET_1, serviceProvider);
    serviceProvider = getServiceProvider(PORT_OFFSET_1, FEDERATED_IS_SP_NAME);
    InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
    boolean success = false;
    if (configs != null) {
        for (InboundAuthenticationRequestConfig config : configs) {
            if (FEDERATED_IS_SP_INBOUND_AUTH_TYPE_SAMLSSO.equals(config.getInboundAuthType())) {
                success = true;
                break;
            }
        }
    }
    Assert.assertTrue(success, "Failed to update service provider with inbound SAML2 configs in primary IS");
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)

Example 3 with UpdateServiceProvider

use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider in project product-is by wso2.

the class OIDCIdentityFederationTestCase method createServiceProviderInPrimaryIS.

private void createServiceProviderInPrimaryIS() throws Exception {
    super.addServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SP_NAME);
    ServiceProvider serviceProvider = getServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SP_NAME);
    Assert.assertNotNull(serviceProvider, "Failed to create service provider 'travelocity' in primary IS");
    updateServiceProviderWithSAMLConfigs(PORT_OFFSET_0, PRIMARY_IS_SAML_ISSUER_NAME, PRIMARY_IS_SAML_ACS_URL, serviceProvider);
    AuthenticationStep authStep = new AuthenticationStep();
    org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider idP = new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider();
    idP.setIdentityProviderName(PRIMARY_IS_IDP_NAME);
    org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig oidcAuthnConfig = new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig();
    oidcAuthnConfig.setName(PRIMARY_IS_IDP_AUTHENTICATOR_NAME_OIDC);
    oidcAuthnConfig.setDisplayName("openidconnect");
    idP.setFederatedAuthenticatorConfigs(new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig[] { oidcAuthnConfig });
    authStep.setFederatedIdentityProviders(new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider[] { idP });
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(PRIMARY_IS_SP_AUTHENTICATION_TYPE);
    updateServiceProvider(PORT_OFFSET_0, serviceProvider);
    serviceProvider = getServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SP_NAME);
    InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
    boolean success = false;
    if (configs != null) {
        for (InboundAuthenticationRequestConfig config : configs) {
            if (PRIMARY_IS_SP_INBOUND_AUTH_TYPE_SAMLSSO.equals(config.getInboundAuthType())) {
                success = true;
                break;
            }
        }
    }
    Assert.assertTrue(success, "Failed to update service provider with inbound SAML2 configs in primary IS");
    Assert.assertTrue(PRIMARY_IS_SP_AUTHENTICATION_TYPE.equals(serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationType()), "Failed to update local and out bound configs in primary IS");
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)

Example 4 with UpdateServiceProvider

use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider in project product-is by wso2.

the class ChangeACSUrlTestCase method initTest.

@BeforeClass(alwaysRun = true)
public void initTest() throws Exception {
    super.initTest();
    String carbonHome = Utils.getResidentCarbonHome();
    File defaultTomlFile = getDeploymentTomlFile(carbonHome);
    File configuredTomlFile = new File(getISResourceLocation() + File.separator + "saml" + File.separator + "application_authentication_changed_acs.toml");
    serverConfigurationManager = new ServerConfigurationManager(isServer);
    serverConfigurationManager.applyConfigurationWithoutRestart(configuredTomlFile, defaultTomlFile, true);
    serverConfigurationManager.restartGracefully();
    super.initTest();
    super.createServiceClients(PORT_OFFSET_0, sessionCookie, new IdentityConstants.ServiceClientType[] { IdentityConstants.ServiceClientType.APPLICATION_MANAGEMENT, IdentityConstants.ServiceClientType.IDENTITY_PROVIDER_MGT, IdentityConstants.ServiceClientType.SAML_SSO_CONFIG });
    super.createServiceClients(PORT_OFFSET_1, null, new IdentityConstants.ServiceClientType[] { IdentityConstants.ServiceClientType.APPLICATION_MANAGEMENT, IdentityConstants.ServiceClientType.SAML_SSO_CONFIG });
    // create identity provider in primary IS
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setIdentityProviderName(IDENTITY_PROVIDER_NAME);
    FederatedAuthenticatorConfig saml2SSOAuthnConfig = new FederatedAuthenticatorConfig();
    saml2SSOAuthnConfig.setName("SAMLSSOAuthenticator");
    saml2SSOAuthnConfig.setDisplayName("samlsso");
    saml2SSOAuthnConfig.setEnabled(true);
    saml2SSOAuthnConfig.setProperties(getSAML2SSOAuthnConfigProperties());
    identityProvider.setDefaultAuthenticatorConfig(saml2SSOAuthnConfig);
    identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { saml2SSOAuthnConfig });
    super.addIdentityProvider(PORT_OFFSET_0, identityProvider);
    // create service provider in primary IS
    super.addServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SERVICE_PROVIDER_NAME);
    ServiceProvider serviceProvider = getServiceProvider(PORT_OFFSET_0, PRIMARY_IS_SERVICE_PROVIDER_NAME);
    updateServiceProviderWithSAMLConfigs(PORT_OFFSET_0, PRIMARY_IS_SAML_ISSUER_NAME, PRIMARY_IS_SAML_ACS_URL, serviceProvider);
    AuthenticationStep authStep = new AuthenticationStep();
    org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider idP = new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider();
    idP.setIdentityProviderName(IDENTITY_PROVIDER_NAME);
    org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig saml2SSOAuthnConfigXsd = new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig();
    saml2SSOAuthnConfigXsd.setName("SAMLSSOAuthenticator");
    saml2SSOAuthnConfigXsd.setDisplayName("samlsso");
    idP.setFederatedAuthenticatorConfigs(new org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig[] { saml2SSOAuthnConfigXsd });
    authStep.setFederatedIdentityProviders(new org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider[] { idP });
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(AUTHENTICATION_TYPE);
    updateServiceProvider(PORT_OFFSET_0, serviceProvider);
    // create service provider in secondary IS
    super.addServiceProvider(PORT_OFFSET_1, SECONDARY_IS_SERVICE_PROVIDER_NAME);
    serviceProvider = getServiceProvider(PORT_OFFSET_1, SECONDARY_IS_SERVICE_PROVIDER_NAME);
    updateServiceProviderWithSAMLConfigs(PORT_OFFSET_1, SECONDARY_IS_SAML_ISSUER_NAME, String.format(COMMON_AUTH_URL_CHANGED, DEFAULT_PORT + PORT_OFFSET_0), serviceProvider);
    updateServiceProvider(PORT_OFFSET_1, serviceProvider);
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) ServerConfigurationManager(org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) IdentityConstants(org.wso2.identity.integration.test.utils.IdentityConstants) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with UpdateServiceProvider

use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider in project product-is by wso2.

the class SAMLFederationWithFileBasedSPAndIDPTestCase method testCreateServiceProviderInSecondaryIS.

@Test(groups = "wso2.is", description = "Check create service provider in secondary IS")
public void testCreateServiceProviderInSecondaryIS() throws Exception {
    super.addServiceProvider(PORT_OFFSET_1, SECONDARY_IS_SERVICE_PROVIDER_NAME);
    ServiceProvider serviceProvider = getServiceProvider(PORT_OFFSET_1, SECONDARY_IS_SERVICE_PROVIDER_NAME);
    Assert.assertNotNull(serviceProvider, "Failed to create service provider 'secondarySP' in secondary IS");
    // Set SAML configurations
    updateServiceProviderWithSAMLConfigs(PORT_OFFSET_1, SECONDARY_IS_SAML_ISSUER_NAME, String.format(COMMON_AUTH_URL, DEFAULT_PORT + PORT_OFFSET_0), serviceProvider);
    // Set claim configurations
    serviceProvider.getClaimConfig().setLocalClaimDialect(false);
    serviceProvider.getClaimConfig().setClaimMappings(getClaimMappingsForSPInSecondaryIS());
    updateServiceProvider(PORT_OFFSET_1, serviceProvider);
    serviceProvider = getServiceProvider(PORT_OFFSET_1, SECONDARY_IS_SERVICE_PROVIDER_NAME);
    InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
    boolean success = false;
    if (configs != null) {
        for (InboundAuthenticationRequestConfig config : configs) {
            if (SECONDARY_IS_SAML_ISSUER_NAME.equals(config.getInboundAuthKey()) && INBOUND_AUTH_TYPE.equals(config.getInboundAuthType())) {
                success = true;
                break;
            }
        }
    }
    Assert.assertTrue(success, "Failed to update service provider with inbound SAML2 configs in secondary IS");
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig) Test(org.testng.annotations.Test)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)12 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)10 Test (org.testng.annotations.Test)8 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)6 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)6 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)6 SAML2ServiceProvider (org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider)5 ApiModelToServiceProvider (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApiModelToServiceProvider)5 UpdateServiceProvider (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider)5 AuthenticationStep (org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep)5 ArrayList (java.util.ArrayList)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3 InboundFunctions.getInboundAuthenticationRequestConfig (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.getInboundAuthenticationRequestConfig)2 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1