Search in sources :

Example 1 with SpTemplate

use of org.wso2.carbon.identity.application.common.model.SpTemplate 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 2 with SpTemplate

use of org.wso2.carbon.identity.application.common.model.SpTemplate 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 3 with SpTemplate

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

the class ApplicationManagementServiceImpl method doUpdateApplicationTemplate.

/**
 * Update SP template from database and cache.
 *
 * @param templateName template name
 * @param spTemplate   template info
 * @param tenantDomain tenant domain
 * @throws IdentityApplicationManagementException
 */
private void doUpdateApplicationTemplate(String templateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
    // Update SP template in database
    ApplicationTemplateDAO applicationTemplateDAO = ApplicationMgtSystemConfig.getInstance().getApplicationTemplateDAO();
    applicationTemplateDAO.updateApplicationTemplate(templateName, spTemplate, tenantDomain);
    // Update the template in cache
    if (!templateName.equals(spTemplate.getName())) {
        ServiceProviderTemplateCacheKey templateCacheKey = new ServiceProviderTemplateCacheKey(templateName);
        ServiceProviderTemplateCache.getInstance().clearCacheEntry(templateCacheKey, tenantDomain);
    }
    ServiceProviderTemplateCacheKey templateCacheKey = new ServiceProviderTemplateCacheKey(spTemplate.getName());
    ServiceProviderTemplateCache.getInstance().addToCache(templateCacheKey, spTemplate, tenantDomain);
}
Also used : ServiceProviderTemplateCacheKey(org.wso2.carbon.identity.application.mgt.cache.ServiceProviderTemplateCacheKey) ApplicationTemplateDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationTemplateDAO)

Example 4 with SpTemplate

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

the class ApplicationManagementServiceImpl method getSpTemplateFromDB.

private SpTemplate getSpTemplateFromDB(String templateName, String tenantDomain, ServiceProviderTemplateCacheKey templateCacheKey) throws IdentityApplicationManagementException {
    ApplicationTemplateDAO applicationTemplateDAO = ApplicationMgtSystemConfig.getInstance().getApplicationTemplateDAO();
    SpTemplate spTemplate = applicationTemplateDAO.getApplicationTemplate(templateName, tenantDomain);
    if (spTemplate != null) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Template with name: %s is taken from database for tenant: %s ", templateName, tenantDomain));
        }
        ServiceProviderTemplateCache.getInstance().addToCache(templateCacheKey, spTemplate, tenantDomain);
        return spTemplate;
    }
    return null;
}
Also used : SpTemplate(org.wso2.carbon.identity.application.common.model.SpTemplate) ApplicationTemplateDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationTemplateDAO)

Example 5 with SpTemplate

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

the class ApplicationTemplateDAOImpl method updateApplicationTemplate.

@Override
public void updateApplicationTemplate(String templateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Updating application template: %s in tenant: %s", spTemplate.getName(), tenantDomain));
    }
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        jdbcTemplate.executeUpdate(UPDATE_SP_TEMPLATE_BY_NAME, preparedStatement -> {
            preparedStatement.setString(1, spTemplate.getName());
            preparedStatement.setString(2, spTemplate.getDescription());
            try {
                setBlobValue(spTemplate.getContent(), preparedStatement, 3);
            } catch (IOException e) {
                throw new SQLException(String.format("Could not set application template: %s content as " + "a Blob in tenant: %s.", spTemplate.getName(), tenantDomain), e);
            }
            preparedStatement.setString(4, templateName);
            preparedStatement.setInt(5, getTenantID(tenantDomain));
        });
    } catch (DataAccessException e) {
        throw new IdentityApplicationManagementException(String.format("An error occurred while updating the" + " application template : %s in tenant: %s", spTemplate.getName(), tenantDomain), e);
    }
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IOException(java.io.IOException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Aggregations

IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)10 IOException (java.io.IOException)9 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)7 SpTemplate (org.wso2.carbon.identity.application.common.model.SpTemplate)7 SpTemplate (org.wso2.carbon.identity.application.common.model.xsd.SpTemplate)7 URISyntaxException (java.net.URISyntaxException)6 Test (org.testng.annotations.Test)6 ApplicationTemplateDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationTemplateDAO)6 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)6 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)4 ServiceProviderTemplateCacheKey (org.wso2.carbon.identity.application.mgt.cache.ServiceProviderTemplateCacheKey)4 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)4 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)4 SQLException (java.sql.SQLException)3 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)3 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)3 IdentityApplicationManagementValidationException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2