Search in sources :

Example 11 with TemplateManagementException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project product-is 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);
}
Also used : Template(org.wso2.carbon.identity.template.mgt.model.Template)

Example 12 with TemplateManagementException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.

the class ServerIdpManagementService method deleteIDPTemplate.

/**
 * Delete a IDP template identified by resource Id.
 *
 * @param templateId Id of the IDP template
 */
public void deleteIDPTemplate(String templateId) {
    try {
        TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
        templateManager.deleteTemplateById(templateId);
    } catch (TemplateManagementException e) {
        throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_DELETING_IDP_TEMPLATE, templateId);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager)

Example 13 with TemplateManagementException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.

the class ServerIdpManagementService method createIDPTemplate.

/**
 * Create a new IDP template.
 *
 * @param identityProviderTemplate identityProviderTemplatePOSTRequest
 * @return IdentityProviderTemplateResponse
 */
public String createIDPTemplate(IdentityProviderTemplate identityProviderTemplate) {
    try {
        TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
        Template idpTemplate = generateIDPTemplate(identityProviderTemplate);
        return templateManager.addTemplate(idpTemplate);
    } catch (TemplateManagementException e) {
        throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
    } catch (JsonProcessingException e) {
        throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Example 14 with TemplateManagementException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.

the class ServerIdpManagementService method handleTemplateMgtException.

/**
 * Handle template management exceptions and return related API errors.
 *
 * @param e {@link TemplateManagementException}.
 * @param errorEnum Error message with error code and description.
 * @param data Additional information.
 * @return API error.
 */
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof TemplateManagementClientException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
            errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof TemplateManagementServerException) {
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
            errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        if (e.getErrorCode() != null) {
            errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
        } else {
            errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
        }
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : IdentityProviderTemplateListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) IdentityProviderListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse) FederatedAuthenticatorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse) Response(javax.ws.rs.core.Response) IdentityProviderResponse(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse) OutboundConnectorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse) ProvisioningResponse(org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse) TemplateManagementServerException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) TemplateManagementClientException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 15 with TemplateManagementException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.

the class TemplateManagerImpl method listTemplates.

@Override
public List<Template> listTemplates(String templateType, Integer limit, Integer offset, Condition searchCondition) throws TemplateManagementException {
    if (!isValidTemplateType(templateType)) {
        throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INVALID_TEMPLATE_TYPE, templateType);
    }
    if (limit != null || offset != null) {
        throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_PAGINATION_NOT_SUPPORTED, null);
    }
    List<Template> templates = new ArrayList<>();
    List<ReadOnlyTemplateHandler> readOnlyTemplateHandlers = TemplateManagerDataHolder.getInstance().getReadOnlyTemplateHandlers();
    for (ReadOnlyTemplateHandler readOnlyTemplateHandler : readOnlyTemplateHandlers) {
        templates.addAll(readOnlyTemplateHandler.listTemplates(templateType, limit, offset, searchCondition));
    }
    templates.addAll(configStoreBasedTemplateHandler.listTemplates(templateType, limit, offset, searchCondition));
    return templates;
}
Also used : ReadOnlyTemplateHandler(org.wso2.carbon.identity.template.mgt.handler.ReadOnlyTemplateHandler) ArrayList(java.util.ArrayList) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Aggregations

Template (org.wso2.carbon.identity.template.mgt.model.Template)16 TemplateManagementException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException)10 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ConfigurationManager (org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager)5 ConfigurationManagementException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)5 TemplateManagerDAO (org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO)5 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)4 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)4 TemplateToResource (org.wso2.carbon.identity.template.mgt.function.TemplateToResource)4 List (java.util.List)3 IOUtils (org.apache.commons.io.IOUtils)3 IdentityProviderTemplate (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate)3 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)3 TemplateManager (org.wso2.carbon.identity.template.mgt.TemplateManager)3 TemplateMgtConstants (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants)3 TemplateManagementServerException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JdbcUtils (org.wso2.carbon.identity.core.util.JdbcUtils)2 JdbcUtils.isDB2DB (org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB)2