@Test public void testXpath_node_count() { FunctionDefinitionXPath<?> fd = (FunctionDefinitionXPath<?>) StdFunctions.FD_XPATH_NODE_COUNT; assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_COUNT, fd.getId()); assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); assertEquals(new Integer(1), fd.getNumArgs()); arguments.clear(); arguments.add(attrXSlashSlashStar); ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); BigInteger resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("18"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdMalignancy); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("1"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdName); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("2"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdRecordSlashStar); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("3"), resValue); arguments.clear(); arguments.add(attrXMdPatientInfo); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("1"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdName); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("2"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdMalignancy); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("1"), resValue); arguments.clear(); arguments.add(attrXNotInRequest); res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("0"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdName); res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXSlashSlashMdName); res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("2"), resValue); arguments.clear(); arguments.add(attrXSlashSlashMdName); res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); assertTrue(res.isOk()); resValue = (BigInteger)res.getValue().getValue(); assertEquals(new BigInteger("0"), resValue); arguments.clear(); arguments.add(attrXEmpty); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Got null EvaluationContext", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXSlashSlashMdRecord); res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXnull); res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Got null attribute at arg index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXNoValue); res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXNoCategory); res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Got null Category at index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrXEmpty); arguments.add(attrXEmpty); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Expected 1 arguments, got 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBadType); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(null); res = fd.evaluate(null, arguments); assertFalse(res.getStatus().isOk()); assertEquals( "function:xpath-node-count Got null argument at arg index 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<NodeList> nodeListList = new ArrayList<>(); List<XPathExpressionWrapper> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } for (int i = 0; i < arguments.size(); i++) { FunctionArgument functionArgument = arguments.get(i); if (functionArgument.isBag()) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got bag at index " + i)); } AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue(); if (attributeValueFunctionArgument == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null value at index " + i)); } Identifier xpathCategory = attributeValueFunctionArgument.getXPathCategory(); if (xpathCategory == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Category at index " + i)); } Iterator<RequestAttributes> it = evaluationContext.getRequest().getRequestAttributes(xpathCategory); if (it == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Iterator at index " + i)); } NodeList nodeList = null; while (it.hasNext()) { if (nodeList != null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " More than one Content section for id '" + xpathCategory + "'" )); } RequestAttributes requestAttributes = it.next(); if (requestAttributes.getContentRoot() == null) { if (operation == OPERATION.COUNT){ return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") )); } else { return ER_FALSE; } } try { XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped(); nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression); } catch (Exception e) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " XPath produces null result at '" + convertedArguments.get(i).getPath() + "' at index " + i )); } } if (nodeList == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " XPathExpression returned null at index " + i)); } nodeListList.add(nodeList); } ExpressionResult expressionResult = null; switch (operation) { case COUNT: Integer listLength = new Integer(nodeListList.get(0).getLength()); expressionResult = ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger(listLength.toString()) )); return expressionResult; case EQUAL: for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) { for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) { if (nodeListList.get(0).item(index0).isSameNode(nodeListList.get(1).item(index1))) { return ER_TRUE; } } } return ER_FALSE; case MATCH: expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1)); return expressionResult; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; }
FunctionDefinitionXPath extends FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<NodeList> nodeListList = new ArrayList<>(); List<XPathExpressionWrapper> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } for (int i = 0; i < arguments.size(); i++) { FunctionArgument functionArgument = arguments.get(i); if (functionArgument.isBag()) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got bag at index " + i)); } AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue(); if (attributeValueFunctionArgument == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null value at index " + i)); } Identifier xpathCategory = attributeValueFunctionArgument.getXPathCategory(); if (xpathCategory == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Category at index " + i)); } Iterator<RequestAttributes> it = evaluationContext.getRequest().getRequestAttributes(xpathCategory); if (it == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Iterator at index " + i)); } NodeList nodeList = null; while (it.hasNext()) { if (nodeList != null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " More than one Content section for id '" + xpathCategory + "'" )); } RequestAttributes requestAttributes = it.next(); if (requestAttributes.getContentRoot() == null) { if (operation == OPERATION.COUNT){ return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") )); } else { return ER_FALSE; } } try { XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped(); nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression); } catch (Exception e) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " XPath produces null result at '" + convertedArguments.get(i).getPath() + "' at index " + i )); } } if (nodeList == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " XPathExpression returned null at index " + i)); } nodeListList.add(nodeList); } ExpressionResult expressionResult = null; switch (operation) { case COUNT: Integer listLength = new Integer(nodeListList.get(0).getLength()); expressionResult = ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger(listLength.toString()) )); return expressionResult; case EQUAL: for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) { for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) { if (nodeListList.get(0).item(index0).isSameNode(nodeListList.get(1).item(index1))) { return ER_TRUE; } } } return ER_FALSE; case MATCH: expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1)); return expressionResult; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } }
FunctionDefinitionXPath extends FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<NodeList> nodeListList = new ArrayList<>(); List<XPathExpressionWrapper> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } for (int i = 0; i < arguments.size(); i++) { FunctionArgument functionArgument = arguments.get(i); if (functionArgument.isBag()) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got bag at index " + i)); } AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue(); if (attributeValueFunctionArgument == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null value at index " + i)); } Identifier xpathCategory = attributeValueFunctionArgument.getXPathCategory(); if (xpathCategory == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Category at index " + i)); } Iterator<RequestAttributes> it = evaluationContext.getRequest().getRequestAttributes(xpathCategory); if (it == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Iterator at index " + i)); } NodeList nodeList = null; while (it.hasNext()) { if (nodeList != null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " More than one Content section for id '" + xpathCategory + "'" )); } RequestAttributes requestAttributes = it.next(); if (requestAttributes.getContentRoot() == null) { if (operation == OPERATION.COUNT){ return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") )); } else { return ER_FALSE; } } try { XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped(); nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression); } catch (Exception e) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " XPath produces null result at '" + convertedArguments.get(i).getPath() + "' at index " + i )); } } if (nodeList == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " XPathExpression returned null at index " + i)); } nodeListList.add(nodeList); } ExpressionResult expressionResult = null; switch (operation) { case COUNT: Integer listLength = new Integer(nodeListList.get(0).getLength()); expressionResult = ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger(listLength.toString()) )); return expressionResult; case EQUAL: for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) { for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) { if (nodeListList.get(0).item(index0).isSameNode(nodeListList.get(1).item(index1))) { return ER_TRUE; } } } return ER_FALSE; case MATCH: expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1)); return expressionResult; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionXPath(Identifier idIn, DataType<O> dataTypeIn, OPERATION op); }
FunctionDefinitionXPath extends FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<NodeList> nodeListList = new ArrayList<>(); List<XPathExpressionWrapper> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } for (int i = 0; i < arguments.size(); i++) { FunctionArgument functionArgument = arguments.get(i); if (functionArgument.isBag()) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got bag at index " + i)); } AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue(); if (attributeValueFunctionArgument == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null value at index " + i)); } Identifier xpathCategory = attributeValueFunctionArgument.getXPathCategory(); if (xpathCategory == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Category at index " + i)); } Iterator<RequestAttributes> it = evaluationContext.getRequest().getRequestAttributes(xpathCategory); if (it == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Iterator at index " + i)); } NodeList nodeList = null; while (it.hasNext()) { if (nodeList != null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " More than one Content section for id '" + xpathCategory + "'" )); } RequestAttributes requestAttributes = it.next(); if (requestAttributes.getContentRoot() == null) { if (operation == OPERATION.COUNT){ return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") )); } else { return ER_FALSE; } } try { XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped(); nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression); } catch (Exception e) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " XPath produces null result at '" + convertedArguments.get(i).getPath() + "' at index " + i )); } } if (nodeList == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " XPathExpression returned null at index " + i)); } nodeListList.add(nodeList); } ExpressionResult expressionResult = null; switch (operation) { case COUNT: Integer listLength = new Integer(nodeListList.get(0).getLength()); expressionResult = ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger(listLength.toString()) )); return expressionResult; case EQUAL: for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) { for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) { if (nodeListList.get(0).item(index0).isSameNode(nodeListList.get(1).item(index1))) { return ER_TRUE; } } } return ER_FALSE; case MATCH: expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1)); return expressionResult; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionXPath(Identifier idIn, DataType<O> dataTypeIn, OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionXPath extends FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<NodeList> nodeListList = new ArrayList<>(); List<XPathExpressionWrapper> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } if (evaluationContext == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null EvaluationContext")); } if (evaluationContext.getRequest() == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null Request in EvaluationContext")); } for (int i = 0; i < arguments.size(); i++) { FunctionArgument functionArgument = arguments.get(i); if (functionArgument.isBag()) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got bag at index " + i)); } AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue(); if (attributeValueFunctionArgument == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Got null value at index " + i)); } Identifier xpathCategory = attributeValueFunctionArgument.getXPathCategory(); if (xpathCategory == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Category at index " + i)); } Iterator<RequestAttributes> it = evaluationContext.getRequest().getRequestAttributes(xpathCategory); if (it == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " Got null Iterator at index " + i)); } NodeList nodeList = null; while (it.hasNext()) { if (nodeList != null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " More than one Content section for id '" + xpathCategory + "'" )); } RequestAttributes requestAttributes = it.next(); if (requestAttributes.getContentRoot() == null) { if (operation == OPERATION.COUNT){ return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") )); } else { return ER_FALSE; } } try { XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped(); nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression); } catch (Exception e) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() + " XPath produces null result at '" + convertedArguments.get(i).getPath() + "' at index " + i )); } } if (nodeList == null) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " XPathExpression returned null at index " + i)); } nodeListList.add(nodeList); } ExpressionResult expressionResult = null; switch (operation) { case COUNT: Integer listLength = new Integer(nodeListList.get(0).getLength()); expressionResult = ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger(listLength.toString()) )); return expressionResult; case EQUAL: for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) { for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) { if (nodeListList.get(0).item(index0).isSameNode(nodeListList.get(1).item(index1))) { return ER_TRUE; } } } return ER_FALSE; case MATCH: expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1)); return expressionResult; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionXPath(Identifier idIn, DataType<O> dataTypeIn, OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }