use of org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule in project carbon-identity-framework by wso2.
the class CarbonPolicyFinder method init.
private synchronized void init() {
if (initFinish) {
return;
}
log.info("Initializing of policy store is started at : " + new Date());
String maxEntries = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties().getProperty(PDPConstants.MAX_POLICY_REFERENCE_ENTRIES);
if (maxEntries != null) {
try {
maxReferenceCacheEntries = Integer.parseInt(maxEntries.trim());
} catch (Exception e) {
// ignore
}
}
policyReferenceCache = new LinkedHashMap<URI, AbstractPolicy>() {
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
// oldest entry of the cache would be removed when max cache size become, i.e 50
return size() > maxReferenceCacheEntries;
}
};
PolicyCombiningAlgorithm policyCombiningAlgorithm = null;
// get registered finder modules
Map<PolicyFinderModule, Properties> finderModules = EntitlementServiceComponent.getEntitlementConfig().getPolicyFinderModules();
if (finderModules != null) {
this.finderModules = new ArrayList<PolicyFinderModule>(finderModules.keySet());
}
PolicyCollection tempPolicyCollection = null;
// get policy collection
Map<PolicyCollection, Properties> policyCollections = EntitlementServiceComponent.getEntitlementConfig().getPolicyCollections();
if (policyCollections != null && policyCollections.size() > 0) {
tempPolicyCollection = policyCollections.entrySet().iterator().next().getKey();
} else {
tempPolicyCollection = new SimplePolicyCollection();
}
// get policy reader
policyReader = PolicyReader.getInstance(finder);
if (this.finderModules != null && this.finderModules.size() > 0) {
// find policy combining algorithm.
// 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();
}
policyCombiningAlgorithm = policyDataStore.getGlobalPolicyAlgorithm();
tempPolicyCollection.setPolicyCombiningAlgorithm(policyCombiningAlgorithm);
for (PolicyFinderModule finderModule : this.finderModules) {
log.info("Start retrieving policies from " + finderModule + " at : " + new Date());
String[] policies = finderModule.getActivePolicies();
for (int a = 0; a < policies.length; a++) {
String policy = policies[a];
AbstractPolicy abstractPolicy = policyReader.getPolicy(policy);
if (abstractPolicy != null) {
PolicyDTO policyDTO = new PolicyDTO();
policyDTO.setPolicyId(abstractPolicy.getId().toString());
policyDTO.setPolicyOrder(a);
policyCollectionOrder.add(policyDTO);
tempPolicyCollection.addPolicy(abstractPolicy);
}
}
log.info("Finish retrieving policies from " + finderModule + " at : " + new Date());
}
} else {
log.warn("No Carbon policy finder modules are registered");
}
policyCollection = tempPolicyCollection;
initFinish = true;
log.info("Initializing of policy store is finished at : " + new Date());
}
use of org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule in project carbon-identity-framework by wso2.
the class EntitlementAdminService method getPolicyFinderData.
/**
* @param finder
* @return
*/
public PolicyFinderDataHolder getPolicyFinderData(String finder) {
PolicyFinderDataHolder holder = null;
// get registered finder modules
Map<PolicyFinderModule, Properties> finderModules = EntitlementServiceComponent.getEntitlementConfig().getPolicyFinderModules();
if (finderModules == null || finder == null) {
return null;
}
for (Map.Entry<PolicyFinderModule, Properties> entry : finderModules.entrySet()) {
PolicyFinderModule module = entry.getKey();
if (module != null && (finder.equals(module.getModuleName()) || finder.equals(module.getClass().getName()))) {
holder = new PolicyFinderDataHolder();
if (module.getModuleName() != null) {
holder.setModuleName(module.getModuleName());
} else {
holder.setModuleName(module.getClass().getName());
}
holder.setClassName(module.getClass().getName());
holder.setPolicyIdentifiers(module.getOrderedPolicyIdentifiers());
break;
}
}
return holder;
}
use of org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule in project carbon-identity-framework by wso2.
the class EntitlementExtensionBuilder method populatePolicyFinders.
/**
* @param properties
* @param holder
* @throws Exception
*/
private void populatePolicyFinders(Properties properties, EntitlementConfigHolder holder) throws Exception {
int i = 1;
PolicyFinderModule finderModule = null;
while (properties.getProperty("PDP.Policy.Finder." + i) != null) {
String className = properties.getProperty("PDP.Policy.Finder." + i++);
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
finderModule = (PolicyFinderModule) clazz.newInstance();
int j = 1;
Properties finderModuleProps = new Properties();
while (properties.getProperty(className + "." + j) != null) {
String[] props = properties.getProperty(className + "." + j++).split(",");
finderModuleProps.put(props[0], props[1]);
}
finderModule.init(finderModuleProps);
if (finderModule instanceof PolicyStoreManageModule) {
holder.addPolicyStore((PolicyStoreManageModule) finderModule, finderModuleProps);
}
holder.addPolicyFinderModule(finderModule, finderModuleProps);
}
}
use of org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule in project carbon-identity-framework by wso2.
the class EntitlementAdminService method getPDPData.
/**
* @return
*/
public PDPDataHolder getPDPData() {
PDPDataHolder pdpDataHolder = new PDPDataHolder();
Map<PolicyFinderModule, Properties> finderModules = EntitlementServiceComponent.getEntitlementConfig().getPolicyFinderModules();
Map<PIPAttributeFinder, Properties> attributeModules = EntitlementServiceComponent.getEntitlementConfig().getDesignators();
Map<PIPResourceFinder, Properties> resourceModules = EntitlementServiceComponent.getEntitlementConfig().getResourceFinders();
if (finderModules != null) {
List<String> list = new ArrayList<String>();
for (Map.Entry<PolicyFinderModule, Properties> entry : finderModules.entrySet()) {
PolicyFinderModule module = entry.getKey();
if (module != null) {
if (module.getModuleName() != null) {
list.add(module.getModuleName());
} else {
list.add(module.getClass().getName());
}
}
}
pdpDataHolder.setPolicyFinders(list.toArray(new String[list.size()]));
}
if (attributeModules != null) {
List<String> list = new ArrayList<String>();
for (Map.Entry<PIPAttributeFinder, Properties> entry : attributeModules.entrySet()) {
PIPAttributeFinder module = entry.getKey();
if (module != null) {
if (module.getModuleName() != null) {
list.add(module.getModuleName());
} else {
list.add(module.getClass().getName());
}
}
}
pdpDataHolder.setPipAttributeFinders(list.toArray(new String[list.size()]));
}
if (resourceModules != null) {
List<String> list = new ArrayList<String>();
for (Map.Entry<PIPResourceFinder, Properties> entry : resourceModules.entrySet()) {
PIPResourceFinder module = entry.getKey();
if (module != null) {
if (module.getModuleName() != null) {
list.add(module.getModuleName());
} else {
list.add(module.getClass().getName());
}
}
}
pdpDataHolder.setPipResourceFinders(list.toArray(new String[list.size()]));
}
return pdpDataHolder;
}
use of org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule in project carbon-identity-framework by wso2.
the class EntitlementEngine method setUPPolicyFinder.
private void setUPPolicyFinder() {
carbonPolicyFinder = new PolicyFinder();
Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
CarbonPolicyFinder tmpCarbonPolicyFinder = new CarbonPolicyFinder();
policyModules.add(tmpCarbonPolicyFinder);
carbonPolicyFinder.setModules(policyModules);
carbonPolicyFinder.init();
}
Aggregations