Search in sources :

Example 51 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getServiceProviderByClientId.

/**
 * @param clientId
 * @param clientType
 * @param tenantDomain
 * @return
 * @throws IdentityApplicationManagementException
 */
@Override
public ServiceProvider getServiceProviderByClientId(String clientId, String clientType, String tenantDomain) throws IdentityApplicationManagementException {
    // invoking the listeners
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreGetServiceProviderByClientId(clientId, clientType, tenantDomain)) {
            return null;
        }
    }
    // client id can contain the @ to identify the tenant domain.
    if (clientId != null && clientId.contains("@")) {
        clientId = clientId.split("@")[0];
    }
    String serviceProviderName;
    ServiceProvider serviceProvider = null;
    serviceProviderName = getServiceProviderNameByClientId(clientId, clientType, tenantDomain);
    try {
        startTenantFlow(tenantDomain);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        serviceProvider = appDAO.getApplication(serviceProviderName, tenantDomain);
        if (serviceProvider != null) {
            // if "Authentication Type" is "Default" we must get the steps from the default SP
            AuthenticationStep[] authenticationSteps = serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps();
            if (authenticationSteps == null || authenticationSteps.length == 0) {
                ServiceProvider defaultSP = ApplicationManagementServiceComponent.getFileBasedSPs().get(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
                authenticationSteps = defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps();
                AuthenticationScriptConfig scriptConfig = defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationScriptConfig();
                serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(authenticationSteps);
                if (scriptConfig != null) {
                    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(scriptConfig);
                    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(ApplicationConstants.AUTH_TYPE_FLOW);
                }
            }
        }
    } finally {
        endTenantFlow();
    }
    if (serviceProvider == null && serviceProviderName != null && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
        serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
    }
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostGetServiceProviderByClientId(serviceProvider, clientId, clientType, tenantDomain)) {
            return null;
        }
    }
    return serviceProvider;
}
Also used : AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 52 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method setDefaultAuthenticationSeq.

private void setDefaultAuthenticationSeq(String sequenceName, String tenantDomain, ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
    // if "Authentication Type" is "Default", get the tenant wise default authentication sequence if
    // available, otherwise the authentication sequence and adaptive script configuration in default SP
    DefaultAuthSeqMgtService seqMgtService = DefaultAuthSeqMgtServiceImpl.getInstance();
    DefaultAuthenticationSequence sequence;
    try {
        sequence = seqMgtService.getDefaultAuthenticationSeq(sequenceName, tenantDomain);
    } catch (DefaultAuthSeqMgtException e) {
        throw new IdentityApplicationManagementException("Error when retrieving default " + "authentication sequence in tenant: " + tenantDomain, e);
    }
    if (sequence != null && sequence.getContent() != null) {
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(sequence.getContent().getAuthenticationSteps());
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(sequence.getContent().getAuthenticationScriptConfig());
    } else {
        ServiceProvider defaultSP = ApplicationManagementServiceComponent.getFileBasedSPs().get(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps());
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationScriptConfig());
    }
}
Also used : DefaultAuthenticationSequence(org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence) DefaultAuthSeqMgtService(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtService) DefaultAuthSeqMgtException(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 53 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationManagementAdminService method createApplicationTemplateFromSP.

/**
 * Add configured service provider as a template.
 *
 * @param serviceProvider Service provider to be configured as a template
 * @param spTemplate      service provider template basic info
 * @throws IdentityApplicationManagementClientException
 */
public void createApplicationTemplateFromSP(ServiceProvider serviceProvider, SpTemplate spTemplate) throws IdentityApplicationManagementClientException {
    try {
        applicationMgtService = ApplicationManagementService.getInstance();
        applicationMgtService.createApplicationTemplateFromSP(serviceProvider, spTemplate, getTenantDomain());
    } catch (IdentityApplicationManagementClientException e) {
        throw e;
    } catch (IdentityApplicationManagementException e) {
        log.error(String.format("Error while creating service provider template for the configured SP: %s for " + "tenant: %s.", serviceProvider.getApplicationName(), getTenantDomain()), e);
        throw new IdentityApplicationManagementClientException(new String[] { "Server error occurred." });
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)

Example 54 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method importSPApplication.

public ImportResponse importSPApplication(SpFileContent spFileContent, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Importing service provider from file " + spFileContent.getFileName());
    }
    ServiceProvider serviceProvider = unmarshalSP(spFileContent, tenantDomain);
    ImportResponse importResponse = importSPApplication(serviceProvider, tenantDomain, username, isUpdate);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Service provider %s@%s created successfully from file %s", serviceProvider.getApplicationName(), tenantDomain, spFileContent.getFileName()));
    }
    return importResponse;
}
Also used : ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 55 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class DirectoryServerApplicationMgtListener method doPreDeleteApplication.

@Override
public boolean doPreDeleteApplication(String applicationName, String tenantDomain, String userName) throws IdentityApplicationManagementException {
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    ServiceProvider serviceProvider = appDAO.getApplication(applicationName, tenantDomain);
    if (serviceProvider != null && serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
        InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs();
        for (InboundAuthenticationRequestConfig config : configs) {
            if (KERBEROS.equalsIgnoreCase(config.getInboundAuthType()) && config.getInboundAuthKey() != null) {
                DirectoryServerManager directoryServerManager = new DirectoryServerManager();
                try {
                    directoryServerManager.removeServer(config.getInboundAuthKey());
                } catch (DirectoryServerManagerException e) {
                    String error = "Error while removing a kerberos: " + config.getInboundAuthKey();
                    throw new IdentityApplicationManagementException(error, e);
                }
                break;
            }
        }
    }
    return true;
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19