org.wso2.balana.finder.PolicyFinder Java Examples

The following examples show how to use org.wso2.balana.finder.PolicyFinder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PAPPolicyReader.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private PAPPolicyReader(PolicyFinder policyFinder) {


        this.policyFinder = policyFinder;
        // create the factory
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setIgnoringComments(true);
        documentBuilderFactory.setNamespaceAware(true);
        documentBuilderFactory.setExpandEntityReferences(false);
        SecurityManager securityManager = new SecurityManager();
        securityManager.setEntityExpansionLimit(ENTITY_EXPANSION_LIMIT);
        documentBuilderFactory.setAttribute(SECURITY_MANAGER_PROPERTY, securityManager);

        // now use the factory to create the document builder
        try {
            documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            documentBuilderFactory.setFeature(EXTERNAL_GENERAL_ENTITIES_URI, false);
            builder = documentBuilderFactory.newDocumentBuilder();
            builder.setEntityResolver(new CarbonEntityResolver());
            builder.setErrorHandler(this);
        } catch (ParserConfigurationException pce) {
            throw new IllegalArgumentException("Failed to create the DocumentBuilder. : ", pce);
        }
    }
 
Example #2
Source File: PAPPolicyReader.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private PAPPolicyReader(PolicyFinder policyFinder) {

        this.policyFinder = policyFinder;

        // create the factory
        DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
        documentBuilderFactory.setIgnoringComments(true);

        // now use the factory to create the document builder
        try {
            builder = documentBuilderFactory.newDocumentBuilder();
            builder.setErrorHandler(this);
        } catch (ParserConfigurationException pce) {
            throw new IllegalArgumentException("Failed to create the DocumentBuilder. : ", pce);
        }
    }
 
Example #3
Source File: PDPConfig.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor that creates a <code>PDPConfig</code> from components.
 * 
 * @param attributeFinder the <code>AttributeFinder</code> that the PDP should use, or null if
 *            it shouldn't use any
 * @param policyFinder the <code>PolicyFinder</code> that the PDP should use, or null if it
 *            shouldn't use any
 * @param resourceFinder the <code>ResourceFinder</code> that the PDP should use, or null if it
 *            shouldn't use any
 * @param multipleRequestHandle whether PDP capable of handling multiple requests or not
 */
public PDPConfig(AttributeFinder attributeFinder, PolicyFinder policyFinder,
        ResourceFinder resourceFinder, boolean multipleRequestHandle) {
    if (attributeFinder != null)
        this.attributeFinder = attributeFinder;
    else
        this.attributeFinder = new AttributeFinder();

    if (policyFinder != null)
        this.policyFinder = policyFinder;
    else
        this.policyFinder = new PolicyFinder();

    if (resourceFinder != null)
        this.resourceFinder = resourceFinder;
    else
        this.resourceFinder = new ResourceFinder();

    this.multipleRequestHandle = multipleRequestHandle;
}
 
Example #4
Source File: BalanaPDP.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
private org.wso2.balana.PDP getPDP(IRI policyAlgorithm) {
    PDPConfig config = balana.getPdpConfig();

    PolicyFinder policyFinder = new PolicyFinder();
    Set<PolicyFinderModule> policyFinderModules = new HashSet<>();
    policyFinderModules.add(balanaPRP);
    policyFinder.setModules(policyFinderModules);

    AttributeFinder attributeFinder = new AttributeFinder();
    List<AttributeFinderModule> attributeFinderModules = new ArrayList<>(config.getAttributeFinder().getModules());
    pips.forEach(pip -> {
        MobiAttributeFinder mobiAttributeFinder = new MobiAttributeFinder(vf, pip, jaxbContext);
        attributeFinderModules.add(mobiAttributeFinder);
    });
    attributeFinder.setModules(attributeFinderModules);

    PDPConfig newConfig = new PDPConfig(attributeFinder, policyFinder, null, false);
    balanaPRP.setPDPConfig(newConfig);
    balanaPRP.setCombiningAlg(getAlgorithm(policyAlgorithm));
    return new org.wso2.balana.PDP(newConfig);
}
 
Example #5
Source File: AdvanceTestV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #6
Source File: PAPPolicyStoreReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyId
 * @param finder
 * @return
 * @throws EntitlementException
 */
public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder)
        throws EntitlementException {
    Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP);
    if (resource != null) {
        try {
            String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8"));
            return PAPPolicyReader.getInstance(null).getPolicy(policy);
        } catch (RegistryException e) {
            log.error("Error while parsing entitlement policy", e);
            throw new EntitlementException("Error while loading entitlement policy");
        }
    }
    return null;
}
 
Example #7
Source File: PolicyReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private PolicyReader(PolicyFinder policyFinder) {

        this.policyFinder = policyFinder;
        // create the factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setIgnoringComments(true);
        factory.setNamespaceAware(true);
        // now use the factory to create the document builder
        try {
            builder = factory.newDocumentBuilder();
            builder.setErrorHandler(this);
        } catch (ParserConfigurationException pce) {
            throw new IllegalArgumentException("Filed to setup repository: ");
        }
    }
 
Example #8
Source File: CarbonPolicyFinder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PolicyFinder finder) {
    initFinish = false;
    this.finder = finder;
    init();
    policyReferenceCache.clear();
}
 
Example #9
Source File: FileBasedPolicyFinderModule.java    From balana with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PolicyFinder finder) {

    this.finder = finder;
    loadPolicies();
    combiningAlg = new DenyOverridesPolicyAlg();
}
 
Example #10
Source File: ConfigurationStore.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private helper that handles the pdp elements.
 */
private PDPConfig parsePDPConfig(Node root) throws ParsingException {
    ArrayList attrModules = new ArrayList();
    HashSet policyModules = new HashSet();
    ArrayList rsrcModules = new ArrayList();

    // go through all elements of the pdp, loading the specified modules
    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        String name = DOMHelper.getLocalName(child);

        if (name.equals("policyFinderModule")) {
            policyModules.add(loadClass("module", child));
        } else if (name.equals("attributeFinderModule")) {
            attrModules.add(loadClass("module", child));
        } else if (name.equals("resourceFinderModule")) {
            rsrcModules.add(loadClass("module", child));
        }
    }

    // after loading the modules, use the collections to setup a
    // PDPConfig based on this pdp element

    AttributeFinder attrFinder = new AttributeFinder();
    attrFinder.setModules(attrModules);

    PolicyFinder policyFinder = new PolicyFinder();
    policyFinder.setModules(policyModules);

    ResourceFinder rsrcFinder = new ResourceFinder();
    rsrcFinder.setModules(rsrcModules);

    return new PDPConfig(attrFinder, policyFinder, rsrcFinder);
}
 
Example #11
Source File: PolicyReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyFinder
 * @return
 */
public static PolicyReader getInstance(PolicyFinder policyFinder) {
    if (reader == null) {
        synchronized (lock) {
            if (reader == null) {
                reader = new PolicyReader(policyFinder);
            }
        }
    }
    return reader;
}
 
Example #12
Source File: ConformanceTestV2.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), false);
    return new PDP(pdpConfig);

}
 
Example #13
Source File: ConformanceTestV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), false);
    return new PDP(pdpConfig);

}
 
Example #14
Source File: BasicTestV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #15
Source File: TestMultipleRequestV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies Set of XACML policy file names
 * @return a  PDP instance
 */

private static PDP getPDPNewInstance(Set<String> policies) {

    PolicyFinder finder = new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for (String policy : policies) {
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
            //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
            pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #16
Source File: TestFunctionV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #17
Source File: TestXPathV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies Set of XACML policy file names
 * @return a  PDP instance
 */

private static PDP getPDPNewInstance(Set<String> policies) {

    PolicyFinder finder = new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for (String policy : policies) {
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
            //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
            pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #18
Source File: TestAlgorithmsV3.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new PDP instance with new XACML policies
 *
 * @param policies  Set of XACML policy file names
 * @return a  PDP instance
 */
private static PDP getPDPNewInstance(Set<String> policies){

    PolicyFinder finder= new PolicyFinder();
    Set<String> policyLocations = new HashSet<String>();

    for(String policy : policies){
        try {
            String policyPath = (new File(".")).getCanonicalPath() + File.separator +
                    TestConstants.RESOURCE_PATH + File.separator + ROOT_DIRECTORY + File.separator +
                    VERSION_DIRECTORY + File.separator + TestConstants.POLICY_DIRECTORY +
                    File.separator + policy;
            policyLocations.add(policyPath);
        } catch (IOException e) {
           //ignore.
        }
    }

    FileBasedPolicyFinderModule testPolicyFinderModule = new FileBasedPolicyFinderModule(policyLocations);
    Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
    policyModules.add(testPolicyFinderModule);
    finder.setModules(policyModules);

    Balana balana = Balana.getInstance();
    PDPConfig pdpConfig = balana.getPdpConfig();
    pdpConfig = new PDPConfig(pdpConfig.getAttributeFinder(), finder,
                                                        pdpConfig.getResourceFinder(), true);
    return new PDP(pdpConfig);

}
 
Example #19
Source File: PAPPolicyReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyFinder
 * @return
 */
public static PAPPolicyReader getInstance(PolicyFinder policyFinder) {
    if (reader == null) {
        synchronized (lock) {
            if (reader == null) {
                reader = new PAPPolicyReader(policyFinder);
            }
        }
    }
    return reader;
}
 
Example #20
Source File: CarbonPolicyFinder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PolicyFinder finder) {
    initFinish = false;
    this.finder = finder;
    init();
    policyReferenceCache.clear();
}
 
Example #21
Source File: PolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyFinder
 * @return
 */
public static PolicyReader getInstance(PolicyFinder policyFinder) {
    if (reader == null) {
        synchronized (lock) {
            if (reader == null) {
                reader = new PolicyReader(policyFinder);
            }
        }
    }
    return reader;
}
 
Example #22
Source File: PolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private PolicyReader(PolicyFinder policyFinder) {

        this.policyFinder = policyFinder;
        // create the factory
        DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory();
        factory.setIgnoringComments(true);
        // now use the factory to create the document builder
        try {
            builder = factory.newDocumentBuilder();
            builder.setErrorHandler(this);
        } catch (ParserConfigurationException pce) {
            throw new IllegalArgumentException("Filed to setup repository: ");
        }
    }
 
Example #23
Source File: PAPPolicyStoreReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyId
 * @param finder
 * @return
 * @throws EntitlementException
 */
public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder)
        throws EntitlementException {
    Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP);
    if (resource != null) {
        try {
            String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8"));
            return PAPPolicyReader.getInstance(null).getPolicy(policy);
        } catch (RegistryException e) {
            log.error("Error while parsing entitlement policy", e);
            throw new EntitlementException("Error while loading entitlement policy");
        }
    }
    return null;
}
 
Example #24
Source File: PAPPolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param policyFinder
 * @return
 */
public static PAPPolicyReader getInstance(PolicyFinder policyFinder) {
    if (reader == null) {
        synchronized (lock) {
            if (reader == null) {
                reader = new PAPPolicyReader(policyFinder);
            }
        }
    }
    return reader;
}
 
Example #25
Source File: EntitlementEngine.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void setUPPolicyFinder() {

        carbonPolicyFinder = new PolicyFinder();
        Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
        CarbonPolicyFinder tmpCarbonPolicyFinder = new CarbonPolicyFinder();
        policyModules.add(tmpCarbonPolicyFinder);
        carbonPolicyFinder.setModules(policyModules);
        carbonPolicyFinder.init();

    }
 
Example #26
Source File: EntitlementEngine.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void setUPPolicyFinder() {

        carbonPolicyFinder = new PolicyFinder();
        Set<PolicyFinderModule> policyModules = new HashSet<PolicyFinderModule>();
        CarbonPolicyFinder tmpCarbonPolicyFinder = new CarbonPolicyFinder();
        policyModules.add(tmpCarbonPolicyFinder);
        carbonPolicyFinder.setModules(policyModules);
        carbonPolicyFinder.init();

    }
 
Example #27
Source File: PolicySet.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new PolicySet based on the given root node. This is private since every class is
 * supposed to use a getInstance() method to construct from a Node, but since we want some
 * common code in the parent class, we need this functionality in a constructor.
 *
 * @param root  the node to parse for the <code>PolicySet</code>
 * @param finder the <code>PolicyFinder</code> used to handle references
 * the XACML policy, if null use default factories
 * @throws ParsingException ParsingException if the PolicyType is invalid
 */
private PolicySet(Node root, PolicyFinder finder) throws ParsingException {
    
    super(root, "PolicySet", "PolicyCombiningAlgId");

    List<AbstractPolicy> policies = new ArrayList<AbstractPolicy>();
    HashMap<String, List<CombinerParameter>> policyParameters =
                                            new HashMap<String, List<CombinerParameter>>();
    HashMap<String, List<CombinerParameter>> policySetParameters =
                                            new HashMap<String, List<CombinerParameter>>();
    PolicyMetaData metaData = getMetaData();

    // collect the PolicySet-specific elements
    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        String name = DOMHelper.getLocalName(child);

        if (name.equals("PolicySet")) {
            policies.add(PolicySet.getInstance(child, finder));
        } else if (name.equals("Policy")) {
            policies.add(Policy.getInstance(child));
        } else if (name.equals("PolicySetIdReference")) {
            policies.add(PolicyReference.getInstance(child, finder, metaData));
        } else if (name.equals("PolicyIdReference")) {
            policies.add(PolicyReference.getInstance(child, finder, metaData));
        } else if (name.equals("PolicyCombinerParameters")) {
            parameterHelper(policyParameters, child, "Policy");
        } else if (name.equals("PolicySetCombinerParameters")) {
            parameterHelper(policySetParameters, child, "PolicySet");
        }
    }

    // now make sure that we can match up any parameters we may have
    // found to a corresponding Policy or PolicySet...
    List<CombinerElement> elements = new ArrayList<CombinerElement>();
    Iterator it = policies.iterator();

    // right now we have to go though each policy and based on several
    // possible cases figure out what parameters might apply...but
    // there should be a better way to do this

    while (it.hasNext()) {
        AbstractPolicy policy = (AbstractPolicy) (it.next());
        List<CombinerParameter> list = null;

        if (policy instanceof Policy) {
            list = policyParameters.remove(policy.getId().toString());
        } else if (policy instanceof PolicySet) {
            list = policySetParameters.remove(policy.getId().toString());
        } else {
            PolicyReference ref = (PolicyReference) policy;
            String id = ref.getReference().toString();
            if (ref.getReferenceType() == PolicyReference.POLICY_REFERENCE){
                list = policyParameters.remove(id);
            } else {
                list = policySetParameters.remove(id);
            }
        }

        elements.add(new PolicyCombinerElement(policy, list));
    }

    // ...and that there aren't extra parameters
    if (!policyParameters.isEmpty()) {
        throw new ParsingException("Unmatched parameters in Policy");
    }
    
    if (!policySetParameters.isEmpty()){
        throw new ParsingException("Unmatched parameters in PolicySet");
    }
    // finally, set the list of Rules
    setChildren(elements);
}
 
Example #28
Source File: PAPPolicyReader.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public PolicyFinder getPolicyFinder() {
    return policyFinder;
}
 
Example #29
Source File: PolicyReader.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public PolicyFinder getPolicyFinder() {
    return policyFinder;
}
 
Example #30
Source File: PAPPolicyReader.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public PolicyFinder getPolicyFinder() {
    return policyFinder;
}