Search in sources :

Example 1 with Purpose

use of org.wso2.carbon.consent.mgt.core.model.Purpose in project carbon-apimgt by wso2.

the class APIUtil method getExternalIDPOrigin.

/**
 * Get the External IDP host name when UIs use an external IDP for SSO or other purpose
 * By default this is equal to $ref{server.base_path} (i:e https://localhost:9443)
 *
 * @return Origin string of the external IDP
 */
public static String getExternalIDPOrigin() throws APIManagementException {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String idpEndpoint = config.getFirstProperty(APIConstants.IDENTITY_PROVIDER_SERVER_URL);
    if (idpEndpoint == null) {
        return getServerURL();
    } else {
        return idpEndpoint;
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 2 with Purpose

use of org.wso2.carbon.consent.mgt.core.model.Purpose in project carbon-identity-framework by wso2.

the class ConsentUtilityService method getMandatoryPIIs.

/**
 * Returns the set of mandatory PIIs of a given set of purposes.
 *
 * @param purposes List of purposes.
 * @return Set of Mandatory PIIs.
 * @throws ConsentUtilityServiceException
 */
public Set<Integer> getMandatoryPIIs(List<Purpose> purposes) throws ConsentUtilityServiceException {
    if (purposes == null) {
        throw new ConsentUtilityServiceException("Purposes list should not be null");
    }
    Set<Integer> mandatoryPIIs = new HashSet<>();
    for (Purpose purpose : purposes) {
        Set<Integer> mandatoryPurposePIIs = getMandatoryPIIs(purpose);
        mandatoryPIIs.addAll(mandatoryPurposePIIs);
    }
    return mandatoryPIIs;
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) HashSet(java.util.HashSet)

Example 3 with Purpose

use of org.wso2.carbon.consent.mgt.core.model.Purpose 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 4 with Purpose

use of org.wso2.carbon.consent.mgt.core.model.Purpose 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 5 with Purpose

use of org.wso2.carbon.consent.mgt.core.model.Purpose in project carbon-identity-framework by wso2.

the class ConsentPurpose method build.

/**
 * Build ConsentPurpose from ConsentPurpose OM element.
 *
 * @param consentPurposeOM ConsentPurpose OM element.
 * @return ConsentPurpose object.
 */
public static ConsentPurpose build(OMElement consentPurposeOM) throws IdentityApplicationManagementException {
    ConsentPurpose consentPurpose = new ConsentPurpose();
    if (consentPurposeOM == null) {
        return consentPurpose;
    }
    Iterator<?> children = consentPurposeOM.getChildElements();
    while (children.hasNext()) {
        OMElement member = (OMElement) children.next();
        if (PURPOSE_ID_ELEM.equals(member.getLocalName())) {
            try {
                consentPurpose.setPurposeId(Integer.parseInt(member.getText()));
            } catch (NumberFormatException e) {
                log.warn("PurposeID should be an Integer. Found: " + member.getText() + " instead.");
                throw new IdentityApplicationManagementException("Invalid purpose ID: " + member.getText(), e);
            }
        } else {
            if (DISPLAY_ORDER_ELEM.equals(member.getLocalName())) {
                try {
                    consentPurpose.setDisplayOrder(Integer.parseInt(member.getText()));
                } catch (NumberFormatException e) {
                    log.warn("DisplayOrder should be an Integer. Found: " + member.getText() + " instead. Setting " + "default display order: " + DEFAULT_DISPLAY_ORDER);
                    consentPurpose.setDisplayOrder(DEFAULT_DISPLAY_ORDER);
                }
            }
        }
    }
    return consentPurpose;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) OMElement(org.apache.axiom.om.OMElement)

Aggregations

Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)7 HashMap (java.util.HashMap)5 JSONObject (org.json.JSONObject)5 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)5 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)5 ConsentUtilityServiceException (org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)4 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 JSONArray (org.json.JSONArray)3 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)3 PurposeCategory (org.wso2.carbon.consent.mgt.core.model.PurposeCategory)3 PurposePIICategory (org.wso2.carbon.consent.mgt.core.model.PurposePIICategory)3 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)3 Resource (org.apache.wink.client.Resource)2 RestClient (org.apache.wink.client.RestClient)2 JSONObject (org.json.simple.JSONObject)2 Test (org.testng.annotations.Test)2