use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method marshalSPTemplate.
private String marshalSPTemplate(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(ServiceProvider.class);
Marshaller marshaller = jaxbContext.createMarshaller();
DocumentBuilderFactory docBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
Document document = docBuilderFactory.newDocumentBuilder().newDocument();
marshaller.marshal(serviceProvider, document);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, "AuthenticationScript inboundConfiguration");
StringWriter stringBuilder = new StringWriter();
StreamResult result = new StreamResult(stringBuilder);
transformer.transform(new DOMSource(document), result);
return stringBuilder.getBuffer().toString();
} catch (JAXBException | ParserConfigurationException | TransformerException e) {
throw new IdentityApplicationManagementException(String.format("Error in exporting Service Provider " + "template from SP %s@%s", serviceProvider.getApplicationName(), tenantDomain), e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method importApplication.
private ImportResponse importApplication(ServiceProvider serviceProvider, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
ServiceProvider savedSP = null;
String appName = serviceProvider.getApplicationName();
try {
if (isUpdate) {
savedSP = getApplicationExcludingFileBasedSPs(appName, tenantDomain);
if (savedSP == null) {
String errorMsg = String.format("Service provider %s@%s is not found", appName, tenantDomain);
throw new IdentityApplicationManagementClientException(APPLICATION_NOT_FOUND.getCode(), errorMsg);
}
}
if (!isUpdate) {
ServiceProvider basicApplication = new ServiceProvider();
basicApplication.setApplicationName(serviceProvider.getApplicationName());
basicApplication.setDescription(serviceProvider.getDescription());
String resourceId = createApplication(basicApplication, tenantDomain, username);
savedSP = getApplicationByResourceId(resourceId, tenantDomain);
}
serviceProvider.setApplicationResourceId(savedSP.getApplicationResourceId());
serviceProvider.setApplicationID(savedSP.getApplicationID());
serviceProvider.setOwner(getUser(tenantDomain, username));
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.onPreCreateInbound(serviceProvider, isUpdate);
}
}
updateApplication(serviceProvider, tenantDomain, username);
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doImportServiceProvider(serviceProvider);
}
}
ImportResponse importResponse = new ImportResponse();
if (isUpdate) {
importResponse.setResponseCode(ImportResponse.UPDATED);
} else {
importResponse.setResponseCode(ImportResponse.CREATED);
}
importResponse.setApplicationName(appName);
importResponse.setApplicationResourceId(serviceProvider.getApplicationResourceId());
importResponse.setErrors(new String[0]);
return importResponse;
} catch (IdentityApplicationManagementClientException e) {
deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
return buildImportErrorResponse(e);
} catch (IdentityApplicationManagementException e) {
deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
String errorMsg = String.format("Error in importing provided service provider %s@%s from file ", appName, tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method createApplication.
@Override
public String createApplication(ServiceProvider application, String tenantDomain, String username) throws IdentityApplicationManagementException {
// Invoking the listeners.
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreCreateApplication(application, tenantDomain, username)) {
throw buildServerException("Pre create application operation of listener: " + getName(listener) + " failed for application: " + application.getApplicationName() + " of tenantDomain: " + tenantDomain);
}
}
doPreAddApplicationChecks(application, tenantDomain, username);
ApplicationDAO applicationDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
String resourceId = doAddApplication(application, tenantDomain, username, applicationDAO::addApplication);
for (ApplicationResourceManagementListener listener : listeners) {
try {
if (listener.isEnabled() && !listener.doPostCreateApplication(resourceId, application, tenantDomain, username)) {
log.error("Post create application operation of listener:" + getName(listener) + " failed for " + "application: " + application.getApplicationName() + " of tenantDomain: " + tenantDomain);
break;
}
} catch (Throwable e) {
/*
* For more information read https://github.com/wso2/product-is/issues/12579. This is to overcome the
* above issue.
*/
log.error("Post create application operation of listener:" + getName(listener) + " failed for " + "application: " + application.getApplicationName() + " of tenantDomain: " + tenantDomain + " due to: " + e);
deleteApplicationByResourceId(resourceId, tenantDomain, username);
if (log.isDebugEnabled()) {
log.debug("Removed the application created with id: " + resourceId + " of tenantDomain: " + tenantDomain);
}
throw buildServerException("Server encountered an unexpected error when creating the application.");
}
}
triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.CREATE_APPLICATION.getEventId(), getAppId(application), getApplicationName(application), TARGET_APPLICATION, buildSPData(application));
return resourceId;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method deleteApplication.
// Will be supported with 'Advance Consent Management Feature'.
/*
private void validateConsentPurposes(ServiceProvider serviceProvider) throws
IdentityApplicationManagementException {
ConsentManager consentManager = ApplicationManagementServiceComponentHolder.getInstance().getConsentManager();
ConsentConfig consentConfig = serviceProvider.getConsentConfig();
if (nonNull(consentConfig)) {
ConsentPurposeConfigs consentPurposeConfigs = consentConfig.getConsentPurposeConfigs();
if (nonNull(consentPurposeConfigs)) {
ConsentPurpose[] consentPurposes = consentPurposeConfigs.getConsentPurpose();
if (nonNull(consentPurposes)) {
for (ConsentPurpose consentPurpose : consentPurposes) {
int purposeId = consentPurpose.getPurposeId();
try {
Purpose purpose = consentManager.getPurpose(purposeId);
if (isNull(purpose)) {
if (log.isDebugEnabled()) {
log.debug("ConsentManager returned null for Purpose ID: " + purposeId);
}
throw new IdentityApplicationManagementException("Invalid purpose ID: " + purposeId);
}
if (!isSPSpecificPurpose(serviceProvider, purpose) && !isSharedPurpose(purpose)) {
String message = "Purpose: %s with ID: %s is not defined under purposes for SP:" +
" %s or 'SHARED' purposes.";
String error = String.format(message, purpose.getName(), purpose.getId(),
serviceProvider.getApplicationName());
throw new IdentityApplicationManagementException(error);
}
} catch (ConsentManagementException e) {
if (ERROR_CODE_PURPOSE_ID_INVALID.getCode().equals(e.getErrorCode())) {
throw new IdentityApplicationManagementException("Invalid purpose ID: " + purposeId, e);
}
throw new IdentityApplicationManagementException("Error while retrieving consent purpose " +
"with ID: " + purposeId, e);
}
}
}
}
}
}
private boolean isSharedPurpose(Purpose purpose) {
return PURPOSE_GROUP_SHARED.equals(purpose.getGroup()) && PURPOSE_GROUP_TYPE_SYSTEM.equals(
purpose.getGroupType());
}
private boolean isSPSpecificPurpose(ServiceProvider serviceProvider, Purpose purpose) {
return serviceProvider.getApplicationName().equals(purpose.getGroup())&& PURPOSE_GROUP_TYPE_SP.equals(
purpose.getGroupType());
}
*/
@Override
public void deleteApplication(String applicationName, String tenantDomain, String username) throws IdentityApplicationManagementException {
ServiceProvider serviceProvider;
// invoking the listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPreDeleteApplication(applicationName, tenantDomain, username)) {
throw buildServerException("Pre Delete application operation of listener: " + getName(listener) + " failed for application: " + applicationName + " of tenantDomain: " + tenantDomain);
}
}
try {
startTenantFlow(tenantDomain, username);
doPreDeleteChecks(applicationName, tenantDomain, username);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
serviceProvider = appDAO.getApplication(applicationName, tenantDomain);
if (serviceProvider != null) {
ApplicationMgtUtil.deleteAppRole(applicationName);
ApplicationMgtUtil.deletePermissions(applicationName);
appDAO.deleteApplication(applicationName);
} else {
if (log.isDebugEnabled()) {
log.debug("Application cannot be found for name: " + applicationName + " in tenantDomain: " + tenantDomain);
}
return;
}
} catch (Exception e) {
String error = "Error occurred while deleting the application: " + applicationName + ". " + e.getMessage();
throw buildServerException(error, e);
} finally {
endTenantFlow();
}
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostDeleteApplication(serviceProvider, tenantDomain, username)) {
log.error("Post Delete application operation of listener: " + getName(listener) + " failed for " + "application with name: " + applicationName + " of tenantDomain: " + tenantDomain);
return;
}
}
triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.DELETE_APPLICATION.getEventId(), getAppId(serviceProvider), getApplicationName(serviceProvider), TARGET_APPLICATION, null);
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplicationTemplate.
@Override
public void updateApplicationTemplate(String oldTemplateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
try {
validateSPTemplateExists(oldTemplateName, spTemplate, tenantDomain);
ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
validateUnsupportedTemplateConfigs(serviceProvider);
applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doPreUpdateApplicationTemplate(serviceProvider, tenantDomain);
}
}
doUpdateApplicationTemplate(oldTemplateName, spTemplate, tenantDomain);
} catch (IdentityApplicationManagementValidationException e) {
log.error("Validation error when updating the application template: " + oldTemplateName + " in:" + tenantDomain);
logValidationErrorMessages(e);
throw new IdentityApplicationManagementClientException(e.getValidationMsg());
} catch (IdentityApplicationManagementException e) {
String errorMsg = String.format("Error in updating the application template: %s in tenant: %s", oldTemplateName, tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
Aggregations