Skip to content

Commit

Permalink
Remove pluggability of version manager and data store
Browse files Browse the repository at this point in the history
  • Loading branch information
Niru-D committed May 7, 2024
1 parent 08818c1 commit 517da62
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisherModule;
import org.wso2.carbon.identity.entitlement.policy.publisher.PostPublisherModule;
import org.wso2.carbon.identity.entitlement.policy.publisher.PublisherVerificationModule;
import org.wso2.carbon.identity.entitlement.policy.store.PolicyDataStore;
import org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManageModule;
import org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager;
import org.wso2.carbon.utils.ConfigurationContextService;

import java.util.ArrayList;
Expand Down Expand Up @@ -114,20 +112,6 @@ public class EntitlementConfigHolder {
private Map<PolicyStoreManageModule, Properties> policyStore =
new HashMap<PolicyStoreManageModule, Properties>();

/**
* This holds all the policy versioning of PAP
*/
private Map<PolicyDataStore, Properties> policyDataStore =
new HashMap<PolicyDataStore, Properties>();


/**
* This holds all the policy storing logic of entitlement engine
*/
private Map<PolicyVersionManager, Properties> policyVersionModule =
new HashMap<PolicyVersionManager, Properties>();


/**
* This holds the policy schema against its version
*/
Expand Down Expand Up @@ -278,22 +262,6 @@ public void addNotificationHandler(PAPStatusDataHandler notificationHandler,
this.papStatusDataHandlers.put(notificationHandler, properties);
}

public Map<PolicyVersionManager, Properties> getPolicyVersionModule() {
return policyVersionModule;
}

public void addPolicyVersionModule(PolicyVersionManager policyVersionModule, Properties properties) {
this.policyVersionModule.put(policyVersionModule, properties);
}

public Map<PolicyDataStore, Properties> getPolicyDataStore() {
return policyDataStore;
}

public void addPolicyDataStore(PolicyDataStore policyDataStore, Properties properties) {
this.policyDataStore.put(policyDataStore, properties);
}

public ConfigurationContextService getConfigurationContextService() {
return configurationContextService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
import org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisherModule;
import org.wso2.carbon.identity.entitlement.policy.publisher.PostPublisherModule;
import org.wso2.carbon.identity.entitlement.policy.publisher.PublisherVerificationModule;
import org.wso2.carbon.identity.entitlement.policy.store.PolicyDataStore;
import org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManageModule;
import org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -109,8 +106,6 @@ public void buildEntitlementConfig(EntitlementConfigHolder holder) throws Except
populatePolicyFinders(properties, holder);
populatePolicyCollection(properties, holder);
populatePolicyStoreModule(properties, holder);
populatePolicyDataStore(properties, holder);
populatePolicyVersionModule(properties, holder);
populatePolicyPostPublishers(properties, holder);
populateAdminNotificationHandlers(properties, holder);
populatePublisherVerificationHandler(properties, holder);
Expand Down Expand Up @@ -397,33 +392,6 @@ private void populatePolicyStoreModule(Properties properties, EntitlementConfigH
}
}

/**
* @param properties
* @param holder
* @throws Exception
*/
private void populatePolicyDataStore(Properties properties, EntitlementConfigHolder holder)
throws Exception {

PolicyDataStore policyDataStore = null;

if (properties.getProperty("PDP.Policy.Data.Store.Module") != null) {
String className = properties.getProperty("PDP.Policy.Data.Store.Module");
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
policyDataStore = (PolicyDataStore) clazz.newInstance();

int j = 1;
Properties storeProps = new Properties();
while (properties.getProperty(className + "." + j) != null) {
String[] props = properties.getProperty(className + "." + j++).split(",");
storeProps.put(props[0], props[1]);
}

policyDataStore.init(storeProps);
holder.addPolicyDataStore(policyDataStore, storeProps);
}
}

/**
* @param properties
* @param holder
Expand Down Expand Up @@ -481,34 +449,6 @@ private void populatePolicyPublishers(Properties properties, EntitlementConfigHo
}
}

/**
* @param properties
* @param holder
* @throws Exception
*/
private void populatePolicyVersionModule(Properties properties, EntitlementConfigHolder holder)
throws Exception {

PolicyVersionManager versionManager = null;

if (properties.getProperty("PAP.Policy.Version.Module") != null) {
String className = properties.getProperty("PAP.Policy.Version.Module");
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
versionManager = (PolicyVersionManager) clazz.newInstance();

int j = 1;
Properties storeProps = new Properties();
while (properties.getProperty(className + "." + j) != null) {
String[] props = properties.getProperty(className + "." + j++).split(",");
storeProps.put(props[0], props[1]);
}

versionManager.init(storeProps);
holder.addPolicyVersionModule(versionManager, storeProps);
}

}

/**
* @param properties
* @param holder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,8 @@ public EntitlementAdminEngine() {
this.entitlementDataFinder = new EntitlementDataFinder();
this.policyPublisher = new PolicyPublisher();
this.papPolicyStoreManager = new PAPPolicyStoreManager();
Map<PolicyVersionManager, Properties> versionManagers = EntitlementServiceComponent.
getEntitlementConfig().getPolicyVersionModule();
if (versionManagers != null && versionManagers.size() > 0) {
this.versionManager = versionManagers.entrySet().iterator().next().getKey();
} else {
//init without init()
this.versionManager = new DefaultPolicyVersionManager();
}
Map<PolicyDataStore, Properties> dataStoreModules = EntitlementServiceComponent.
getEntitlementConfig().getPolicyDataStore();
if (dataStoreModules != null && dataStoreModules.size() > 0) {
this.policyDataStore = dataStoreModules.entrySet().iterator().next().getKey();
} else {
//init without init()
this.policyDataStore = new DefaultPolicyDataStore();
}
this.versionManager = new DefaultPolicyVersionManager();
this.policyDataStore = new DefaultPolicyDataStore();

Map<PAPStatusDataHandler, Properties> statusDataHandlers = EntitlementServiceComponent.
getEntitlementConfig().getPapStatusDataHandlers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,8 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
// here we can get policy data store by using EntitlementAdminEngine. But we are not
// use it here. As we need not to have a dependant on EntitlementAdminEngine
PolicyDataStore policyDataStore;
Map<PolicyDataStore, Properties> dataStoreModules = EntitlementServiceComponent.
getEntitlementConfig().getPolicyDataStore();
if (dataStoreModules != null && dataStoreModules.size() > 0) {
policyDataStore = dataStoreModules.entrySet().iterator().next().getKey();
} else {
policyDataStore = new DefaultPolicyDataStore();
}
policyDataStore = new DefaultPolicyDataStore();

policyCombiningAlgorithm = policyDataStore.getGlobalPolicyAlgorithm();

tempPolicyCollection.setPolicyCombiningAlgorithm(policyCombiningAlgorithm);
Expand Down

0 comments on commit 517da62

Please sign in to comment.