Search in sources :

Example 1 with PolicyFinderModule

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());
}
Also used : DefaultPolicyDataStore(org.wso2.carbon.identity.entitlement.policy.store.DefaultPolicyDataStore) PolicyDataStore(org.wso2.carbon.identity.entitlement.policy.store.PolicyDataStore) PolicyCollection(org.wso2.carbon.identity.entitlement.policy.collection.PolicyCollection) SimplePolicyCollection(org.wso2.carbon.identity.entitlement.policy.collection.SimplePolicyCollection) Properties(java.util.Properties) URI(java.net.URI) PolicyCombiningAlgorithm(org.wso2.balana.combine.PolicyCombiningAlgorithm) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) PolicyDTO(org.wso2.carbon.identity.entitlement.dto.PolicyDTO) AbstractPolicy(org.wso2.balana.AbstractPolicy) SimplePolicyCollection(org.wso2.carbon.identity.entitlement.policy.collection.SimplePolicyCollection) DefaultPolicyDataStore(org.wso2.carbon.identity.entitlement.policy.store.DefaultPolicyDataStore) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with PolicyFinderModule

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;
}
Also used : PolicyFinderModule(org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule) PolicyFinderDataHolder(org.wso2.carbon.identity.entitlement.dto.PolicyFinderDataHolder) Properties(java.util.Properties) Map(java.util.Map)

Example 3 with PolicyFinderModule

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);
    }
}
Also used : PolicyStoreManageModule(org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManageModule) PolicyFinderModule(org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule) Properties(java.util.Properties)

Example 4 with PolicyFinderModule

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;
}
Also used : PIPAttributeFinder(org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder) AbstractPIPAttributeFinder(org.wso2.carbon.identity.entitlement.pip.AbstractPIPAttributeFinder) PDPDataHolder(org.wso2.carbon.identity.entitlement.dto.PDPDataHolder) ArrayList(java.util.ArrayList) Properties(java.util.Properties) PolicyFinderModule(org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule) Map(java.util.Map) PIPResourceFinder(org.wso2.carbon.identity.entitlement.pip.PIPResourceFinder)

Example 5 with PolicyFinderModule

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();
}
Also used : CarbonPolicyFinder(org.wso2.carbon.identity.entitlement.policy.finder.CarbonPolicyFinder) PolicyFinderModule(org.wso2.balana.finder.PolicyFinderModule) PolicyFinder(org.wso2.balana.finder.PolicyFinder) CarbonPolicyFinder(org.wso2.carbon.identity.entitlement.policy.finder.CarbonPolicyFinder) PAPPolicyFinder(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyFinder) HashSet(java.util.HashSet)

Aggregations

PolicyFinderModule (org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule)5 Map (java.util.Map)4 Properties (java.util.Properties)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)2 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)2 AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)2 EntitledAttributesDTO (org.wso2.carbon.identity.entitlement.dto.EntitledAttributesDTO)2 EntitledResultSetDTO (org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AbstractPolicy (org.wso2.balana.AbstractPolicy)1 PolicyCombiningAlgorithm (org.wso2.balana.combine.PolicyCombiningAlgorithm)1 PolicyFinder (org.wso2.balana.finder.PolicyFinder)1 PolicyFinderModule (org.wso2.balana.finder.PolicyFinderModule)1