use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener 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.mgt.listener.ApplicationMgtListener 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.mgt.listener.ApplicationMgtListener 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);
}
}
use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getServiceProvider.
/**
* @param serviceProviderName
* @param tenantDomain
* @return
* @throws IdentityApplicationManagementException
*/
@Override
public ServiceProvider getServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
// invoking the listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPreGetServiceProvider(serviceProviderName, tenantDomain)) {
return null;
}
}
ServiceProvider serviceProvider = null;
try {
startTenantFlow(tenantDomain);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
serviceProvider = appDAO.getApplication(serviceProviderName, tenantDomain);
if (serviceProvider == null && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
}
} finally {
endTenantFlow();
}
// invoking the listeners
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain)) {
return null;
}
}
return serviceProvider;
}
use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getServiceProvider.
/**
* @param appId
* @return
* @throws IdentityApplicationManagementException
*/
@Override
public ServiceProvider getServiceProvider(int appId) throws IdentityApplicationManagementException {
// TODO: Need to have pre listeners. Don't have them because we didn't want to add listener methods to the
// TODO: ApplicationMgtListener interface since we didn't want to change APIs. Also pre listener aren't vital
// TODO: for getters. Mostly post listeners are enough.
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ServiceProvider serviceProvider = appDAO.getApplication(appId);
String serviceProviderName = serviceProvider.getApplicationName();
String tenantDomain = serviceProvider.getOwner().getTenantDomain();
// TODO: Since we didn't add post listener methods to the ApplicationMgtListener API to avoid API changes, we
// TODO: are invoking doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain) listener
// TODO: method here as well.
// invoking the post listeners
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable() && !listener.doPostGetServiceProvider(serviceProvider, serviceProviderName, tenantDomain)) {
return null;
}
}
return serviceProvider;
}
Aggregations