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