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;
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations