use of org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener 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.mgt.listener.ApplicationResourceManagementListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getApplicationByResourceId.
@Override
public ServiceProvider getApplicationByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreGetApplicationByResourceId(resourceId, tenantDomain)) {
throw buildServerException("Pre Get application operation of " + "listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
}
}
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ServiceProvider application = appDAO.getApplicationByResourceId(resourceId, tenantDomain);
if (application == null) {
if (log.isDebugEnabled()) {
log.debug("Cannot find an application for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain);
}
return null;
}
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostGetApplicationByResourceId(application, resourceId, tenantDomain)) {
log.error("Post Get application operation of " + "listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
break;
}
}
return application;
}
use of org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplicationByResourceId.
@Override
public void updateApplicationByResourceId(String resourceId, ServiceProvider updatedApp, String tenantDomain, String username) throws IdentityApplicationManagementException {
validateApplicationConfigurations(updatedApp, tenantDomain, username);
updatedApp.setApplicationResourceId(resourceId);
setDisplayNamesOfLocalAuthenticators(updatedApp, tenantDomain);
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
throw buildServerException("Pre Update application operation of listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
}
}
try {
startTenantFlow(tenantDomain);
ApplicationBasicInfo storedAppInfo = getApplicationBasicInfo(resourceId, tenantDomain);
if (storedAppInfo == null) {
String msg = "Cannot find an application for " + "resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
throw buildClientException(APPLICATION_NOT_FOUND, msg);
}
String updatedAppName = updatedApp.getApplicationName();
String storedAppName = storedAppInfo.getApplicationName();
doPreUpdateChecks(storedAppName, updatedApp, tenantDomain, username);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
appDAO.updateApplicationByResourceId(resourceId, tenantDomain, updatedApp);
if (isOwnerUpdateRequest(storedAppInfo.getAppOwner(), updatedApp.getOwner())) {
// User existence check is already done in appDAO.updateApplicationByResourceId() method.
assignApplicationRole(updatedApp.getApplicationName(), updatedApp.getOwner().getUserName());
}
updateApplicationPermissions(updatedApp, updatedAppName, storedAppName);
} catch (RegistryException e) {
String message = "Error while updating application with resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
throw buildServerException(message, e);
} finally {
endTenantFlow();
}
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
log.error("Post Update application operation of listener: " + getName(listener) + " failed for " + "application with resourceId: " + resourceId);
return;
}
}
triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.UPDATE_APPLICATION.getEventId(), getAppId(updatedApp), getApplicationName(updatedApp), TARGET_APPLICATION, buildSPData(updatedApp));
}
use of org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getApplicationBasicInfoByName.
@Override
public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String tenantDomain) throws IdentityApplicationManagementException {
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreGetApplicationBasicInfoByName(name, tenantDomain)) {
throw buildServerException("Error executing doPreGetApplicationBasicInfoByName operation of " + "listener: " + getName(listener) + " for application name: " + name);
}
}
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
ApplicationBasicInfo basicAppInfo = appDAO.getApplicationBasicInfoByName(name, tenantDomain);
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostGetApplicationBasicInfoByName(basicAppInfo, name, tenantDomain)) {
throw buildServerException("Error executing doPostGetApplicationBasicInfoByName operation of " + "listener: " + getName(listener) + " for application name: " + name);
}
}
return basicAppInfo;
}
use of org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getApplicationBasicInfoByResourceId.
@Override
public ApplicationBasicInfo getApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreGetApplicationBasicInfoByResourceId(resourceId, tenantDomain)) {
throw buildServerException("Error executing doPreGetApplicationBasicInfoByResourceId operation of " + "listener: " + getName(listener) + " for application resourceId: " + resourceId);
}
}
ApplicationBasicInfo basicAppInfo = getApplicationBasicInfo(resourceId, tenantDomain);
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostGetApplicationBasicInfoByResourceId(basicAppInfo, resourceId, tenantDomain)) {
throw buildServerException("Error executing doPostGetApplicationBasicInfoByResourceId operation of " + "listener: " + getName(listener) + " for application resourceId: " + resourceId);
}
}
return basicAppInfo;
}
Aggregations