Search in sources :

Example 1 with IdentityProviderTemplate

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate 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 2 with IdentityProviderTemplate

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate in project identity-api-server by wso2.

the class ServerIdpManagementService method generateIDPTemplate.

/**
 * Create {@link Template} using the {@link IdentityProviderTemplate}.
 *
 * @param idpTemplate Identity provider template object created by the API request.
 * @return IDPTemplate {@link Template}.
 * @throws JsonProcessingException
 */
private Template generateIDPTemplate(IdentityProviderTemplate idpTemplate) throws JsonProcessingException {
    Template identityProviderTemplate = new Template();
    identityProviderTemplate.setTemplateName(idpTemplate.getName());
    identityProviderTemplate.setDescription(idpTemplate.getDescription());
    identityProviderTemplate.setImageUrl(idpTemplate.getImage());
    identityProviderTemplate.setTenantId(IdentityTenantUtil.getTenantId(ContextLoader.getTenantDomainFromContext()));
    Map<String, String> properties = createPropertiesMapForIdPTemplate(idpTemplate);
    identityProviderTemplate.setTemplateType(TemplateMgtConstants.TemplateType.IDP_TEMPLATE);
    identityProviderTemplate.setPropertiesMap(properties);
    identityProviderTemplate.setTemplateScript(createIDPTemplateScript(idpTemplate.getIdp()));
    return identityProviderTemplate;
}
Also used : IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Example 3 with IdentityProviderTemplate

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate in project identity-api-server by wso2.

the class ServerIdpManagementService method updateIDPTemplate.

/**
 * Update IDP template.
 *
 * @param identityProviderTemplate Updated IDP template
 */
public void updateIDPTemplate(String templateId, IdentityProviderTemplate identityProviderTemplate) {
    try {
        Template idpTemplate = generateIDPTemplate(identityProviderTemplate);
        IdentityProviderServiceHolder.getTemplateManager().updateTemplateById(templateId, idpTemplate);
    } catch (TemplateManagementException e) {
        throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP_TEMPLATE, identityProviderTemplate.getId());
    } catch (JsonProcessingException e) {
        throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP_TEMPLATE, templateId);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) 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 4 with IdentityProviderTemplate

use of org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate in project identity-api-server by wso2.

the class ServerIdpManagementService method createIDPTemplateResponse.

/**
 * Create IDP template response using retrieved IDP template.
 *
 * @param idpTemplate IDP template {@link Template}.
 * @return {@link IdentityProviderTemplate}
 * @throws IOException
 */
private IdentityProviderTemplate createIDPTemplateResponse(Template idpTemplate) throws IOException {
    IdentityProviderTemplate idpTemplateResponse = new IdentityProviderTemplate();
    idpTemplateResponse.setId(idpTemplate.getTemplateId());
    idpTemplateResponse.setName(idpTemplate.getTemplateName());
    idpTemplateResponse.setDescription(idpTemplate.getDescription());
    idpTemplateResponse.setImage(idpTemplate.getImageUrl());
    if (idpTemplate.getPropertiesMap().containsKey(PROP_CATEGORY)) {
        if (IdentityProviderTemplateListItem.CategoryEnum.CUSTOM.toString().equals(idpTemplate.getPropertiesMap().get(PROP_CATEGORY))) {
            idpTemplateResponse.setCategory(IdentityProviderTemplate.CategoryEnum.CUSTOM);
        } else {
            idpTemplateResponse.setCategory(IdentityProviderTemplate.CategoryEnum.DEFAULT);
        }
    }
    if (idpTemplate.getPropertiesMap().containsKey(PROP_DISPLAY_ORDER)) {
        idpTemplateResponse.setDisplayOrder(Integer.valueOf(idpTemplate.getPropertiesMap().get(PROP_DISPLAY_ORDER)));
    }
    if (idpTemplate.getTemplateScript() != null) {
        ObjectMapper mapper = new ObjectMapper();
        IdentityProviderPOSTRequest idp = mapper.readValue(idpTemplate.getTemplateScript(), IdentityProviderPOSTRequest.class);
        idpTemplateResponse.setIdp(idp);
    }
    return idpTemplateResponse;
}
Also used : IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IdentityProviderPOSTRequest(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderPOSTRequest)

Aggregations

IdentityProviderTemplate (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate)4 Template (org.wso2.carbon.identity.template.mgt.model.Template)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 TemplateManagementException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IdentityProviderPOSTRequest (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderPOSTRequest)1 TemplateManager (org.wso2.carbon.identity.template.mgt.TemplateManager)1