use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerImpl method addTemplateUsingTemplateMgtDAO.
@Override
public Template addTemplateUsingTemplateMgtDAO(Template template) throws TemplateManagementException {
validateInputParameters(template);
if (isTemplateExists(template.getTemplateName())) {
if (log.isDebugEnabled()) {
log.debug("A template already exists with the name: " + template.getTemplateName());
}
throw handleClientException(ERROR_CODE_TEMPLATE_ALREADY_EXIST, template.getTemplateName());
}
TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
return templateManagerDAO.addTemplate(template);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerImpl method updateTemplate.
/**
* This method is used to update an existing Template.
*
* @param templateName Name of the updated template.
* @param template Template element.
* @return Return the updated Template element.
* @throws TemplateManagementException Template Management Exception.
*/
@Override
public Template updateTemplate(String templateName, Template template) throws TemplateManagementException {
validateInputParameters(template);
TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
if (!isTemplateExists(templateName)) {
if (log.isDebugEnabled()) {
log.debug("No template found for the name: " + templateName);
}
throw handleClientException(ERROR_CODE_TEMPLATE_NAME_INVALID, templateName);
}
if (!StringUtils.equals(templateName, template.getTemplateName()) && isTemplateExists(template.getTemplateName())) {
// with the name of the updated template
if (log.isDebugEnabled()) {
log.debug("A template already exists with the name: " + template.getTemplateName());
}
throw handleClientException(ERROR_CODE_TEMPLATE_ALREADY_EXIST, template.getTemplateName());
}
return templateManagerDAO.updateTemplate(templateName, template);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method getTemplateByName.
/**
* Retrieve {@link Template} by template name and tenant Id.
*
* @param templateName name of the {@link Template} to retrieve.
* @param tenantId tenant Id of the tenant which the {@link Template} resides.
* @return {@link Template} for the given name and tenant Id.
* @throws TemplateManagementException If error occurs while retrieving {@link Template}.
*/
public Template getTemplateByName(String templateName, Integer tenantId) throws TemplateManagementException {
Template template;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
template = jdbcTemplate.fetchSingleRecord(GET_TEMPLATE_BY_NAME, ((resultSet, rowNumber) -> {
Template templateResult;
try {
templateResult = new Template(resultSet.getString(1), resultSet.getString(2), IOUtils.toString(resultSet.getBinaryStream(3)));
} catch (IOException e) {
// SQLException is thrown since the QueryFilter throws an SQLException
throw new TemplateManagementSQLException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
}
return templateResult;
}), preparedStatement -> {
preparedStatement.setString(1, templateName);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
}
return template;
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagementServiceClient method addTemplate.
public Template addTemplate(TemplateRequestDTO templateRequestDTO) throws TemplateManagementException {
handleLoggedInUserAuthorization(TemplateMgtConstants.PERMISSION_TEMPLATE_MGT_ADD);
Template template = new Template(templateRequestDTO.getTenantId(), templateRequestDTO.getTemplateName(), templateRequestDTO.getDescription(), templateRequestDTO.getTemplateScript());
return getTemplateManager().addTemplateUsingTemplateMgtDAO(template);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagementServiceClient method handleLoggedInUserAuthorization.
private void handleLoggedInUserAuthorization(String permission) throws TemplateManagementException {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (StringUtils.isBlank(loggedInUser)) {
throw new TemplateManagementException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_NO_AUTH_USER_FOUND.getMessage(), TemplateMgtConstants.ErrorMessages.ERROR_CODE_NO_AUTH_USER_FOUND.getCode());
}
AuthorizationManager authorizationManager = TemplateManagementUIServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getAuthorizationManager();
if (!authorizationManager.isUserAuthorized(loggedInUser, permission, CarbonConstants.UI_PERMISSION_ACTION)) {
throw new TemplateManagementException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_USER_NOT_AUTHORIZED.getMessage(), TemplateMgtConstants.ErrorMessages.ERROR_CODE_USER_NOT_AUTHORIZED.getCode());
}
} catch (UserStoreException e) {
throw new TemplateManagementException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getMessage(), TemplateMgtConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode());
}
}
Aggregations