⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 argnode.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this 
* list of conditions and the following disclaimer.
* 
* Redistributions 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 the University of Salford nor the names of its 
* contributors may be used to endorse or promote products derived from this 
* software without specific prior written permission. 
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
* POSSIBILITY OF SUCH DAMAGE.
*/

package issrg.pba.rbac.xmlpolicy.ifstatement;

/**
 * This is the class that represents an Arg node and evaluates the arguments of 
 * an
 * action at run-time.
 *
 * <p>If the policy contains the arguments of types for which there is no 
 * constructor provided
 * by the AEF (not registered with the Types), or the AEF failed to provide the 
 * argument with the name
 * stated in the policy, an EvaluationException will occur at run-time.
 *
 * <p>Note that if the evaluation does not reach the point where the argument 
 * is needed, no
 * exception will be thrown.
 *
 * @author A.Otenko
 */

public class ArgNode extends TermNode {
  /**
   * This is the name of the node that represents the Arg - a reference to an 
   * argument of the
   * action being authorised.
   */
  public final static String ARG_NODE = "Arg";

  /**
   * This method should be called to register the node with the XML Parser
   */
  public static void register(){
    try{
      issrg.pba.rbac.xmlpolicy.XMLPolicyParser.registerXMLNode(ARG_NODE, ArgNode.class);
    }catch (NoSuchMethodException nsme){
      nsme.printStackTrace();
    }
  }

  protected String type;
  protected String parameter_name;

  protected ArgNode() {}

  /**
   * This constructor builds an ArgNode, given a XMLPolicyParser and the
   * set of attributes of this XML element. It expects that a 
   * issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE and 
   * issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE ("Type" and "Name") are 
   * present in this XML element.
   *
   * @param p - the XMLPolicyParser that builds this ArgNode
   * @param attr - the attributes of this XML element
   */
  public ArgNode(issrg.pba.rbac.xmlpolicy.XMLPolicyParser p, org.xml.sax.Attributes attr) throws issrg.pba.rbac.PolicyParsingException {
    super(ARG_NODE, attr, -1, 0);

    type=((String)getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE)).intern();
    if (type==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.TYPE_ATTRIBUTE+" attribute was expected in "+ARG_NODE);
    parameter_name=(String)getAttributes().get(issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE);
    if (type==null) throw new issrg.pba.rbac.PolicyParsingException(issrg.pba.rbac.xmlpolicy.XMLTags.NAME_ATTRIBUTE+" attribute was expected in "+ARG_NODE);
  }

  /**
   * This method returns the type of this argument.
   */
  public String getType(){
    return type;
  }

  /**
   * This method returns the value of the action argument that this element 
   * refers to. Types.construct() method is used to convert the String 
   * representation of the argument value in the Environment into a Java object.
   *
   * @param env - the Environment of the evaluation, including the arguments
   *   of the Action
   *
   * @return the Object, constructed from the String representation of the
   *   argument value
   */
  public Object evaluate(Environment env) throws EvaluationException{
    try{
      issrg.pba.rbac.Argument arg = (issrg.pba.rbac.Argument)env.getArgs().get(parameter_name);

      if (arg==null || arg.getType().intern()!=type){
        throw new EvaluationException("No such argument to the action: "+parameter_name+" of type "+type);
      }

      return Types.construct(type, arg.getValue());
    }catch (Throwable th){
      throw new EvaluationException("Evaluation run-time error", th);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -