Search in sources :

Example 1 with ConsentPurposeConfigs

use of org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs 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);
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) 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) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) TransformerException(javax.xml.transform.TransformerException) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBException(javax.xml.bind.JAXBException) IdentityApplicationRegistrationFailureException(org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException) SAXException(org.xml.sax.SAXException) DefaultAuthSeqMgtException(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with ConsentPurposeConfigs

use of org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method updateConsentPurposeConfiguration.

/**
 * Updates the consent purpose configurations of the application.
 *
 * @param connection
 * @param applicationId
 * @param consentConfig
 * @param tenantID
 */
private void updateConsentPurposeConfiguration(Connection connection, int applicationId, ConsentConfig consentConfig, int tenantID) throws IdentityApplicationManagementException {
    try (PreparedStatement pst = connection.prepareStatement(UPDATE_BASIC_APP_INFO_WITH_CONSENT_ENABLED)) {
        pst.setString(1, consentConfig.isEnabled() ? "1" : "0");
        pst.setInt(2, tenantID);
        pst.setInt(3, applicationId);
        pst.executeUpdate();
    } catch (SQLException e) {
        String error = String.format("Error while setting consentEnabled: %s for applicationId: %s in tenantId: " + "%s", Boolean.toString(consentConfig.isEnabled()), applicationId, tenantID);
        throw new IdentityApplicationManagementException(error, e);
    }
    ConsentPurposeConfigs consentPurposeConfigs = consentConfig.getConsentPurposeConfigs();
    if (isNull(consentPurposeConfigs)) {
        if (log.isDebugEnabled()) {
            log.debug("ConsentPurposeConfigs entry is null for application ID: " + applicationId);
        }
        return;
    }
    ConsentPurpose[] consentPurposes = consentPurposeConfigs.getConsentPurpose();
    if (isNull(consentPurposes)) {
        if (log.isDebugEnabled()) {
            log.debug("ConsentPurpose entry is null for application ID: " + applicationId);
        }
        return;
    }
    for (ConsentPurpose consentPurpose : consentPurposes) {
        try (PreparedStatement ps = connection.prepareStatement(ADD_SP_CONSENT_PURPOSE)) {
            ps.setInt(1, applicationId);
            ps.setInt(2, consentPurpose.getPurposeId());
            ps.setInt(3, consentPurpose.getDisplayOrder());
            ps.setInt(4, tenantID);
            ps.executeUpdate();
        } catch (SQLException e) {
            String error = String.format("Error while persisting consent purposeId: %s for applicationId: %s " + "in tenantId: %s", consentPurpose.getPurposeId(), applicationId, tenantID);
            throw new IdentityApplicationManagementException(error, e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) ConsentPurposeConfigs(org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs) ConsentPurpose(org.wso2.carbon.identity.application.common.model.ConsentPurpose)

Example 3 with ConsentPurposeConfigs

use of org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getConsentPurposeConfigs.

private ConsentPurposeConfigs getConsentPurposeConfigs(Connection connection, int applicationId, int tenantId) throws IdentityApplicationManagementException {
    ConsentPurposeConfigs consentPurposeConfigs = new ConsentPurposeConfigs();
    List<ConsentPurpose> consentPurposes = new ArrayList<>();
    try (PreparedStatement ps = connection.prepareStatement(LOAD_SP_CONSENT_PURPOSES)) {
        ps.setInt(1, applicationId);
        ps.setInt(2, tenantId);
        try (ResultSet resultSet = ps.executeQuery()) {
            while (resultSet.next()) {
                ConsentPurpose consentPurpose = new ConsentPurpose();
                consentPurpose.setPurposeId(resultSet.getInt(2));
                consentPurpose.setDisplayOrder(resultSet.getInt(3));
                consentPurposes.add(consentPurpose);
            }
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error while retrieving consent purpose configurations " + "for application ID: " + applicationId, e);
    }
    consentPurposeConfigs.setConsentPurpose(consentPurposes.toArray(new ConsentPurpose[0]));
    return consentPurposeConfigs;
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) ConsentPurposeConfigs(org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs) ConsentPurpose(org.wso2.carbon.identity.application.common.model.ConsentPurpose)

Example 4 with ConsentPurposeConfigs

use of org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs in project carbon-identity-framework by wso2.

the class ConsentPurposeConfigs method build.

/**
 * Build ConsentPurposeConfigs from ConsentPurposeConfigs OM element.
 *
 * @param consentPurposeConfigsOM ConsentPurposeConfigs OM element.
 * @return ConsentPurposeConfigs object.
 */
public static ConsentPurposeConfigs build(OMElement consentPurposeConfigsOM) {
    ConsentPurposeConfigs consentPurposeConfigs = new ConsentPurposeConfigs();
    if (consentPurposeConfigsOM == null) {
        return consentPurposeConfigs;
    }
    List<ConsentPurpose> consentPurposes = new ArrayList<>();
    Iterator<?> iterator = consentPurposeConfigsOM.getChildElements();
    while (iterator.hasNext()) {
        OMElement consentPurposeOM = (OMElement) iterator.next();
        if (CONSENT_PURPOSE_ELEM.equals(consentPurposeOM.getLocalName())) {
            ConsentPurpose consentPurpose;
            try {
                consentPurpose = ConsentPurpose.build(consentPurposeOM);
                if (consentPurpose != null) {
                    consentPurposes.add(consentPurpose);
                }
            } catch (IdentityApplicationManagementException e) {
                log.error("Error while parsing the ConsentPurpose config.", e);
            }
        }
    }
    consentPurposeConfigs.setConsentPurpose(consentPurposes.toArray(new ConsentPurpose[0]));
    return consentPurposeConfigs;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement)

Aggregations

IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)4 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)2 ConsentPurpose (org.wso2.carbon.identity.application.common.model.ConsentPurpose)2 ConsentPurposeConfigs (org.wso2.carbon.identity.application.common.model.ConsentPurposeConfigs)2 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 JAXBException (javax.xml.bind.JAXBException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 OMElement (org.apache.axiom.om.OMElement)1 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)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 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)1 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)1