Search in sources :

Example 1 with IdentityApplicationManagementClientException

use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method importApplication.

private ImportResponse importApplication(ServiceProvider serviceProvider, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    ServiceProvider savedSP = null;
    String appName = serviceProvider.getApplicationName();
    try {
        if (isUpdate) {
            savedSP = getApplicationExcludingFileBasedSPs(appName, tenantDomain);
            if (savedSP == null) {
                String errorMsg = String.format("Service provider %s@%s is not found", appName, tenantDomain);
                throw new IdentityApplicationManagementClientException(APPLICATION_NOT_FOUND.getCode(), errorMsg);
            }
        }
        if (!isUpdate) {
            ServiceProvider basicApplication = new ServiceProvider();
            basicApplication.setApplicationName(serviceProvider.getApplicationName());
            basicApplication.setDescription(serviceProvider.getDescription());
            String resourceId = createApplication(basicApplication, tenantDomain, username);
            savedSP = getApplicationByResourceId(resourceId, tenantDomain);
        }
        serviceProvider.setApplicationResourceId(savedSP.getApplicationResourceId());
        serviceProvider.setApplicationID(savedSP.getApplicationID());
        serviceProvider.setOwner(getUser(tenantDomain, username));
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.onPreCreateInbound(serviceProvider, isUpdate);
            }
        }
        updateApplication(serviceProvider, tenantDomain, username);
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.doImportServiceProvider(serviceProvider);
            }
        }
        ImportResponse importResponse = new ImportResponse();
        if (isUpdate) {
            importResponse.setResponseCode(ImportResponse.UPDATED);
        } else {
            importResponse.setResponseCode(ImportResponse.CREATED);
        }
        importResponse.setApplicationName(appName);
        importResponse.setApplicationResourceId(serviceProvider.getApplicationResourceId());
        importResponse.setErrors(new String[0]);
        return importResponse;
    } catch (IdentityApplicationManagementClientException e) {
        deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
        return buildImportErrorResponse(e);
    } catch (IdentityApplicationManagementException e) {
        deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
        String errorMsg = String.format("Error in importing provided service provider %s@%s from file ", appName, tenantDomain);
        throw new IdentityApplicationManagementException(errorMsg, e);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)

Example 2 with IdentityApplicationManagementClientException

use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getApplicationTemplate.

@Override
public SpTemplate getApplicationTemplate(String templateName, String tenantDomain) throws IdentityApplicationManagementException {
    String retrievedTemplateName = templateName;
    if (StringUtils.isBlank(retrievedTemplateName)) {
        retrievedTemplateName = ApplicationConstants.TENANT_DEFAULT_SP_TEMPLATE_NAME;
    }
    SpTemplate spTemplate = doGetApplicationTemplate(retrievedTemplateName, tenantDomain);
    if (spTemplate == null) {
        if (StringUtils.isBlank(templateName)) {
            return null;
        } else {
            throw new IdentityApplicationManagementClientException(new String[] { String.format("Template with name: %s is not " + "registered for tenant: %s.", templateName, tenantDomain) });
        }
    }
    return spTemplate;
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SpTemplate(org.wso2.carbon.identity.application.common.model.SpTemplate)

Example 3 with IdentityApplicationManagementClientException

use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method updateApplicationTemplate.

@Override
public void updateApplicationTemplate(String oldTemplateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        validateSPTemplateExists(oldTemplateName, spTemplate, tenantDomain);
        ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
        validateUnsupportedTemplateConfigs(serviceProvider);
        applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
        Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.doPreUpdateApplicationTemplate(serviceProvider, tenantDomain);
            }
        }
        doUpdateApplicationTemplate(oldTemplateName, spTemplate, tenantDomain);
    } catch (IdentityApplicationManagementValidationException e) {
        log.error("Validation error when updating the application template: " + oldTemplateName + " in:" + tenantDomain);
        logValidationErrorMessages(e);
        throw new IdentityApplicationManagementClientException(e.getValidationMsg());
    } catch (IdentityApplicationManagementException e) {
        String errorMsg = String.format("Error in updating the application template: %s in tenant: %s", oldTemplateName, tenantDomain);
        throw new IdentityApplicationManagementException(errorMsg, e);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)

Example 4 with IdentityApplicationManagementClientException

use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getDiscoverableApplicationBasicInfoByResourceId.

@Override
public ApplicationBasicInfo getDiscoverableApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Getting application basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain + " if discoverable.");
    }
    ApplicationBasicInfo applicationBasicInfo = null;
    boolean isDiscoverable = false;
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_APP_BY_TENANT_AND_UUID)) {
            statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
            statement.setString(ApplicationTableColumns.UUID, resourceId);
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    applicationBasicInfo = buildApplicationBasicInfo(resultSet);
                    isDiscoverable = getBooleanValue(resultSet.getString(ApplicationTableColumns.IS_DISCOVERABLE));
                }
            }
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementServerException("Error while getting discoverable application " + "basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, e);
    }
    if (applicationBasicInfo != null && !isDiscoverable) {
        throw new IdentityApplicationManagementClientException(APPLICATION_NOT_DISCOVERABLE.getCode(), "Requested application resource " + resourceId + " is not discoverable.");
    }
    return applicationBasicInfo;
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 5 with IdentityApplicationManagementClientException

use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method addApplication.

public String addApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException {
    Connection connection = IdentityDatabaseUtil.getDBConnection(true);
    try {
        // Create basic application.
        ApplicationCreateResult result = persistBasicApplicationInformation(connection, application, tenantDomain);
        int applicationId = result.getApplicationId();
        String resourceId = result.getApplicationResourceId();
        if (log.isDebugEnabled()) {
            log.debug("Application with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain + " has been created with appId: " + applicationId + " and resourceId: " + resourceId);
        }
        // Before calling update we set the appId and resourceId to the application.
        application.setApplicationID(applicationId);
        application.setApplicationResourceId(resourceId);
        addApplicationConfigurations(connection, application, tenantDomain);
        IdentityDatabaseUtil.commitTransaction(connection);
        return resourceId;
    } catch (SQLException | UserStoreException | IdentityApplicationManagementException e) {
        log.error("Error while creating the application with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain + ". Rolling back created application information.");
        IdentityDatabaseUtil.rollbackTransaction(connection);
        if (isApplicationConflict(e)) {
            throw new IdentityApplicationManagementClientException(APPLICATION_ALREADY_EXISTS.getCode(), "Application already exists with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain);
        }
        throw new IdentityApplicationManagementException("Error while creating an application: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain, e);
    } finally {
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Aggregations

IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)14 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)10 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)5 IdentityApplicationManagementValidationException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)4 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)4 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 IdentityApplicationManagementServerException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)3 Response (javax.ws.rs.core.Response)2 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)2 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)2 ImportResponse (org.wso2.carbon.identity.application.common.model.ImportResponse)2 ResultSet (java.sql.ResultSet)1 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)1 ApplicationBasicInfo (org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)1 SpTemplate (org.wso2.carbon.identity.application.common.model.SpTemplate)1 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)1 ApplicationDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.ApplicationDAOImpl)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1