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);
}
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);
}
}
}
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;
}
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;
}
Aggregations