Skip to content

Commit

Permalink
Merge pull request #5686 from Niru-D/xacml-dao-registry-implementatio…
Browse files Browse the repository at this point in the history
…n-v2

Add XACML DAO Interfaces
  • Loading branch information
Yoshani authored Jun 25, 2024
2 parents 802cd6d + ae6f353 commit 098dcdf
Show file tree
Hide file tree
Showing 37 changed files with 2,294 additions and 2,533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ public void uploadPolicy(String content) throws AxisFault {
/**
* Import XACML policy from registry
*
* @deprecated since the functionality cannot be support by the rdbms based implementation
* @param policyRegistryPath registry path
* @throws AxisFault
*/
@Deprecated
public void importPolicyFromRegistry(String policyRegistryPath) throws AxisFault {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.entitlement.dao.ConfigDAO;
import org.wso2.carbon.identity.entitlement.dto.PDPDataHolder;
import org.wso2.carbon.identity.entitlement.dto.PIPFinderDataHolder;
import org.wso2.carbon.identity.entitlement.dto.PolicyFinderDataHolder;
Expand Down Expand Up @@ -527,8 +528,8 @@ public PIPFinderDataHolder getPIPResourceFinderData(String finder) {
*/
public String getGlobalPolicyAlgorithm() throws EntitlementException {

return EntitlementAdminEngine.getInstance().
getPolicyDataStore().getGlobalPolicyAlgorithmName();
ConfigDAO configDAO = EntitlementAdminEngine.getInstance().getConfigDAO();
return configDAO.getGlobalPolicyAlgorithmName();
}

/**
Expand All @@ -539,7 +540,8 @@ public String getGlobalPolicyAlgorithm() throws EntitlementException {
*/
public void setGlobalPolicyAlgorithm(String policyCombiningAlgorithm) throws EntitlementException {

EntitlementAdminEngine.getInstance().
getPolicyDataStore().setGlobalPolicyAlgorithm(policyCombiningAlgorithm);
ConfigDAO configDAO = EntitlementAdminEngine.getInstance().getConfigDAO();
configDAO.setGlobalPolicyAlgorithm(policyCombiningAlgorithm);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.identity.entitlement.common.EntitlementConstants;
import org.wso2.carbon.identity.entitlement.dao.PolicyDAO;
import org.wso2.carbon.identity.entitlement.dao.SubscriberDAO;
import org.wso2.carbon.identity.entitlement.dto.AttributeDTO;
import org.wso2.carbon.identity.entitlement.dto.EntitlementFinderDataHolder;
import org.wso2.carbon.identity.entitlement.dto.EntitlementTreeNodeDTO;
Expand All @@ -40,7 +42,6 @@
import org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager;
import org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher;
import org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisherModule;
import org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
Expand Down Expand Up @@ -99,9 +100,9 @@ public void addPolicies(PolicyDTO[] policies) throws EntitlementException {
/**
* This method finds the policy file from given registry path and adds the policy
*
* @deprecated since the functionality cannot be support by the rdbms based implementation
* @param policyRegistryPath given registry path
* @throws org.wso2.carbon.identity.entitlement.EntitlementException throws when fails or registry error
* occurs
* @throws org.wso2.carbon.identity.entitlement.EntitlementException throws when fails or registry error occurs
*/
public void importPolicyFromRegistry(String policyRegistryPath) throws EntitlementException {

Expand All @@ -114,7 +115,7 @@ public void importPolicyFromRegistry(String policyRegistryPath) throws Entitleme
// Finding from which registry by comparing prefix of resource path
String resourceUri = policyRegistryPath.substring(policyRegistryPath.lastIndexOf(':') + 1);
String registryIdentifier = policyRegistryPath.substring(0,
policyRegistryPath.lastIndexOf(':'));
policyRegistryPath.lastIndexOf(':'));
if ("conf".equals(registryIdentifier)) {
registry = (Registry) CarbonContext.getThreadLocalCarbonContext().
getRegistry(RegistryType.SYSTEM_CONFIGURATION);
Expand Down Expand Up @@ -288,8 +289,8 @@ public PolicyDTO getPolicyByVersion(String policyId, String version) throws Enti
PolicyDTO policyDTO = null;

try {
PolicyVersionManager versionManager = EntitlementAdminEngine.getInstance().getVersionManager();
policyDTO = versionManager.getPolicy(policyId, version);
PolicyDAO policyStore = EntitlementAdminEngine.getInstance().getPolicyDAO();
policyDTO = policyStore.getPolicy(policyId, version);
} catch (EntitlementException e) {
policyDTO = new PolicyDTO();
policyDTO.setPolicy(policyId);
Expand Down Expand Up @@ -369,9 +370,6 @@ public void removePolicy(String policyId, boolean dePromote) throws EntitlementE
}
handleStatus(EntitlementConstants.StatusTypes.DELETE_POLICY, oldPolicy, true, null);

//remove versions
EntitlementAdminEngine.getInstance().getVersionManager().deletePolicy(policyId);

// policy remove from PDP. this is done by separate thread
if (dePromote) {
publishToPDP(new String[]{policyId}, null,
Expand Down Expand Up @@ -425,8 +423,8 @@ public String[] getAllPolicyIds(String searchString) throws EntitlementException
*/
public PublisherDataHolder getSubscriber(String subscribeId) throws EntitlementException {

PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
return publisher.retrieveSubscriber(subscribeId, false);
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
return subscriberManager.getSubscriber(subscribeId, false);
}

/**
Expand All @@ -437,9 +435,9 @@ public PublisherDataHolder getSubscriber(String subscribeId) throws EntitlementE
* @throws EntitlementException throws, if fails
*/
public String[] getSubscriberIds(String searchString) throws EntitlementException {
PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
String[] ids = publisher.retrieveSubscriberIds(searchString);
if (ids != null) {
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
String[] ids = subscriberManager.listSubscriberIds(searchString).toArray(new String[0]);
if (ids.length != 0) {
return ids;
} else {
return new String[0];
Expand All @@ -454,8 +452,8 @@ public String[] getSubscriberIds(String searchString) throws EntitlementExceptio
*/
public void addSubscriber(PublisherDataHolder holder) throws EntitlementException {

PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
publisher.persistSubscriber(holder, false);
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
subscriberManager.addSubscriber(holder);

}

Expand All @@ -467,8 +465,8 @@ public void addSubscriber(PublisherDataHolder holder) throws EntitlementExceptio
*/
public void updateSubscriber(PublisherDataHolder holder) throws EntitlementException {

PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
publisher.persistSubscriber(holder, true);
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
subscriberManager.updateSubscriber(holder);

}

Expand All @@ -480,8 +478,8 @@ public void updateSubscriber(PublisherDataHolder holder) throws EntitlementExcep
*/
public void deleteSubscriber(String subscriberId) throws EntitlementException {

PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
publisher.deleteSubscriber(subscriberId);
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
subscriberManager.removeSubscriber(subscriberId);

}

Expand All @@ -504,14 +502,15 @@ public void publishPolicies(String[] policyIds, String[] subscriberIds, String a
policyIds = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager().getPolicyIds();
}
if (subscriberIds == null || subscriberIds.length < 1) {
subscriberIds = publisher.retrieveSubscriberIds("*");
SubscriberDAO subscriberManager = EntitlementAdminEngine.getInstance().getSubscriberDAO();
subscriberIds = subscriberManager.listSubscriberIds("*").toArray(new String[0]);
}

if (policyIds == null || policyIds.length < 1) {
throw new EntitlementException("There are no policies to publish");
}

if (subscriberIds == null || subscriberIds.length < 1) {
if (subscriberIds.length < 1) {
throw new EntitlementException("There are no subscribers to publish");
}

Expand Down Expand Up @@ -561,8 +560,8 @@ public void publishToPDP(String[] policyIds, String action, String version, bool
*/
public void rollBackPolicy(String policyId, String version) throws EntitlementException {

PolicyVersionManager versionManager = EntitlementAdminEngine.getInstance().getVersionManager();
PolicyDTO policyDTO = versionManager.getPolicy(policyId, version);
PolicyDAO policyStore = EntitlementAdminEngine.getInstance().getPolicyDAO();
PolicyDTO policyDTO = policyStore.getPolicy(policyId, version);
addOrUpdatePolicy(policyDTO, false);

}
Expand Down Expand Up @@ -641,7 +640,8 @@ public EntitlementFinderDataHolder[] getEntitlementDataModules() {
*/
public String[] getPolicyVersions(String policyId) throws EntitlementException {

String[] versions = EntitlementAdminEngine.getInstance().getVersionManager().getVersions(policyId);
PolicyDAO policyStore = EntitlementAdminEngine.getInstance().getPolicyDAO();
String[] versions = policyStore.getVersions(policyId);
if(versions == null){
throw new EntitlementException("Error obtaining policy versions");
}
Expand All @@ -658,7 +658,7 @@ public void orderPolicy(String policyId, int newOrder) throws EntitlementExcepti
PAPPolicyStoreManager storeManager = EntitlementAdminEngine.
getInstance().getPapPolicyStoreManager();
if (storeManager.isExistPolicy(policyId)) {
storeManager.addOrUpdatePolicy(policyDTO);
storeManager.addOrUpdatePolicy(policyDTO, false);
}
publishToPDP(new String[]{policyDTO.getPolicyId()}, EntitlementConstants.PolicyPublish.ACTION_ORDER, null,
false, newOrder);
Expand All @@ -672,7 +672,7 @@ public void enableDisablePolicy(String policyId, boolean enable) throws Entitlem
PAPPolicyStoreManager storeManager = EntitlementAdminEngine.
getInstance().getPapPolicyStoreManager();
if (storeManager.isExistPolicy(policyId)) {
storeManager.addOrUpdatePolicy(policyDTO);
storeManager.addOrUpdatePolicy(policyDTO, false);
}

if (enable) {
Expand Down Expand Up @@ -713,7 +713,6 @@ private void addOrUpdatePolicy(PolicyDTO policyDTO, boolean isAdd) throws Entitl
}

PAPPolicyStoreManager policyAdmin = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager();
PolicyVersionManager versionManager = EntitlementAdminEngine.getInstance().getVersionManager();

AbstractPolicy policyObj;
String policyId = null;
Expand Down Expand Up @@ -764,14 +763,8 @@ private void addOrUpdatePolicy(PolicyDTO policyDTO, boolean isAdd) throws Entitl
} else {
throw new EntitlementException("Unsupported Entitlement Policy. Policy can not be parsed");
}
try {
String version = versionManager.createVersion(policyDTO);
policyDTO.setVersion(version);
} catch (EntitlementException e) {
log.error("Policy versioning is not supported", e);
}
}
policyAdmin.addOrUpdatePolicy(policyDTO);
policyAdmin.addOrUpdatePolicy(policyDTO, true);
} catch (EntitlementException e) {
handleStatus(operation, policyDTO, false, e.getMessage());
throw e;
Expand Down
Loading

0 comments on commit 098dcdf

Please sign in to comment.