policy.java
来自「sunxacml源码」· Java 代码 · 共 497 行 · 第 1/2 页
JAVA
497 行
/*
* @(#)Policy.java
*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
* AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
* AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use in
* the design, construction, operation or maintenance of any nuclear facility.
*/
package com.sun.xacml;
import com.sun.xacml.combine.CombinerParameter;
import com.sun.xacml.combine.RuleCombinerElement;
import com.sun.xacml.combine.RuleCombiningAlgorithm;
import com.sun.xacml.cond.VariableDefinition;
import com.sun.xacml.cond.VariableManager;
import com.sun.xacml.ctx.Result;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Represents one of the two top-level constructs in XACML, the PolicyType.
* This optionally contains rules, which in turn contain most of the logic of
* a policy.
*
* @since 1.0
* @author Seth Proctor
*/
public class Policy extends AbstractPolicy
{
// the set of variable definitions in this policy
private Set definitions;
/**
* Creates a new <code>Policy</code> with only the required elements.
*
* @param id the policy identifier
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param target the <code>Target</code> for this policy
*/
public Policy(URI id, RuleCombiningAlgorithm combiningAlg, Target target) {
this(id, null, combiningAlg, null, target, null, null, null);
}
/**
* Creates a new <code>Policy</code> with only the required elements
* plus rules.
*
* @param id the policy identifier
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param target the <code>Target</code> for this policy
* @param rules a list of <code>Rule</code> objects
*
* @throws IllegalArgumentException if the <code>List</code> of rules
* contains an object that is not a
* <code>Rule</code>
*/
public Policy(URI id, RuleCombiningAlgorithm combiningAlg, Target target,
List rules) {
this(id, null, combiningAlg, null, target, null, rules, null);
}
/**
* Creates a new <code>Policy</code> with the required elements plus
* a version, rules, and a String description. Note that the version
* is an XACML 2.0 feature.
*
* @param id the policy identifier
* @param version the policy version or null for the default (this must
* always be null for XACML 1.x policies)
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param description a <code>String</code> describing the policy
* @param target the <code>Target</code> for this policy
* @param rules a list of <code>Rule</code> objects
*
* @throws IllegalArgumentException if the <code>List</code> of rules
* contains an object that is not a
* <code>Rule</code>
*/
public Policy(URI id, String version, RuleCombiningAlgorithm combiningAlg,
String description, Target target, List rules) {
this(id, version, combiningAlg, description, target, null, rules,
null);
}
/**
* Creates a new <code>Policy</code> with the required elements plus
* a version, rules, a String description and policy defaults. Note that
* the version is an XACML 2.0 feature.
*
* @param id the policy identifier
* @param version the policy version or null for the default (this must
* always be null for XACML 1.x policies)
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param description a <code>String</code> describing the policy
* @param target the <code>Target</code> for this policy
* @param defaultVersion the XPath version to use
* @param rules a list of <code>Rule</code> objects
*
* @throws IllegalArgumentException if the <code>List</code> of rules
* contains an object that is not a
* <code>Rule</code>
*/
public Policy(URI id, String version, RuleCombiningAlgorithm combiningAlg,
String description, Target target, String defaultVersion,
List rules) {
this(id, version, combiningAlg, description, target, defaultVersion,
rules, null);
}
/**
* Creates a new <code>Policy</code> with the required elements plus
* a version, rules, a String description, policy defaults, and
* obligations. Note that the version is an XACML 2.0 feature.
*
* @param id the policy identifier
* @param version the policy version or null for the default (this must
* always be null for XACML 1.x policies)
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param description a <code>String</code> describing the policy
* @param target the <code>Target</code> for this policy
* @param defaultVersion the XPath version to use
* @param rules a list of <code>Rule</code> objects
* @param obligations a set of <code>Obligations</code> objects
*
* @throws IllegalArgumentException if the <code>List</code> of rules
* contains an object that is not a
* <code>Rule</code>
*/
public Policy(URI id, String version, RuleCombiningAlgorithm combiningAlg,
String description, Target target, String defaultVersion,
List rules, Set obligations) {
this(id, version, combiningAlg, description, target, defaultVersion,
rules, obligations, null);
}
/**
* Creates a new <code>Policy</code> with the required elements plus
* a version, rules, a String description, policy defaults, obligations,
* and variable definitions. Note that the version and definitions are
* XACML 2.0 features.
*
* @param id the policy identifier
* @param version the policy version or null for the default (this must
* always be null for XACML 1.x policies)
* @param combiningAlg the <code>CombiningAlgorithm</code> used on the
* rules in this set
* @param description a <code>String</code> describing the policy
* @param target the <code>Target</code> for this policy
* @param defaultVersion the XPath version to use
* @param rules a list of <code>Rule</code> objects
* @param obligations a set of <code>Obligations</code> objects
* @param definitions a set of <code>VariableDefinition</code> objects
* that must provide all definitions referenced by
* all <code>VariableReference</code>s in the policy
*
* @throws IllegalArgumentException if the <code>List</code> of rules
* contains an object that is not a
* <code>Rule</code>
*/
public Policy(URI id, String version, RuleCombiningAlgorithm combiningAlg,
String description, Target target, String defaultVersion,
List rules, Set obligations, Set definitions) {
super(id, version, combiningAlg, description, target, defaultVersion,
obligations, null);
List list = null;
// check that the list contains only rules
if (rules != null) {
list = new ArrayList();
Iterator it = rules.iterator();
while (it.hasNext()) {
Object o = it.next();
if (! (o instanceof Rule))
throw new IllegalArgumentException("non-Rule in rules");
list.add(new RuleCombinerElement((Rule)o));
}
}
setChildren(list);
// save the definitions
if (definitions == null)
this.definitions = Collections.EMPTY_SET;
else
this.definitions = Collections.
unmodifiableSet(new HashSet(definitions));
}
/**
* Creates a new <code>Policy</code> with the required and optional
* elements. If you need to provide combining algorithm parameters, you
* need to use this constructor. Note that unlike the other constructors
* in this class, the rules list is actually a list of
* <code>CombinerElement</code>s used to match a rule with any
* combiner parameters it may have.
*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?