org.wso2.balana.PolicyMetaData Java Examples

The following examples show how to use org.wso2.balana.PolicyMetaData. 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: ObligationExpressions.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * creates a <code>ObligationExpressions</code> based on its DOM node.
 *
 * @param root root the node to parse for the ObligationExpressions
 * @param metaData meta-date associated with the policy
 * @return  a new <code>ObligationExpressions</code> constructed by parsing
 * @throws ParsingException if the DOM node is invalid
 */
public static ObligationExpressions getInstance(Node root, PolicyMetaData metaData) throws ParsingException {

    Set<ObligationExpression> obligationExpressions = new HashSet<ObligationExpression>();

    NodeList children = root.getChildNodes();

    for(int i = 0; i < children.getLength(); i ++){
        Node child = children.item(i);
        if("ObligationExpression".equals(DOMHelper.getLocalName(child))){
            obligationExpressions.add(ObligationExpression.getInstance(child, metaData));    
        }
    }

    if(obligationExpressions.isEmpty()){
        throw new ParsingException("ObligationExpressions must contain at least one " +
                "ObligationExpression");            
    }

    return new ObligationExpressions(obligationExpressions);
}
 
Example #2
Source File: VariableDefinition.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of the <code>VariableDefinition</code> class based on a DOM node. The
 * node must be the root of an XML VariableDefinitionType.
 * 
 * @param root the DOM root of a VariableDefinitionType XML type
 * @param metaData the meta-data associated with the containing policy
 * @param manager <code>VariableManager</code> used to connect references to this definition
 * 
 * @throws ParsingException if the VariableDefinitionType is invalid
 */
public static VariableDefinition getInstance(Node root, PolicyMetaData metaData,
        VariableManager manager) throws ParsingException {
    String variableId = root.getAttributes().getNamedItem("VariableId").getNodeValue();

    // get the first element, which is the expression node
    NodeList nodes = root.getChildNodes();
    Node xprNode = nodes.item(0);
    int i = 1;
    while (xprNode.getNodeType() != Node.ELEMENT_NODE)
        xprNode = nodes.item(i++);

    // use that node to get the expression
    Expression xpr = ExpressionHandler.parseExpression(xprNode, metaData, manager);

    return new VariableDefinition(variableId, xpr);
}
 
Example #3
Source File: FileBasedPolicyFinderModule.java    From balana with Apache License 2.0 6 votes vote down vote up
@Override
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
                                     PolicyMetaData parentMetaData) {

    AbstractPolicy policy = policies.get(idReference);
    if (policy != null) {
        if (type == PolicyReference.POLICY_REFERENCE) {
            if (policy instanceof Policy) {
                return new PolicyFinderResult(policy);
            }
        } else {
            if (policy instanceof PolicySet) {
                return new PolicyFinderResult(policy);
            }
        }
    }

    // if there was an error loading the policy, return the error
    ArrayList<String> code = new ArrayList<String>();
    code.add(Status.STATUS_PROCESSING_ERROR);
    Status status = new Status(code,
            "couldn't load referenced policy");
    return new PolicyFinderResult(status);
}
 
Example #4
Source File: PAPPolicyFinder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
                                     PolicyMetaData parentMetaData) {

    // clear all current policies
    policies.getPolicies().clear();

    AbstractPolicy policy = null;

    try {
        AbstractPolicy policyFromStore = policyReader.readPolicy(idReference.toString(),
                this.policyFinder);

        if (policyFromStore != null) {
            if (type == PolicyReference.POLICY_REFERENCE) {
                if (policyFromStore instanceof Policy) {
                    policy = policyFromStore;
                    policies.addPolicy(policy);
                }
            } else {
                if (policyFromStore instanceof PolicySet) {
                    policy = policyFromStore;
                    policies.addPolicy(policy);
                }
            }
        }
    } catch (EntitlementException e) {
        // ignore and just log the error.
        log.error(e);
    }

    if (policy == null) {
        return new PolicyFinderResult();
    } else {
        return new PolicyFinderResult(policy);
    }
}
 
Example #5
Source File: CarbonPolicyFinder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
                                     PolicyMetaData parentMetaData) {

    AbstractPolicy policy = policyReferenceCache.get(idReference);

    if (policy == null) {
        if (this.finderModules != null) {
            for (PolicyFinderModule finderModule : this.finderModules) {
                String policyString = finderModule.getReferencedPolicy(idReference.toString());
                if (policyString != null) {
                    policy = policyReader.getPolicy(policyString);
                    if (policy != null) {
                        policyReferenceCache.put(idReference, policy);
                        break;
                    }
                }
            }
        }
    }

    if (policy != null) {
        // we found a valid version, so see if it's the right kind,
        // and if it is then we return it
        if (type == PolicyReference.POLICY_REFERENCE) {
            if (policy instanceof Policy) {
                return new PolicyFinderResult(policy);
            }
        } else {
            if (policy instanceof PolicySet) {
                return new PolicyFinderResult(policy);
            }
        }
    }

    return new PolicyFinderResult();
}
 
Example #6
Source File: PAPPolicyFinder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
                                     PolicyMetaData parentMetaData) {

    // clear all current policies
    policies.getPolicies().clear();

    AbstractPolicy policy = null;

    try {
        AbstractPolicy policyFromStore = policyReader.readPolicy(idReference.toString(),
                this.policyFinder);

        if (policyFromStore != null) {
            if (type == PolicyReference.POLICY_REFERENCE) {
                if (policyFromStore instanceof Policy) {
                    policy = policyFromStore;
                    policies.addPolicy(policy);
                }
            } else {
                if (policyFromStore instanceof PolicySet) {
                    policy = policyFromStore;
                    policies.addPolicy(policy);
                }
            }
        }
    } catch (EntitlementException e) {
        // ignore and just log the error.
        log.error(e);
    }

    if (policy == null) {
        return new PolicyFinderResult();
    } else {
        return new PolicyFinderResult(policy);
    }
}
 
Example #7
Source File: CarbonPolicyFinder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
                                     PolicyMetaData parentMetaData) {

    AbstractPolicy policy = policyReferenceCache.get(idReference);

    if (policy == null) {
        if (this.finderModules != null) {
            for (PolicyFinderModule finderModule : this.finderModules) {
                String policyString = finderModule.getReferencedPolicy(idReference.toString());
                if (policyString != null) {
                    policy = policyReader.getPolicy(policyString);
                    if (policy != null) {
                        policyReferenceCache.put(idReference, policy);
                        break;
                    }
                }
            }
        }
    }

    if (policy != null) {
        // we found a valid version, so see if it's the right kind,
        // and if it is then we return it
        if (type == PolicyReference.POLICY_REFERENCE) {
            if (policy instanceof Policy) {
                return new PolicyFinderResult(policy);
            }
        } else {
            if (policy instanceof PolicySet) {
                return new PolicyFinderResult(policy);
            }
        }
    }

    return new PolicyFinderResult();
}
 
Example #8
Source File: VariableReference.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new instance of the <code>VariableReference</code> class based on a DOM node. The
 * node must be the root of an XML VariableReferenceType.
 *
 * @param root     the DOM root of a VariableReferenceType XML type
 * @param metaData the meta-data associated with the containing policy
 * @param manager  the <code>VariableManager</code> used to connect this reference to its
 *                 definition
 * @throws ParsingException if the VariableReferenceType is invalid
 */
public static VariableReference getInstance(Node root, PolicyMetaData metaData,
                                            VariableManager manager) throws ParsingException {
    // pretty easy, since there's just an attribute...
    String variableId = root.getAttributes().getNamedItem("VariableId").getNodeValue();

    // ...but we keep the manager since after this we'll probably get
    // asked for our type, etc., and the manager will also be used to
    // resolve the actual definition
    return new VariableReference(variableId, manager);
}
 
Example #9
Source File: AttributeSelectorFactory.java    From balana with Apache License 2.0 5 votes vote down vote up
public AbstractAttributeSelector getAbstractSelector(Node root, PolicyMetaData metaData)
                                                                    throws ParsingException {

    if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
        return org.wso2.balana.attr.xacml3.AttributeSelector.getInstance(root, metaData);
    } else {
        return org.wso2.balana.attr.AttributeSelector.getInstance(root, metaData);
    }
}
 
Example #10
Source File: AttributeDesignatorFactory.java    From balana with Apache License 2.0 5 votes vote down vote up
public AbstractDesignator getAbstractDesignator(Node root, PolicyMetaData metaData)
                                                                    throws ParsingException {

    if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
        return AttributeDesignator.getInstance(root);
    } else {
        return org.wso2.balana.attr.AttributeDesignator.getInstance(root);
    }
}
 
Example #11
Source File: VariableManager.java    From balana with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a manager with a fixed set of supported identifiers. For each of these identifiers,
 * the map supplies a cooresponding DOM node used to parse the definition. This is used if, in
 * the course of parsing one definition, a reference requires that you have information about
 * another definition available. All parsed definitions are cached so that each is only parsed
 * once. If a node is not provided, then the parsing code may throw an exception if out-of-order
 * or circular refereces are used.
 * <p>
 * Note that the use of a DOM node may change to an arbitrary interface, so that you could use
 * your own mechanism, but this is still being hashed out. This interface will be forzed before
 * a 2.0 release.
 * 
 * @param variableIds a <code>Map</code> from an identifier to the <code>Node</code> that is the
 *            root of the cooresponding variable definition, or null
 * @param metaData the meta-data associated with the containing policy
 */
public VariableManager(Map variableIds, PolicyMetaData metaData) {
    idMap = new HashMap();

    Iterator it = variableIds.entrySet().iterator();
    while (it.hasNext()) {
        Object key = ((Entry)it.next()).getKey();
        Node node = (Node) (variableIds.get(key));
        idMap.put(key, new VariableState(null, node, null, false, false));
    }

    this.metaData = metaData;
}
 
Example #12
Source File: PolicyFinderModule.java    From balana with Apache License 2.0 2 votes vote down vote up
/**
 * Tries to find one and only one matching policy given the idReference If more than one policy
 * is found, this is an error and must be reported as such. If no policies are found, then an
 * empty result must be returned. By default this method returns an empty result. This method
 * should never return null.
 * 
 * @param idReference an identifier specifying some policy
 * @param type type of reference (policy or policySet) as identified by the fields in
 *            <code>PolicyReference</code>
 * @param constraints any optional constraints on the version of the referenced policy (this
 *            will never be null, but it may impose no constraints, and in fact will never
 *            impose constraints when used from a pre-2.0 XACML policy)
 * @param parentMetaData the meta-data from the parent policy, which provides XACML version,
 *            factories, etc.
 * 
 * @return the result of looking for a matching policy
 */
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints,
        PolicyMetaData parentMetaData) {
    return new PolicyFinderResult();
}