use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method deleteTemplate.
/**
* Delete {@link Template} for a given template name and a tenant Id.
*
* @param templateName name of the {@link Template} to be deleted.the tenant
* @param tenantId tenant Id of the tenant which the {@link Template} resides.
* @return TemplateInfo of the deleted {@link Template}.
* @throws TemplateManagementException If error occurs while deleting the {@link Template}
*/
public TemplateInfo deleteTemplate(String templateName, Integer tenantId) throws TemplateManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(DELETE_TEMPLATE, preparedStatement -> {
preparedStatement.setString(1, templateName);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_DELETE_TEMPLATE.getMessage(), tenantId.toString(), templateName), ERROR_CODE_DELETE_TEMPLATE.getCode(), e);
}
return new TemplateInfo(tenantId, templateName);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method getAllTemplates.
/**
* List {@link TemplateInfo} items for a given search criteria.
*
* @param tenantId Tenant Id to be searched.
* @param limit Maximum number of results expected.
* @param offset Result offset.
* @return List of {@link TemplateInfo} entries.
* @throws TemplateManagementException If error occurs while searching the Templates.
*/
public List<TemplateInfo> getAllTemplates(Integer tenantId, Integer limit, Integer offset) throws TemplateManagementException {
List<TemplateInfo> templates;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String query;
if (isH2DB() || isMySQLDB() || isPostgreSQLDB()) {
query = LIST_PAGINATED_TEMPLATES_MYSQL;
} else if (isDB2DB()) {
query = LIST_PAGINATED_TEMPLATES_DB2;
int initialOffset = offset;
offset = offset + limit;
limit = initialOffset + 1;
} else if (isMSSqlDB()) {
int initialOffset = offset;
offset = limit + offset;
limit = initialOffset + 1;
query = LIST_PAGINATED_TEMPLATES_MSSQL;
} else {
// oracle
query = LIST_PAGINATED_TEMPLATES_ORACLE;
limit = offset + limit;
}
int finalLimit = limit;
int finalOffset = offset;
templates = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> new TemplateInfo(resultSet.getString(1), resultSet.getString(2)), preparedStatement -> {
preparedStatement.setInt(1, tenantId);
preparedStatement.setInt(2, finalLimit);
preparedStatement.setInt(3, finalOffset);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_PAGINATED_LIST_TEMPLATES.getMessage(), tenantId, limit, offset), ERROR_CODE_PAGINATED_LIST_TEMPLATES.getCode(), e);
}
return templates;
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagementServiceClient method updateTemplate.
public Template updateTemplate(String templateName, UpdateTemplateRequestDTO updateTemplateRequestDTO) throws TemplateManagementException {
handleLoggedInUserAuthorization(TemplateMgtConstants.PERMISSION_TEMPLATE_MGT_UPDATE);
Template updateTemplateRequest = new Template(updateTemplateRequestDTO.getTemplateName(), updateTemplateRequestDTO.getDescription(), updateTemplateRequestDTO.getTemplateScript());
return getTemplateManager().updateTemplate(templateName, updateTemplateRequest);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project product-is by wso2.
the class TemplateManagementServiceClient method updateTemplate.
public Template updateTemplate(String templateName, UpdateTemplateRequestDTO updateTemplateRequestDTO) throws TemplateManagementException {
handleLoggedInUserAuthorization(TemplateMgtConstants.PERMISSION_TEMPLATE_MGT_UPDATE);
Template updateTemplateRequest = new Template(updateTemplateRequestDTO.getTemplateName(), updateTemplateRequestDTO.getDescription(), updateTemplateRequestDTO.getTemplateScript());
return getTemplateManager().updateTemplate(templateName, updateTemplateRequest);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project product-is 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