Search in sources :

Example 11 with ApplicationMgtListener

use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getApplicationBasicInfo.

/**
 * Get all basic application information for a matching filter with pagination based on the offset and limit.
 *
 * @param tenantDomain Tenant Domain.
 * @param username     User name.
 * @param filter       Application name filter.
 * @param offset       Starting index of the count.
 * @param limit        Counting value.
 * @return An array of {@link ApplicationBasicInfo} instances within the limit.
 * @throws IdentityApplicationManagementException Error in retrieving basic application information.
 */
@Override
public ApplicationBasicInfo[] getApplicationBasicInfo(String tenantDomain, String username, String filter, int offset, int limit) throws IdentityApplicationManagementException {
    ApplicationBasicInfo[] applicationBasicInfoArray;
    try {
        startTenantFlow(tenantDomain, username);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        if (appDAO instanceof PaginatableFilterableApplicationDAO) {
            // Invoking pre listeners.
            Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
            for (ApplicationMgtListener listener : listeners) {
                if (listener.isEnable() && listener instanceof AbstractApplicationMgtListener && !((AbstractApplicationMgtListener) listener).doPreGetApplicationBasicInfo(tenantDomain, username, filter, offset, limit)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Invoking pre listener: " + listener.getClass().getName());
                    }
                    return new ApplicationBasicInfo[0];
                }
            }
            applicationBasicInfoArray = ((PaginatableFilterableApplicationDAO) appDAO).getApplicationBasicInfo(filter, offset, limit);
            // Invoking post listeners.
            for (ApplicationMgtListener listener : listeners) {
                if (listener.isEnable() && listener instanceof AbstractApplicationMgtListener && !((AbstractApplicationMgtListener) listener).doPostGetApplicationBasicInfo(tenantDomain, username, filter, offset, limit, applicationBasicInfoArray)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Invoking post listener: " + listener.getClass().getName());
                    }
                    return new ApplicationBasicInfo[0];
                }
            }
        } else {
            throw new UnsupportedOperationException("Application filtering and pagination not supported in " + appDAO.getClass().getName() + " with tenant domain: " + tenantDomain);
        }
    } finally {
        endTenantFlow();
    }
    return applicationBasicInfoArray;
}
Also used : PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) 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) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)

Example 12 with ApplicationMgtListener

use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getAllPaginatedApplicationBasicInfo.

/**
 * Get All Application Basic Information with pagination
 *
 * @param tenantDomain Tenant Domain
 * @param username     User Name
 * @param pageNumber   Number of the page
 * @return ApplicationBasicInfo[]
 * @throws IdentityApplicationManagementException
 */
@Override
public ApplicationBasicInfo[] getAllPaginatedApplicationBasicInfo(String tenantDomain, String username, int pageNumber) throws IdentityApplicationManagementException {
    ApplicationBasicInfo[] applicationBasicInfoArray;
    try {
        startTenantFlow(tenantDomain, username);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        if (appDAO instanceof PaginatableFilterableApplicationDAO) {
            // invoking pre listeners
            Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
            for (ApplicationMgtListener listener : listeners) {
                if (listener.isEnable() && listener instanceof AbstractApplicationMgtListener && !((AbstractApplicationMgtListener) listener).doPreGetPaginatedApplicationBasicInfo(tenantDomain, username, pageNumber)) {
                    return new ApplicationBasicInfo[0];
                }
            }
            applicationBasicInfoArray = ((PaginatableFilterableApplicationDAO) appDAO).getAllPaginatedApplicationBasicInfo(pageNumber);
            // invoking post listeners
            for (ApplicationMgtListener listener : listeners) {
                if (listener.isEnable() && listener instanceof AbstractApplicationMgtListener && !((AbstractApplicationMgtListener) listener).doPostGetPaginatedApplicationBasicInfo(tenantDomain, username, pageNumber, applicationBasicInfoArray)) {
                    return new ApplicationBasicInfo[0];
                }
            }
        } else {
            throw new UnsupportedOperationException("Application pagination is not supported. Tenant domain: " + tenantDomain);
        }
    } finally {
        endTenantFlow();
    }
    return applicationBasicInfoArray;
}
Also used : PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) 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) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)

Example 13 with ApplicationMgtListener

use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method createApplicationTemplateFromSP.

@Override
public void createApplicationTemplateFromSP(ServiceProvider serviceProvider, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
    if (serviceProvider != null) {
        try {
            validateSPTemplateExists(spTemplate, tenantDomain);
            ServiceProvider updatedSP = removeUnsupportedTemplateConfigs(serviceProvider);
            applicationValidatorManager.validateSPConfigurations(updatedSP, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
            Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
            for (ApplicationMgtListener listener : listeners) {
                if (listener.isEnable()) {
                    listener.doPreCreateApplicationTemplate(serviceProvider, tenantDomain);
                }
            }
            String serviceProviderTemplateXml = marshalSPTemplate(updatedSP, tenantDomain);
            spTemplate.setContent(serviceProviderTemplateXml);
            doAddApplicationTemplate(spTemplate, tenantDomain);
        } catch (IdentityApplicationManagementValidationException e) {
            log.error("Validation error when creating the application template:" + spTemplate.getName() + "from service provider: " + serviceProvider.getApplicationName() + " in:" + tenantDomain);
            logValidationErrorMessages(e);
            throw new IdentityApplicationManagementClientException(e.getValidationMsg());
        } catch (IdentityApplicationManagementException e) {
            String errorMsg = String.format("Error when creating the application template: %s from " + "service provider: %s in: ", spTemplate.getName(), serviceProvider.getApplicationName(), tenantDomain);
            throw new IdentityApplicationManagementException(errorMsg, e);
        }
    } else {
        createApplicationTemplate(spTemplate, tenantDomain);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)

Example 14 with ApplicationMgtListener

use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method createApplicationWithTemplate.

@Override
public ServiceProvider createApplicationWithTemplate(ServiceProvider serviceProvider, String tenantDomain, String username, String templateName) throws IdentityApplicationManagementException {
    // Call pre listeners.
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreCreateApplication(serviceProvider, tenantDomain, username)) {
            throw buildServerException("Pre create application operation of listener: " + getName(listener) + " failed for application: " + serviceProvider.getApplicationName() + " of tenantDomain: " + tenantDomain);
        }
    }
    doPreAddApplicationChecks(serviceProvider, tenantDomain, username);
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    serviceProvider.setOwner(getUser(tenantDomain, username));
    int appId = doAddApplication(serviceProvider, tenantDomain, username, appDAO::createApplication);
    serviceProvider.setApplicationID(appId);
    setDisplayNamesOfLocalAuthenticators(serviceProvider, tenantDomain);
    SpTemplate spTemplate = this.getApplicationTemplate(templateName, tenantDomain);
    if (spTemplate != null) {
        updateSpFromTemplate(serviceProvider, tenantDomain, spTemplate);
        appDAO.updateApplication(serviceProvider, tenantDomain);
    }
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostCreateApplication(serviceProvider, tenantDomain, username)) {
            log.error("Post create application operation of listener:" + getName(listener) + " failed for " + "application: " + serviceProvider.getApplicationName() + " of tenantDomain: " + tenantDomain);
            break;
        }
    }
    triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.CREATE_APPLICATION.getEventId(), getAppId(serviceProvider), getApplicationName(serviceProvider), TARGET_APPLICATION, buildSPData(serviceProvider));
    return serviceProvider;
}
Also used : SpTemplate(org.wso2.carbon.identity.application.common.model.SpTemplate) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) 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 15 with ApplicationMgtListener

use of org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method createApplicationTemplate.

@Override
public void createApplicationTemplate(SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
        validateSPTemplateExists(spTemplate, tenantDomain);
        validateUnsupportedTemplateConfigs(serviceProvider);
        applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
        Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.doPreCreateApplicationTemplate(serviceProvider, tenantDomain);
            }
        }
        doAddApplicationTemplate(spTemplate, tenantDomain);
    } catch (IdentityApplicationManagementValidationException e) {
        log.error("Validation error when creating the application template: " + spTemplate.getName() + " in:" + tenantDomain);
        logValidationErrorMessages(e);
        throw new IdentityApplicationManagementClientException(e.getValidationMsg());
    } catch (IdentityApplicationManagementException e) {
        String errorMsg = String.format("Error when creating the application template: %s in tenant: %s", spTemplate.getName(), tenantDomain);
        throw new IdentityApplicationManagementException(errorMsg, e);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)

Aggregations

ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)19 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)18 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)13 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)13 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)13 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)8 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)7 IdentityApplicationManagementValidationException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)6 ApplicationBasicInfo (org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)4 IOException (java.io.IOException)3 JAXBException (javax.xml.bind.JAXBException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 IdentityApplicationManagementServerException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)3 IdentityApplicationRegistrationFailureException (org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException)3 DefaultAuthSeqMgtException (org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException)3 RegistryException (org.wso2.carbon.registry.api.RegistryException)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 SAXException (org.xml.sax.SAXException)3