Search in sources :

Example 1 with ApplicationResourceManagementListener

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;
}
Also used : ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 2 with ApplicationResourceManagementListener

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;
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 3 with ApplicationResourceManagementListener

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));
}
Also used : ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 4 with ApplicationResourceManagementListener

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;
}
Also used : ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 5 with ApplicationResourceManagementListener

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;
}
Also used : ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Aggregations

ApplicationResourceManagementListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener)6 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)5 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)5 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)5 ApplicationBasicInfo (org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)3 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 RegistryException (org.wso2.carbon.registry.api.RegistryException)2 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)1 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)1 IdentityApplicationManagementServerException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)1 IdentityApplicationManagementValidationException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)1 IdentityApplicationRegistrationFailureException (org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException)1 DefaultAuthSeqMgtException (org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 SAXException (org.xml.sax.SAXException)1