You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openaz.apache.org by pd...@apache.org on 2015/05/13 18:02:49 UTC
[27/56] [abbrv] [partial] incubator-openaz git commit: Merging
re-factoring with PMD work
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionURIStringConcatenate.java
----------------------------------------------------------------------
diff --cc openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionURIStringConcatenate.java
index 77b52be,0000000..f65b8b5
mode 100644,000000..100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionURIStringConcatenate.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionURIStringConcatenate.java
@@@ -1,132 -1,0 +1,133 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.openaz.xacml.api.DataTypeException;
+import org.apache.openaz.xacml.api.Identifier;
+import org.apache.openaz.xacml.api.Status;
+import org.apache.openaz.xacml.api.XACML;
+import org.apache.openaz.xacml.pdp.eval.EvaluationContext;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.std.StdAttributeValue;
+import org.apache.openaz.xacml.std.StdStatus;
+import org.apache.openaz.xacml.std.StdStatusCode;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+
+/**
- * FunctionDefinitionURIStringConcatenate extends {@link FunctionDefinitionHomogeneousSimple} to
- * implement the XACML uri-string-concatenate predicate as a function taking one <code>URI</code> and one or more <code>String</code> arguments
- * and returning a single <code>URI</code> value.
- *
- * THIS FUNCTION IS DEPRECATED IN 3.0 BUT NOT REMOVED.
- * To provide backward compatibility for previously built XACML policies we include it in our R3 version.
- *
- * In the first implementation of XACML we had separate files for each XACML Function.
- * This release combines multiple Functions in fewer files to minimize code duplication.
- * This file supports the following XACML codes:
- * uri-string-concatenate
- *
- *
++ * FunctionDefinitionURIStringConcatenate extends {@link FunctionDefinitionHomogeneousSimple} to implement the
++ * XACML uri-string-concatenate predicate as a function taking one <code>URI</code> and one or more
++ * <code>String</code> arguments and returning a single <code>URI</code> value. THIS FUNCTION IS DEPRECATED IN
++ * 3.0 BUT NOT REMOVED. To provide backward compatibility for previously built XACML policies we include it in
++ * our R3 version. In the first implementation of XACML we had separate files for each XACML Function. This
++ * release combines multiple Functions in fewer files to minimize code duplication. This file supports the
++ * following XACML codes: uri-string-concatenate
+ */
+@Deprecated
+public class FunctionDefinitionURIStringConcatenate extends FunctionDefinitionBase<URI, URI> {
+
-
+ /**
+ * Constructor
+ *
+ * @param idIn
+ * @param dataTypeArgsIn
+ * @param op
+ */
+ public FunctionDefinitionURIStringConcatenate(Identifier idIn) {
+ super(idIn, DataTypes.DT_ANYURI, DataTypes.DT_ANYURI, false);
+ }
+
-
+ @Override
+ public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) {
+
+ if (arguments == null || arguments.size() < 2) {
- return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, getShortFunctionId() + " Expected 2 or more arguments, got " +
- ((arguments == null) ? "null" : arguments.size()) ));
++ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
++ getShortFunctionId()
++ + " Expected 2 or more arguments, got "
++ + ((arguments == null) ? "null" : arguments
++ .size())));
+ }
+
+ // get the string to search for
- ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0), DataTypes.DT_ANYURI, false);
- if ( ! uriArgument.isOk()) {
- Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument.getStatus().getStatusMessage() + " at arg index 0" );
++ ConvertedArgument<URI> uriArgument = new ConvertedArgument<URI>(arguments.get(0),
++ DataTypes.DT_ANYURI, false);
++ if (!uriArgument.isOk()) {
++ Status decoratedStatus = new StdStatus(uriArgument.getStatus().getStatusCode(), uriArgument
++ .getStatus().getStatusMessage() + " at arg index 0");
+ return ExpressionResult.newError(getFunctionStatus(decoratedStatus));
+ }
+ String uriString = uriArgument.getValue().toString();
+
+ // remaining arguments are strings
+ String[] stringValues = new String[arguments.size() - 1];
+
+ for (int i = 1; i < arguments.size(); i++) {
+
- ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i), DataTypes.DT_STRING, false);
- if ( ! stringArgument.isOk()) {
- Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(), stringArgument.getStatus().getStatusMessage() + " at arg index " + i );
++ ConvertedArgument<String> stringArgument = new ConvertedArgument<String>(arguments.get(i),
++ DataTypes.DT_STRING,
++ false);
++ if (!stringArgument.isOk()) {
++ Status decoratedStatus = new StdStatus(stringArgument.getStatus().getStatusCode(),
++ stringArgument.getStatus().getStatusMessage()
++ + " at arg index " + i);
+ return ExpressionResult.newError(getFunctionStatus(decoratedStatus));
+ }
+
- stringValues[i-1] = stringArgument.getValue();
++ stringValues[i - 1] = stringArgument.getValue();
+
+ }
+
-
+ // add each of the strings onto the URI
+ for (int i = 0; i < stringValues.length; i++) {
+ uriString += stringValues[i];
+ }
+
+ URI resultURI = null;
+ try {
+ resultURI = DataTypes.DT_ANYURI.convert(uriString);
+ } catch (DataTypeException e) {
+ String message = e.getMessage();
+ if (e.getCause() != null) {
+ message = e.getCause().getMessage();
+ }
- return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, getShortFunctionId() +
- " Final string '" + uriString + "' not URI, " + message));
++ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR,
++ getShortFunctionId() + " Final string '"
++ + uriString + "' not URI, " + message));
+ }
+
+ return ExpressionResult.newSingle(new StdAttributeValue<URI>(XACML.ID_DATATYPE_ANYURI, resultURI));
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionX500NameMatch.java
----------------------------------------------------------------------
diff --cc openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionX500NameMatch.java
index 6841cae,0000000..5dbe04a
mode 100644,000000..100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionX500NameMatch.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionX500NameMatch.java
@@@ -1,116 -1,0 +1,110 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.openaz.xacml.api.Identifier;
+import org.apache.openaz.xacml.api.Status;
+import org.apache.openaz.xacml.pdp.eval.EvaluationContext;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.std.StdStatusCode;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+
+/**
- * FunctionDefinitionX500NameMatch extends {@link org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionHomogeneousSimple} to
- * implement the XACML X500Name match predicate as functions taking two <code>X500Name</code> arguments and returning a single <code>Boolean</code> value.
- *
- * In the first implementation of XACML we had separate files for each XACML Function.
- * This release combines multiple Functions in fewer files to minimize code duplication.
- * This file supports the following XACML codes:
- * x500Name-match
- *
- *
++ * FunctionDefinitionX500NameMatch extends
++ * {@link com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionHomogeneousSimple} to implement the
++ * XACML X500Name match predicate as functions taking two <code>X500Name</code> arguments and returning a
++ * single <code>Boolean</code> value. In the first implementation of XACML we had separate files for each
++ * XACML Function. This release combines multiple Functions in fewer files to minimize code duplication. This
++ * file supports the following XACML codes: x500Name-match
+ */
- public class FunctionDefinitionX500NameMatch extends FunctionDefinitionHomogeneousSimple<Boolean, X500Principal> {
-
++public class FunctionDefinitionX500NameMatch extends
++ FunctionDefinitionHomogeneousSimple<Boolean, X500Principal> {
+
+ /**
+ * Constructor
+ *
+ * @param idIn
+ * @param dataTypeArgsIn
+ * @param op
+ */
+ public FunctionDefinitionX500NameMatch(Identifier idIn) {
+ super(idIn, DataTypes.DT_BOOLEAN, DataTypes.DT_X500NAME, 2);
+ }
+
-
+ @Override
+ public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) {
- List<X500Principal> convertedArguments = new ArrayList<X500Principal>();
- Status status = this.validateArguments(arguments, convertedArguments);
++ List<X500Principal> convertedArguments = new ArrayList<X500Principal>();
++ Status status = this.validateArguments(arguments, convertedArguments);
+
+ /*
+ * If the function arguments are not correct, just return an error status immediately
+ */
+ if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) {
+ return ExpressionResult.newError(getFunctionStatus(status));
+ }
+
+ /*
+ * Now perform the match.
+ */
+
+ /*
- * The spec writer's comments at:
- * https://lists.oasis-open.org/archives/xacml/200906/msg00019.html
- * say that the first sequence must exactly match the END of the second sequence.
++ * The spec writer's comments at: https://lists.oasis-open.org/archives/xacml/200906/msg00019.html say
++ * that the first sequence must exactly match the END of the second sequence.
+ */
+
+ String[] searchFor = convertedArguments.get(0).getName().split(",");
+ String[] searchIn = convertedArguments.get(1).getName().split(",");
+
+ // if first is bigger than 2nd there is no way we can match
+ if (searchFor.length > searchIn.length) {
+ return ER_FALSE;
+ }
+
+ // start from back-end of both lists - everything should match up to the length of the input
+ for (int i = 0; i < searchFor.length; i++) {
+ String searchForTerm = searchFor[searchFor.length - i - 1];
+ String searchInTerm = searchIn[searchIn.length - i - 1];
- if (searchForTerm == null || searchInTerm == null ||
- ! searchForTerm.trim().equals(searchInTerm.trim())) {
++ if (searchForTerm == null || searchInTerm == null
++ || !searchForTerm.trim().equals(searchInTerm.trim())) {
+ return ER_FALSE;
+ }
+ }
+
-
+ return ER_TRUE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionXPath.java
----------------------------------------------------------------------
diff --cc openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionXPath.java
index bb21e2c,0000000..ab91e83
mode 100644,000000..100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionXPath.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionXPath.java
@@@ -1,265 -1,0 +1,277 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.xpath.XPathExpression;
+
+import org.apache.openaz.xacml.api.AttributeValue;
+import org.apache.openaz.xacml.api.DataType;
+import org.apache.openaz.xacml.api.Identifier;
+import org.apache.openaz.xacml.api.RequestAttributes;
+import org.apache.openaz.xacml.api.Status;
+import org.apache.openaz.xacml.api.XACML;
+import org.apache.openaz.xacml.pdp.eval.EvaluationContext;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.std.StdAttributeValue;
+import org.apache.openaz.xacml.std.StdStatus;
+import org.apache.openaz.xacml.std.StdStatusCode;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.apache.openaz.xacml.std.datatypes.XPathExpressionWrapper;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * FunctionDefinitionXPath extends {@link org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionHomogeneousSimple} to
+ * implement the XACML XPath predicates as functions taking one or two <code>XPathExpression</code> arguments and returning
+ * either an <code>Integer</code> or a <code>Boolean</code>.
+ *
+ * XACML version 1.0 and 2.0 used <code>String</code> data type as input.
+ * We do NOT support those functions because of ambiguity in the meaning of those Strings.
+ * The root of the XPath changed from the Request level in 2.0 to the Content level in 3.0.
+ * Also the 2.0 Requests contain only one Content, located in the resources category, while 3.0 allows Requests to contain Content in multiple categories.
+ *
+ * In the first implementation of XACML we had separate files for each XACML Function.
+ * This release combines multiple Functions in fewer files to minimize code duplication.
+ * This file supports the following XACML codes:
+ * xpath-node-count
+ * xpath-node-equals
+ * xpath-node-match
+ *
+ *
- * @param <O> the java class for the data type of the function Output
-
- *
- */
- public class FunctionDefinitionXPath<O> extends FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> {
++ * @param <O> the java class for the data type of the function Output */
++public class FunctionDefinitionXPath<O> extends
++ FunctionDefinitionHomogeneousSimple<O, XPathExpressionWrapper> {
+
+ /**
+ * List of string normalization operations.
- *
- *
+ */
- public enum OPERATION {COUNT, EQUAL, MATCH };
++ public enum OPERATION {
++ COUNT,
++ EQUAL,
++ MATCH
++ };
+
+ // operation to be used in this instance of the Arightmetic class
+ private final OPERATION operation;
+
-
+ // result variables used by all functions
- AttributeValue<String> result;
-
++ AttributeValue<String> result;
+
+ /**
+ * Constructor
+ *
+ * @param idIn
+ * @param dataTypeArgsIn
+ * @param op
+ */
+ public FunctionDefinitionXPath(Identifier idIn, DataType<O> dataTypeIn, OPERATION op) {
- super(idIn, dataTypeIn, DataTypes.DT_XPATHEXPRESSION, ( (op == OPERATION.COUNT) ? 1 : 2 ) );
++ super(idIn, dataTypeIn, DataTypes.DT_XPATHEXPRESSION, ((op == OPERATION.COUNT) ? 1 : 2));
+ // save the operation and data type to be used in this instance
+ operation = op;
+
+ }
+
+ @Override
+ public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) {
+
+ List<NodeList> nodeListList = new ArrayList<NodeList>();
+
- List<XPathExpressionWrapper> convertedArguments = new ArrayList<XPathExpressionWrapper>();
- Status status = this.validateArguments(arguments, convertedArguments);
++ List<XPathExpressionWrapper> convertedArguments = new ArrayList<XPathExpressionWrapper>();
++ Status status = this.validateArguments(arguments, convertedArguments);
+
+ /*
+ * If the function arguments are not correct, just return an error status immediately
+ */
+ if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) {
+ return ExpressionResult.newError(getFunctionStatus(status));
+ }
+
+ // check the evaluationContext and Request for null
+ if (evaluationContext == null) {
- return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() +
- " Got null EvaluationContext"));
++ 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"));
++ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this
++ .getShortFunctionId() + " Got null Request in EvaluationContext"));
+ }
+
-
- // each argument is an XPath that needs to be evaluated against the Content part of some Category (specified in the argument)
++ // each argument is an XPath that needs to be evaluated against the Content part of some Category
++ // (specified in the argument)
+ 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));
++ return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
++ this.getShortFunctionId()
++ + " Got bag at index " + i));
+ }
- AttributeValue<?> attributeValueFunctionArgument = functionArgument.getValue();
++ 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));
++ 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));
++ 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);
++ 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));
++ 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) {
+ // the request has more than one Content entry for the same Category - error
- return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, this.getShortFunctionId() +
- " More than one Content section for id '" + xpathCategory + "'" ));
++ 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 there is no Content section then we return either 0 or FALSE
+ if (requestAttributes.getContentRoot() == null) {
+ if (operation == OPERATION.COUNT) {
- return ExpressionResult.newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER, new BigInteger("0") ));
++ return ExpressionResult
++ .newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER,
++ BigInteger.ZERO));
+ } else {
+ return ER_FALSE;
+ }
+ }
+
+ try {
+ XPathExpression xPathExpression = convertedArguments.get(i).getXpathExpressionWrapped();
- nodeList = requestAttributes.getContentNodeListByXpathExpression(xPathExpression);
++ 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 ));
++ 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));
++ return ExpressionResult
++ .newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this
++ .getShortFunctionId() + " XPathExpression returned null at index " + i));
+ }
+
+ // add this nodeList to the list of lists
+ nodeListList.add(nodeList);
+ }
+
-
+ /*
+ * Now perform the requested operation.
+ */
+ 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()) ));
++ expressionResult = ExpressionResult
++ .newSingle(new StdAttributeValue<BigInteger>(XACML.ID_DATATYPE_INTEGER,
++ new BigInteger(listLength.toString())));
+ return expressionResult;
+
-
+ case EQUAL:
+ // true if any node in first list equals any node in second set.
+ // The spec says: "Two nodes are considered equal if they have the same identity."
+ // we use the isSameNode method in Node to determine that.
+ for (int index0 = 0; index0 < nodeListList.get(0).getLength(); index0++) {
- for (int index1 = 0; index1 < nodeListList.get(1).getLength(); index1++) {
++ 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;
+ }
+ }
+ }
+ // none from the first list found in the second
+ return ER_FALSE;
+
-
+ case MATCH:
- // this is looking to see if any of the nodes in the second set are children of (or equal to) the nodes in the first set
++ // this is looking to see if any of the nodes in the second set are children of (or equal to) the
++ // nodes in the first set
+ // Call recursive check for that.
+ expressionResult = nodeListMatch(nodeListList.get(0), nodeListList.get(1));
+ return expressionResult;
+ }
+
+ expressionResult = ExpressionResult.newSingle(result);
+
+ return expressionResult;
+ }
+
+ /**
- * Recursive method checking to see if anything in list 2 equals anything in list 1 OR list 1's child nodes
++ * Recursive method checking to see if anything in list 2 equals anything in list 1 OR list 1's child
++ * nodes
++ *
+ * @param list1
+ * @param list2
+ * @return
+ */
+ private ExpressionResult nodeListMatch(NodeList list1, NodeList list2) {
+ // look for match with current contents of list 1
+ for (int index1 = 0; index1 < list1.getLength(); index1++) {
- for (int index2 = 0; index2 < list2.getLength(); index2++) {
++ for (int index2 = 0; index2 < list2.getLength(); index2++) {
+ if (list1.item(index1).isSameNode(list2.item(index2))) {
+ return ER_TRUE;
+ }
+ }
+ }
+ // look for match with children of list 1
+ for (int index1 = 0; index1 < list1.getLength(); index1++) {
+ if (nodeListMatch(list1.item(index1).getChildNodes(), list2) == ER_TRUE) {
+ return ER_TRUE;
+ }
+ // this one had no children that matched, so check the next element in list1
+ }
+
+ // no match anywhere
+ return ER_FALSE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/util/OpenAZPDPProperties.java
----------------------------------------------------------------------
diff --cc openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/util/OpenAZPDPProperties.java
index 7ade75b,0000000..aad4763
mode 100644,000000..100644
--- a/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/util/OpenAZPDPProperties.java
+++ b/openaz-xacml-pdp/src/main/java/org/apache/openaz/xacml/pdp/util/OpenAZPDPProperties.java
@@@ -1,49 -1,0 +1,49 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.util;
+
+import org.apache.openaz.xacml.api.Identifier;
+import org.apache.openaz.xacml.std.IdentifierImpl;
+import org.apache.openaz.xacml.util.XACMLProperties;
+
+public class OpenAZPDPProperties extends XACMLProperties {
- public static final String PROP_EVALUATIONCONTEXTFACTORY = "xacml.openaz.evaluationContextFactory";
- public static final String PROP_COMBININGALGORITHMFACTORY = "xacml.openaz.combiningAlgorithmFactory";
- public static final String PROP_FUNCTIONDEFINITIONFACTORY = "xacml.openaz.functionDefinitionFactory";
- public static final String PROP_POLICYFINDERFACTORY = "xacml.openaz.policyFinderFactory";
++ public static final String PROP_EVALUATIONCONTEXTFACTORY = "xacml.openaz.evaluationContextFactory";
++ public static final String PROP_COMBININGALGORITHMFACTORY = "xacml.openaz.combiningAlgorithmFactory";
++ public static final String PROP_FUNCTIONDEFINITIONFACTORY = "xacml.openaz.functionDefinitionFactory";
++ public static final String PROP_POLICYFINDERFACTORY = "xacml.openaz.policyFinderFactory";
+ public static final String PROP_POLICYFINDERFACTORY_COMBINEROOTPOLICIES = "xacml.openaz.policyFinderFactory.combineRootPolicies";
+
+ public static final Identifier ID_POLICY_COMBINEDPERMITOVERRIDES = new IdentifierImpl("urn:org:apache:openaz:xacml:3.0:policy-combining-algorithm:combined-permit-overrides");
+
+ protected OpenAZPDPProperties() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRest.java
index 7d25895,0000000..5d53ced
mode 100644,000000..100644
--- a/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRest.java
+++ b/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRest.java
@@@ -1,219 -1,0 +1,217 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.rest;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.openaz.xacml.util.XACMLProperties;
+
+/**
- * This static class is used by both the PDP and PAP servlet's. It contains some common
- * static functions and objects used by both the servlet's.
- *
- *
++ * This static class is used by both the PDP and PAP servlet's. It contains some common static functions and
++ * objects used by both the servlet's.
+ */
+public class XACMLRest {
- private static final Log logger = LogFactory.getLog(XACMLRest.class);
++ private static final Log logger = LogFactory.getLog(XACMLRest.class);
+ private static Properties restProperties = new Properties();
+
+ /**
- * This must be called during servlet initialization. It sets up the xacml.?.properties
- * file as a system property. If the System property is already set, then it does not
- * do anything. This allows the developer to specify their own xacml.properties file to be
- * used. They can 1) modify the default properties that comes with the project, or 2) change
- * the WebInitParam annotation, or 3) specify an alternative path in the web.xml, or 4) set
- * the Java System property to point to their xacml.properties file.
- *
- * The recommended way of overriding the default xacml.properties file is using a Java System
- * property:
- *
- * -Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties
- *
- * This way one does not change any actual code or files in the project and can leave the
- * defaults alone.
++ * This must be called during servlet initialization. It sets up the xacml.?.properties file as a system
++ * property. If the System property is already set, then it does not do anything. This allows the
++ * developer to specify their own xacml.properties file to be used. They can 1) modify the default
++ * properties that comes with the project, or 2) change the WebInitParam annotation, or 3) specify an
++ * alternative path in the web.xml, or 4) set the Java System property to point to their xacml.properties
++ * file. The recommended way of overriding the default xacml.properties file is using a Java System
++ * property: -Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties This way one does not change any
++ * actual code or files in the project and can leave the defaults alone.
+ *
+ * @param config - The servlet config file passed from the javax servlet init() function
+ */
+ public static void xacmlInit(ServletConfig config) {
+ //
+ // Get the XACML Properties File parameter first
+ //
+ String propFile = config.getInitParameter("XACML_PROPERTIES_NAME");
+ if (propFile != null) {
+ //
+ // Look for system override
+ //
+ String xacmlPropertiesName = System.getProperty(XACMLProperties.XACML_PROPERTIES_NAME);
+ if (xacmlPropertiesName == null) {
+ //
+ // Set it to our servlet default
+ //
+ if (logger.isDebugEnabled()) {
+ logger.debug("Using Servlet Config Property for XACML_PROPERTIES_NAME:" + propFile);
+ }
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, propFile);
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Using System Property for XACML_PROPERTIES_NAME:" + xacmlPropertiesName);
+ }
+ }
+ }
+ //
+ // Setup the remaining properties
+ //
+ Enumeration<String> params = config.getInitParameterNames();
+ while (params.hasMoreElements()) {
+ String param = params.nextElement();
- if (! param.equals("XACML_PROPERTIES_NAME")) {
++ if (!param.equals("XACML_PROPERTIES_NAME")) {
+ String value = config.getInitParameter(param);
+ logger.info(param + "=" + config.getInitParameter(param));
+ restProperties.setProperty(param, value);
+ }
+ }
+ }
+
+ /**
- * Reset's the XACMLProperties internal properties object so we start
- * in a fresh environment. Then adds back in our Servlet init properties that were
- * passed in the javax Servlet init() call.
- *
- * This function is primarily used when a new configuration is passed in and the
- * PDP servlet needs to load a new PDP engine instance.
++ * Reset's the XACMLProperties internal properties object so we start in a fresh environment. Then adds
++ * back in our Servlet init properties that were passed in the javax Servlet init() call. This function is
++ * primarily used when a new configuration is passed in and the PDP servlet needs to load a new PDP engine
++ * instance.
+ *
+ * @param pipProperties - PIP configuration properties
- * @param policyProperties - Policy configuration properties
++ * @param policyProperties - Policy configuration properties
+ */
+ public static void loadXacmlProperties(Properties policyProperties, Properties pipProperties) {
+ try {
+ //
+ // Start fresh
+ //
+ XACMLProperties.reloadProperties();
+ //
+ // Now load our init properties
+ //
+ XACMLProperties.getProperties().putAll(XACMLRest.restProperties);
+ //
+ // Load our policy properties
+ //
+ if (policyProperties != null) {
+ XACMLProperties.getProperties().putAll(policyProperties);
+ }
+ //
+ // Load our pip config properties
+ //
+ if (pipProperties != null) {
+ XACMLProperties.getProperties().putAll(pipProperties);
+ }
+ } catch (IOException e) {
+ logger.error("Failed to put init properties into Xacml properties", e);
+ }
+ //
+ // Dump them
+ //
+ if (logger.isDebugEnabled()) {
+ try {
+ logger.debug(XACMLProperties.getProperties().toString());
+ } catch (IOException e) {
+ logger.error("Cannot dump properties", e);
+ }
+ }
+ }
+
+ /**
+ * Helper routine to dump the HTTP servlet request being serviced. Primarily for debugging.
+ *
+ * @param request - Servlet request (from a POST/GET/PUT/etc.)
+ */
+ public static void dumpRequest(HttpServletRequest request) {
+ if (logger.isDebugEnabled()) {
- // special-case for receiving heartbeat - don't need to repeatedly output all of the information in multiple lines
- if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) {
++ // special-case for receiving heartbeat - don't need to repeatedly output all of the information
++ // in multiple lines
++ if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type"))) {
+ logger.debug("GET type=hb : heartbeat received");
+ return;
+ }
- logger.debug(request.getMethod() + ":" + request.getRemoteAddr() + " " + request.getRemoteHost() + " " + request.getRemotePort());
- logger.debug(request.getLocalAddr() + " " + request.getLocalName() + " " + request.getLocalPort());
++ logger.debug(request.getMethod() + ":" + request.getRemoteAddr() + " " + request.getRemoteHost()
++ + " " + request.getRemotePort());
++ logger
++ .debug(request.getLocalAddr() + " " + request.getLocalName() + " " + request.getLocalPort());
+ Enumeration<String> en = request.getHeaderNames();
+ logger.debug("Headers:");
+ while (en.hasMoreElements()) {
+ String element = en.nextElement();
+ Enumeration<String> values = request.getHeaders(element);
+ while (values.hasMoreElements()) {
+ String value = values.nextElement();
+ logger.debug(element + ":" + value);
+ }
+ }
+ logger.debug("Attributes:");
+ en = request.getAttributeNames();
+ while (en.hasMoreElements()) {
+ String element = en.nextElement();
+ logger.debug(element + ":" + request.getAttribute(element));
+ }
+ logger.debug("ContextPath: " + request.getContextPath());
+ if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) {
- // POST and PUT are allowed to have parameters in the content, but in our usage the parameters are always in the Query string.
- // More importantly, there are cases where the POST and PUT content is NOT parameters (e.g. it might contain a Policy file).
- // Unfortunately the request.getParameterMap method reads the content to see if there are any parameters,
++ // POST and PUT are allowed to have parameters in the content, but in our usage the parameters
++ // are always in the Query string.
++ // More importantly, there are cases where the POST and PUT content is NOT parameters (e.g. it
++ // might contain a Policy file).
++ // Unfortunately the request.getParameterMap method reads the content to see if there are any
++ // parameters,
+ // and once the content is read it cannot be read again.
- // Thus for PUT and POST we must avoid reading the content here so that the main code can read it.
++ // Thus for PUT and POST we must avoid reading the content here so that the main code can read
++ // it.
+ logger.debug("Query String:" + request.getQueryString());
+ try {
+ if (request.getInputStream() == null) {
+ logger.debug("Content: No content inputStream");
+ } else {
+ logger.debug("Content available: " + request.getInputStream().available());
+ }
+ } catch (Exception e) {
- logger.debug("Content: inputStream exception: " + e.getMessage() + "; (May not be relevant)");
++ logger.debug("Content: inputStream exception: " + e.getMessage()
++ + "; (May not be relevant)");
+ }
+ } else {
+ logger.debug("Parameters:");
+ Map<String, String[]> params = request.getParameterMap();
+ Set<String> keys = params.keySet();
+ for (String key : keys) {
+ String[] values = params.get(key);
+ logger.debug(key + "(" + values.length + "): " + (values.length > 0 ? values[0] : ""));
+ }
+ }
+ logger.debug("Request URL:" + request.getRequestURL());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRestProperties.java
----------------------------------------------------------------------
diff --cc openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRestProperties.java
index cc0f206,0000000..0f3e6cb
mode 100644,000000..100644
--- a/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRestProperties.java
+++ b/openaz-xacml-rest/src/main/java/org/apache/openaz/xacml/rest/XACMLRestProperties.java
@@@ -1,156 -1,0 +1,138 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.rest;
+
+import org.apache.openaz.xacml.util.XACMLProperties;
+
+/**
- * These are XACML Properties that are relevant to the RESTful API interface for
- * the PDP, PAP and AC interfaces.
- *
- *
- *
++ * These are XACML Properties that are relevant to the RESTful API interface for the PDP, PAP and AC
++ * interfaces.
+ */
+public class XACMLRestProperties extends XACMLProperties {
+ /**
- * A unique identifier for the PDP servlet instance. Usually set to the URL
- * it is running as in the J2EE container.
- *
- * Eg. http://localhost:8080/pdp/
++ * A unique identifier for the PDP servlet instance. Usually set to the URL it is running as in the J2EE
++ * container. Eg. http://localhost:8080/pdp/
+ */
- public static final String PROP_PDP_ID = "xacml.rest.pdp.id";
++ public static final String PROP_PDP_ID = "xacml.rest.pdp.id";
+ /**
- * A PDP servlet's configuration directory. Holds the pip and policy configuration
- * data as well as the local policy cache.
- *
- * Eg: /opt/app/xacml/config
++ * A PDP servlet's configuration directory. Holds the pip and policy configuration data as well as the
++ * local policy cache. Eg: /opt/app/xacml/config
+ */
- public static final String PROP_PDP_CONFIG = "xacml.rest.pdp.config";
++ public static final String PROP_PDP_CONFIG = "xacml.rest.pdp.config";
+ /**
- * Set this property to true or false if the PDP servlet should register itself upon
- * startup with the PAP servlet.
++ * Set this property to true or false if the PDP servlet should register itself upon startup with the PAP
++ * servlet.
+ */
- public static final String PROP_PDP_REGISTER = "xacml.rest.pdp.register";
++ public static final String PROP_PDP_REGISTER = "xacml.rest.pdp.register";
+ /**
- * Number of seconds the PDP will sleep while retrying registration with the PAP.
- * This value must be greater or equal to 5.
++ * Number of seconds the PDP will sleep while retrying registration with the PAP. This value must be
++ * greater or equal to 5.
+ */
- public static final String PROP_PDP_REGISTER_SLEEP = "xacml.rest.pdp.register.sleep";
++ public static final String PROP_PDP_REGISTER_SLEEP = "xacml.rest.pdp.register.sleep";
+ /**
+ * Number of retry attempts at registration with the PAP. A value of -1 indicates infinite retries.
+ */
- public static final String PROP_PDP_REGISTER_RETRIES = "xacml.rest.pdp.register.retries";
++ public static final String PROP_PDP_REGISTER_RETRIES = "xacml.rest.pdp.register.retries";
+ /**
+ * Max content length accepted for an incoming POST XML/JSON request. Default is 32767 bytes.
+ */
- public static final String PROP_PDP_MAX_CONTENT = "xacml.rest.pdp.maxcontent";
++ public static final String PROP_PDP_MAX_CONTENT = "xacml.rest.pdp.maxcontent";
+ /**
+ * Custom HTTP header used by PDP to send the value of the PROP_PDP_ID
+ */
- public static final String PROP_PDP_HTTP_HEADER_ID = "X-XACML-PDP-ID";
++ public static final String PROP_PDP_HTTP_HEADER_ID = "X-XACML-PDP-ID";
+ /**
+ * Custom HHTP header used by PDP to send its heartbeat value.
+ */
- public static final String PROP_PDP_HTTP_HEADER_HB = "X-XACML-PDP-HB";
++ public static final String PROP_PDP_HTTP_HEADER_HB = "X-XACML-PDP-HB";
+ /**
- * The URL of the PAP servlet. Used by PDP servlet's to communicate. Because administrators
- * can set whatever context they want to run the PAP servlet, it isn't easy to determine a return
- * URL for the PAP servlet. This is especially true upon initialization.
++ * The URL of the PAP servlet. Used by PDP servlet's to communicate. Because administrators can set
++ * whatever context they want to run the PAP servlet, it isn't easy to determine a return URL for the PAP
++ * servlet. This is especially true upon initialization.
+ */
- public static final String PROP_PAP_URL = "xacml.rest.pap.url";
++ public static final String PROP_PAP_URL = "xacml.rest.pap.url";
+ /**
- * Upon startup, have the PAP servlet send latest configuration information to all
- * the PDP nodes it knows about.
++ * Upon startup, have the PAP servlet send latest configuration information to all the PDP nodes it knows
++ * about.
+ */
+ public static final String PROP_PAP_INITIATE_PDP_CONFIG = "xacml.rest.pap.initiate.pdp";
+ /**
+ * The interval the PAP servlet uses to send heartbeat requests to the PDP nodes.
+ */
- public static final String PROP_PAP_HEARTBEAT_INTERVAL = "xacml.rest.pap.heartbeat.interval";
++ public static final String PROP_PAP_HEARTBEAT_INTERVAL = "xacml.rest.pap.heartbeat.interval";
+ /**
+ * Timeout value used by the PAP servlet when trying to check the heartbeat of a PDP node.
+ */
- public static final String PROP_PAP_HEARTBEAT_TIMEOUT = "xacml.rest.pap.heartbeat.timeout";
++ public static final String PROP_PAP_HEARTBEAT_TIMEOUT = "xacml.rest.pap.heartbeat.timeout";
+ /*
- * Local path to where the GIT repository exists.
- *
- * Eg. /opt/app/xacml/repository
++ * Local path to where the GIT repository exists. Eg. /opt/app/xacml/repository
+ */
+ public static final String PROP_ADMIN_REPOSITORY = "xacml.rest.admin.repository";
+ /*
- * Local path to where user workspaces exist. The user workspace contains temporary files, the
- * user's clone of the GIT repository, anything specific to the user, etc.
++ * Local path to where user workspaces exist. The user workspace contains temporary files, the user's
++ * clone of the GIT repository, anything specific to the user, etc.
+ */
+ public static final String PROP_ADMIN_WORKSPACE = "xacml.rest.admin.workspace";
+ /*
- * This is the domain you can setup for your organization, it should be a URI.
- *
- * Eg. com:sample:foo
++ * This is the domain you can setup for your organization, it should be a URI. Eg. com:sample:foo
+ */
+ public static final String PROP_ADMIN_DOMAIN = "xacml.rest.admin.domain";
+ /**
- * PROP_ADMIN_USER_NAME is simply a name for the logged in user.
- *
- * AC authentication is out the scope of the web application itself. It is up to the
- * developer to setup authentication as they please in the J2EE container used to run
- * the web application. Whatever authentication mechanism they use, they should then set
- * the attribute into the HttpSession object. The Admin Console will be able to read that
- * value (default to "guest") in.
- *
- * ((HttpServletRequest) request).getSession().setAttribute("xacml.rest.admin.user.name", "Homer");
- *
++ * PROP_ADMIN_USER_NAME is simply a name for the logged in user. AC authentication is out the scope of the
++ * web application itself. It is up to the developer to setup authentication as they please in the J2EE
++ * container used to run the web application. Whatever authentication mechanism they use, they should then
++ * set the attribute into the HttpSession object. The Admin Console will be able to read that value
++ * (default to "guest") in. ((HttpServletRequest)
++ * request).getSession().setAttribute("xacml.rest.admin.user.name", "Homer");
+ */
- public static final String PROP_ADMIN_USER_NAME = "xacml.rest.admin.user.name";
++ public static final String PROP_ADMIN_USER_NAME = "xacml.rest.admin.user.name";
+ /**
- *
- * PROP_ADMIN_USER_ID is an id for the logged in user.
- *
- * Eg. hs1234
++ * PROP_ADMIN_USER_ID is an id for the logged in user. Eg. hs1234
+ *
+ * @see #PROP_ADMIN_USER_NAME for more information.
+ */
- public static final String PROP_ADMIN_USER_ID = "xacml.rest.admin.user.id";
++ public static final String PROP_ADMIN_USER_ID = "xacml.rest.admin.user.id";
+ /**
- *
+ * PROP_ADMIN_USER_EMAIL is a user's email address.
+ *
+ * @see #PROP_ADMIN_USER_NAME for more information.
+ */
- public static final String PROP_ADMIN_USER_EMAIL = "xacml.rest.admin.user.email";
++ public static final String PROP_ADMIN_USER_EMAIL = "xacml.rest.admin.user.email";
+ /**
- * Directory path containing sub-directories where the Subscriber servlet puts files sent through data feeds.
++ * Directory path containing sub-directories where the Subscriber servlet puts files sent through data
++ * feeds.
+ */
- public static final String PROP_SUBSCRIBER_INCOMING = "xacml.subscriber.incoming";
++ public static final String PROP_SUBSCRIBER_INCOMING = "xacml.subscriber.incoming";
+ /**
+ * The specific data feed name for the Subscriber servlet to register for.
+ */
- public static final String PROP_SUBSCRIBER_FEED = "xacml.subscriber.feed";
++ public static final String PROP_SUBSCRIBER_FEED = "xacml.subscriber.feed";
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/dom/DOMResponseConformanceTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/dom/DOMResponseConformanceTest.java
index ddd1a1b,0000000..bafebf4
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/dom/DOMResponseConformanceTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/dom/DOMResponseConformanceTest.java
@@@ -1,205 -1,0 +1,190 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.std.dom;
+
+import static org.junit.Assert.fail;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openaz.xacml.api.Response;
+import org.apache.openaz.xacml.std.dom.DOMResponse;
+import org.junit.Test;
+
+/**
- * Tests for handling the XML version of the XACML Response object.
- *
- * TO RUN - use jUnit
- * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
- *
- * Normally the Response is generated by the PDP and returned through the RESTful interface as JSON.
- * Testing of the XML interface is minimal and not complete.
- *
- *
- *
- *
++ * Tests for handling the XML version of the XACML Response object. TO RUN - use jUnit In Eclipse select this
++ * file or the enclosing directory, right-click and select Run As/JUnit Test Normally the Response is
++ * generated by the PDP and returned through the RESTful interface as JSON. Testing of the XML interface is
++ * minimal and not complete.
+ */
+public class DOMResponseConformanceTest {
+
+ // where to find the conformance test XML files
+ private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4";
+
+ // The request object output from each test conversion from JSON string
+ Response response;
+
-
-
- // Load the Conformance test responses into Response objects, generate the output XML for that Response and compare with the original files.
++ // Load the Conformance test responses into Response objects, generate the output XML for that Response
++ // and compare with the original files.
+ @Test
+ public void testDOMResponse() {
+ List<File> filesInDirectory = null;
+
+ File conformanceDirectory = null;
+
+ File currentFile = null;
+
+ try {
+ conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH);
+ filesInDirectory = getRequestsInDirectory(conformanceDirectory);
+ } catch (Exception e) {
- fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e);
++ fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()
++ + "' e=" + e);
+ }
+
+ // run through each XML file
- // - load the file from XML into an internal Response object
- // - generate the XML representation from that Response object
- // - reload the file into a String
- // - compare the 2 XML strings
++ // - load the file from XML into an internal Response object
++ // - generate the XML representation from that Response object
++ // - reload the file into a String
++ // - compare the 2 XML strings
+ Response xmlResponse = null;
+ try {
+ for (File f : filesInDirectory) {
+ currentFile = f;
+
- //// This is a simple way to select just one file for debugging - comment out when not being used
- //if ( ! f.getName().equals("IID302Response.xml")) { continue; }
-
- // during debugging it is helpful to know what file it is starting to work on
- // System.out.println("starting file="+currentFile.getName());
++ // // This is a simple way to select just one file for debugging - comment out when not being
++ // used
++ // if ( ! f.getName().equals("IID302Response.xml")) { continue; }
+
++ // during debugging it is helpful to know what file it is starting to work on
++ // System.out.println("starting file="+currentFile.getName());
+
+ BufferedReader br = new BufferedReader(new FileReader(f));
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ br.close();
+
+ String xmlFromFile = sb.toString();
+
+ try {
+ // load XML into a Response object
+ xmlResponse = DOMResponse.load(xmlFromFile);
+ } catch (Exception e) {
+ // if XML does not load, just note it and continue with next file
+ System.out.println("XML file did not load: '" + f.getName() + " e=" + e);
+ continue;
+ }
- //System.out.println(xmlFromFile);
++ // System.out.println(xmlFromFile);
+
+ // create String version from the Response object
+ String xmlResponseString = DOMResponse.toString(xmlResponse, false);
+
+ // Comparing the string directly to the String from the file is difficult.
- // We can minimize the problems with newlines and whitespace, but we have other issues with how various object values are represented.
- // For instance, and input double of "23.50" is output as "23.5" which is the same value but not identical strings.
- // Therefore we take the XML output and use it to create a new Response object, then compare the two objects.
-
- //System.out.println(xmlResponseString);
++ // We can minimize the problems with newlines and whitespace, but we have other issues with
++ // how various object values are represented.
++ // For instance, and input double of "23.50" is output as "23.5" which is the same value but
++ // not identical strings.
++ // Therefore we take the XML output and use it to create a new Response object, then compare
++ // the two objects.
++
++ // System.out.println(xmlResponseString);
+ Response reGeneratedResponse = DOMResponse.load(xmlResponseString);
+
- if ( ! xmlResponse.equals(reGeneratedResponse)) {
++ if (!xmlResponse.equals(reGeneratedResponse)) {
+ String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", "");
+ normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " ");
+ normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><");
- System.out.println("File="+normalizedFromFile);
- System.out.println("Gend="+ xmlResponseString);
++ System.out.println("File=" + normalizedFromFile);
++ System.out.println("Gend=" + xmlResponseString);
+
+ System.out.println(DOMResponse.toString(xmlResponse, true));
+
+ fail("Output string did not re-generate eqivilent object.");
+ }
+
- // // Normally whitespace is significant in XML.
- // // However in this case we are generating an XML string for output and comparing it to a hand-made file.
- // // The file may contain extra newlines or fewer spaces then our prettyPrinted output version.
- // // Therefore we do the comparison on the un-prettyPrinted generated string.
- // // To do this we have to remove the extra whitespace from the version read from the file.
- // String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", "");
- // normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " ");
- // normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><");
- //
- // if ( ! xmlResponseString.equals(normalizedFromFile)) {
- // System.out.println("file="+normalizedFromFile+"\ngend="+xmlResponseString);
- // fail("file not same as generated string: " + f.getName()+ "\nFile="+xmlFromFile + "\nString="+xmlResponseString);
- // }
-
++ // // Normally whitespace is significant in XML.
++ // // However in this case we are generating an XML string for output and comparing it to a
++ // hand-made file.
++ // // The file may contain extra newlines or fewer spaces then our prettyPrinted output
++ // version.
++ // // Therefore we do the comparison on the un-prettyPrinted generated string.
++ // // To do this we have to remove the extra whitespace from the version read from the file.
++ // String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", "");
++ // normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " ");
++ // normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><");
++ //
++ // if ( ! xmlResponseString.equals(normalizedFromFile)) {
++ // System.out.println("file="+normalizedFromFile+"\ngend="+xmlResponseString);
++ // fail("file not same as generated string: " + f.getName()+ "\nFile="+xmlFromFile +
++ // "\nString="+xmlResponseString);
++ // }
+
+ }
+
+ } catch (Exception e) {
- fail ("Failed test with '" + currentFile.getName() + "', e=" + e);
++ fail("Failed test with '" + currentFile.getName() + "', e=" + e);
+ }
+
-
+ }
+
-
-
+ //
+ // HELPER to get list of all Request files in the given directory
+ //
+
+ private List<File> getRequestsInDirectory(File directory) {
+ List<File> fileList = new ArrayList<File>();
+
+ File[] fileArray = directory.listFiles();
+ for (File f : fileArray) {
+ if (f.isDirectory()) {
+ List<File> subDirList = getRequestsInDirectory(f);
+ fileList.addAll(subDirList);
+ }
+ if (f.getName().endsWith("Response.xml")) {
+ fileList.add(f);
+ }
+ }
+ return fileList;
+
+ }
+
-
+}
+
-
+/*
- Place to edit long strings output during tests
-
-
-
-
-
-
-
-
- */
++ * Place to edit long strings output during tests
++ */