Search in sources :

Example 1 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class EnvironmentImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("EnvironmentImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("EnvironmentImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.ENVIRONMENT)) {
        XACMLSDKUtils.debug.error("EnvironmentImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes >= 1) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int nextElem = 0; nextElem < numOfNodes; nextElem++) {
            Node child = (Node) nodes.item(nextElem);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                // The child nodes should be <Attribute> 
                String attrChildName = child.getLocalName();
                if (attrChildName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (this.attributes == null) {
                        this.attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else {
                    XACMLSDKUtils.debug.error("EnvironmentImpl." + "processElement(): Invalid element :" + attrChildName);
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
                }
            }
        }
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 2 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class RequestImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.REQUEST)) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes < 1) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): request has no subelements");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
    ContextFactory factory = ContextFactory.getInstance();
    List children = new ArrayList();
    int i = 0;
    Node child;
    while (i < numOfNodes) {
        child = (Node) nodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            children.add(child);
        }
        i++;
    }
    if (children.isEmpty()) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " request has no subelements");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
    child = (Node) children.get(0);
    // The first subelement should be <Subject>
    String childName = child.getLocalName();
    if ((childName == null) || (!childName.equals(XACMLConstants.SUBJECT))) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " the first element is not <Subject>");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelement_subject"));
    }
    Subject subject = factory.getInstance().createSubject((Element) child);
    if (!supportedSubjectCategory.contains(subject.getSubjectCategory().toString())) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement():subject " + "category in subject not supported");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("unsupported_subject_category"));
    }
    subjects.add(subject);
    boolean resourceFound = false;
    boolean actionFound = false;
    boolean envFound = false;
    for (int j = 1; j < children.size(); j++) {
        child = (Node) children.get(j);
        // so far <Resource> is not encountered
        // Go through next sub elements for <Subject> and <Resource>
        // The next subelement may be <Resource> or <Subject>
        childName = child.getLocalName();
        if ((childName != null) && (childName.equals(XACMLConstants.RESOURCE) || childName.equals(XACMLConstants.SUBJECT))) {
            if (resourceFound) {
                if (childName.equals(XACMLConstants.SUBJECT)) {
                    // all <Subject> should be before <Resource>
                    XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Subject> should be " + "before <Resource>");
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
                } else {
                    // found another resource
                    Resource resource = factory.getInstance().createResource((Element) child);
                    resources.add(resource);
                }
            } else if (childName.equals(XACMLConstants.SUBJECT)) {
                subject = factory.getInstance().createSubject((Element) child);
                subjects.add(subject);
            } else {
                // childname is resource
                resourceFound = true;
                Resource resource = factory.getInstance().createResource((Element) child);
                resources.add(resource);
            }
        } else if ((childName != null) && (childName.equals(XACMLConstants.ACTION))) {
            if (!resourceFound) {
                XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> should be " + "before <Action>");
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
            } else {
                actionFound = true;
                action = factory.createAction((Element) child);
            }
        } else if ((childName != null) && (childName.equals(XACMLConstants.ENVIRONMENT))) {
            if (!resourceFound || !actionFound) {
                XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> and " + "Action should be before <Environment>");
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
            } else {
                envFound = true;
                env = factory.createEnvironment((Element) child);
            }
        }
    }
    if (XACMLSDKUtils.debug.messageEnabled()) {
        XACMLSDKUtils.debug.message("resourceFound:" + resourceFound);
        XACMLSDKUtils.debug.message("actionFound:" + actionFound);
        XACMLSDKUtils.debug.message("envFound:" + envFound);
    }
    if (!resourceFound || !actionFound || !envFound) {
        XACMLSDKUtils.debug.error("RequestImpl.processElement(): Some" + "of required elements are missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Resource(com.sun.identity.xacml.context.Resource) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Subject(com.sun.identity.xacml.context.Subject) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 3 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class ResourceImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.RESOURCE)) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes > 0) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int i = 0; i < numOfNodes; i++) {
            Node child = (Node) nodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                String childName = child.getLocalName();
                // <ResourceContent>
                if (childName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (attributes == null) {
                        attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else if (childName.equals(XACMLConstants.RESOURCE_CONTENT)) {
                    resourceContent = (Element) child;
                }
            }
        }
    } else {
    /* not a schema violation
             XACMLSDKUtils.debug.error(
                "ResourceImpl.processElement(): no attributes or resource "
                +"content");
            throw new XACMLException( 
                XACMLSDKUtils.xacmlResourceBundle.getString(
                "missing_subelements"));
            */
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 4 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class XACMLSDKUtils method createAttribute.

public static Attribute createAttribute(List values, URI attributeId, URI dataType, String issuer) throws XACMLException {
    ContextFactory factory = ContextFactory.getInstance();
    Attribute attr = null;
    attr = factory.getInstance().createAttribute();
    attr.setAttributeId(attributeId);
    attr.setDataType(dataType);
    attr.setAttributeValues(values);
    ;
    attr.setIssuer(issuer);
    return attr;
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute)

Example 5 with ContextFactory

use of com.sun.identity.xacml.context.ContextFactory in project OpenAM by OpenRock.

the class XACMLAuthzDecisionQueryImpl method parseDOMElement.

protected void parseDOMElement(Element element) throws SAML2Exception {
    //TODO: fix
    String value = null;
    if (element == null) {
        XACMLSDKUtils.debug.error("XACMLAuthzDecisionQueryImpl.processElement(): " + "invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    // First check that we're really parsing an XACMLAuthzDecisionQuery
    if (!element.getLocalName().equals(XACMLConstants.REQUEST_ABSTRACT)) {
        XACMLSDKUtils.debug.error("XACMLAuthzDecisionQueryImpl.processElement(): " + "invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    //TODO: check for xsi:type=
    // now we get the request
    NodeList nodes = element.getChildNodes();
    ContextFactory factory = ContextFactory.getInstance();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if ((node.getNodeType() == Node.ELEMENT_NODE) || (node.getNodeType() == Node.ATTRIBUTE_NODE)) {
            if (node.getLocalName().equals(XACMLConstants.REQUEST)) {
                if (request != null) {
                //validation error, throw error
                } else {
                    request = factory.getInstance().createRequest((Element) node);
                }
            }
        }
    }
    // make sure we got a request
    if (request == null) {
    //throw new XACMLException(
    //       XACMLSDKUtils.xacmlResourceBundle.getString(
    //       "null_not_valid"));
    }
    System.out.println("ReturnContex:" + element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.RETURN_CONTEXT));
    System.out.println("InputContextOnly:" + element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.INPUT_CONTEXT_ONLY));
    String returnContextString = element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.RETURN_CONTEXT);
    if (returnContextString != null) {
        returnContext = Boolean.valueOf(returnContextString).booleanValue();
    }
    String inputContextOnlyString = element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.INPUT_CONTEXT_ONLY);
    if (inputContextOnlyString != null) {
        inputContextOnly = Boolean.valueOf(inputContextOnlyString).booleanValue();
    }
    NamedNodeMap attrs = element.getAttributes();
    //TODO: change the baseclass impl and call super.parse...
    //parse the attributes of base class RequestAbstract
    NamedNodeMap atts = ((Node) element).getAttributes();
    if (atts != null) {
        int length = atts.getLength();
        for (int i = 0; i < length; i++) {
            Attr attr = (Attr) atts.item(i);
            String attrName = attr.getName();
            String attrValue = attr.getValue().trim();
            if (attrName.equals("ID")) {
                requestId = attrValue;
            } else if (attrName.equals("Version")) {
                version = attrValue;
            } else if (attrName.equals("IssueInstant")) {
                try {
                    issueInstant = DateUtils.stringToDate(attrValue);
                } catch (ParseException pe) {
                    throw new XACMLException(pe.getMessage());
                }
            } else if (attrName.equals("Destination")) {
                destinationURI = attrValue;
            }
        }
    }
    //parse the elements of base class RequestAbstract
    NodeList nl = element.getChildNodes();
    Node child;
    String childName;
    int length = nl.getLength();
    for (int i = 0; i < length; i++) {
        child = nl.item(i);
        if ((childName = child.getLocalName()) != null) {
            if (childName.equals("Issuer")) {
                if (nameID != null) {
                    if (XACMLSDKUtils.debug.messageEnabled()) {
                        XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element: included more than one Issuer.");
                    }
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
                }
                if (signatureString != null || extensions != null) {
                    if (XACMLSDKUtils.debug.messageEnabled()) {
                        XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:wrong sequence.");
                    }
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("schemaViolation"));
                }
                nameID = AssertionFactory.getInstance().createIssuer((Element) child);
            } else if (childName.equals("Signature")) {
                if (signatureString != null) {
                    if (XACMLSDKUtils.debug.messageEnabled()) {
                        XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:included more than one Signature.");
                    }
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
                }
                if (extensions != null) {
                    if (XACMLSDKUtils.debug.messageEnabled()) {
                        XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:wrong sequence.");
                    }
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("schemaViolation"));
                }
                signatureString = XMLUtils.print((Element) child);
                isSigned = true;
            } else if (childName.equals("Extensions")) {
                if (extensions != null) {
                    if (XACMLSDKUtils.debug.messageEnabled()) {
                        XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:included more than one Extensions.");
                    }
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
                }
                extensions = ProtocolFactory.getInstance().createExtensions((Element) child);
            } else if (childName.equals("Request")) {
            //no action, it has been processd already
            } else {
                if (XACMLSDKUtils.debug.messageEnabled()) {
                    XACMLSDKUtils.debug.message("XACMLAuthzDecisionQueryImpl.parseDOMElement" + "Element: Invalid element:" + childName);
                }
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalidElement"));
            }
        }
    }
    validateData();
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ParseException(java.text.ParseException) Attr(org.w3c.dom.Attr) XACMLException(com.sun.identity.xacml.common.XACMLException)

Aggregations

ContextFactory (com.sun.identity.xacml.context.ContextFactory)7 XACMLException (com.sun.identity.xacml.common.XACMLException)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Attribute (com.sun.identity.xacml.context.Attribute)5 ArrayList (java.util.ArrayList)5 Element (org.w3c.dom.Element)3 Resource (com.sun.identity.xacml.context.Resource)1 Subject (com.sun.identity.xacml.context.Subject)1 URI (java.net.URI)1 ParseException (java.text.ParseException)1 List (java.util.List)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1