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

📄 attributedesignator.java

📁 sunxacml源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

/*
 * @(#)AttributeDesignator.java
 *
 * Copyright 2003-2006 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.attr;

import com.sun.xacml.EvaluationCtx;
import com.sun.xacml.Indenter;
import com.sun.xacml.MatchResult;
import com.sun.xacml.ParsingException;
import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.TargetMatch;

import com.sun.xacml.cond.Evaluatable;
import com.sun.xacml.cond.EvaluationResult;

import com.sun.xacml.ctx.Attribute;
import com.sun.xacml.ctx.Status;
import com.sun.xacml.ctx.StatusDetail;

import java.io.OutputStream;
import java.io.PrintStream;

import java.net.URI;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


/**
 * Represents all four kinds of Designators in XACML.
 *
 * @since 1.0
 * @author Seth Proctor
 */
public class AttributeDesignator implements Evaluatable
{

    /**
     * Tells designator to search in the subject section of the request
     */
    public static final int SUBJECT_TARGET = 0;

    /**
     * Tells designator to search in the resource section of the request
     */
    public static final int RESOURCE_TARGET = 1;

    /**
     * Tells designator to search in the action section of the request
     */
    public static final int ACTION_TARGET = 2;

    /**
     * Tells designator to search in the environment section of the request
     */
    public static final int ENVIRONMENT_TARGET = 3;

    /**
     * The standard URI for the default subject category value
     */
    public static final String SUBJECT_CATEGORY_DEFAULT =
        "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject";

    // helper array of strings
    static final private String [] targetTypes = { "Subject", "Resource",
                                                   "Action", "Environment" };

    // the type of designator we are
    private int target;

    // required attributes
    private URI type;
    private URI id;

    // optional attribute
    private URI issuer;

    // must resolution find something
    private boolean mustBePresent;

    // if we're a subject this is the category
    private URI subjectCategory;

    // the logger we'll use for all messages
    private static final Logger logger =
        Logger.getLogger(AttributeDesignator.class.getName());

    /**
     * Creates a new <code>AttributeDesignator</code> without the optional
     * issuer.
     *
     * @param target the type of designator as specified by the 4 member
     *               *_TARGET fields
     * @param type the data type resolved by this designator
     * @param id the attribute id looked for by this designator
     * @param mustBePresent whether resolution must find a value
     */
    public AttributeDesignator(int target, URI type, URI id,
                               boolean mustBePresent) {
        this(target, type, id, mustBePresent, null);
    }

    /**
     * Creates a new <code>AttributeDesignator</code> with the optional
     * issuer.
     *
     * @param target the type of designator as specified by the 4 member
     *               *_TARGET fields
     * @param type the data type resolved by this designator
     * @param id the attribute id looked for by this designator
     * @param mustBePresent whether resolution must find a value
     * @param issuer the issuer of the values to search for or null if no
     *               issuer is specified
     *
     * @throws IllegalArgumentException if the input target isn't a valid value
     */
    public AttributeDesignator(int target, URI type, URI id,
                               boolean mustBePresent, URI issuer) 
        throws IllegalArgumentException{
        
        // check if input target is a valid value
        if ((target != SUBJECT_TARGET) && 
            (target != RESOURCE_TARGET) &&
            (target != ACTION_TARGET) &&
            (target != ENVIRONMENT_TARGET))
            throw new IllegalArgumentException("Input target is not a valid" +
                                               "value");        
        this.target = target;
        this.type = type;
        this.id = id;
        this.mustBePresent = mustBePresent;
        this.issuer = issuer;

        subjectCategory = null;
    }

    /**
     * Sets the category if this is a SubjectAttributeDesignatorType
     *
     * @param category the subject category
     */
    public void setSubjectCategory(URI category) {
        if (target == SUBJECT_TARGET)
            subjectCategory = category;
    }

    /**
     * Creates a new <code>AttributeDesignator</code> based on the DOM
     * root of the XML data.
     * 
     * @deprecated As of 2.0 you should avoid using this method and should
     *             instead use the version that takes a
     *             <code>PolicyMetaData</code> instance. This method will
     *             only work for XACML 1.x policies.
     *
     * @param root the DOM root of the AttributeDesignatorType XML type
     * @param target the type of designator to create as specified in the
     *               four member *_TARGET fields
     *
     * @return the designator
     *
     * @throws ParsingException if the AttributeDesignatorType was invalid
     */
    public static AttributeDesignator getInstance(Node root, int target)
        throws ParsingException
    {
        return getInstance(root, target, new PolicyMetaData());
    }

    /**
     * Creates a new <code>AttributeDesignator</code> based on the DOM
     * root of the XML data.
     * 
     * @param root the DOM root of the AttributeDesignatorType XML type
     * @param target the type of designator to create as specified in the
     *               four member *_TARGET fields
     * @param metaData the meta-data associated with the containing policy
     *
     * @return the designator
     *
     * @throws ParsingException if the AttributeDesignatorType was invalid
     */
    public static AttributeDesignator getInstance(Node root, int target,
                                                  PolicyMetaData metaData)
        throws ParsingException
    {
        URI type = null;
        URI id = null;
        URI issuer = null;
        boolean mustBePresent = false;
        URI subjectCategory = null;

        NamedNodeMap attrs = root.getAttributes();

        try {
            // there's always an Id
            id = new URI(attrs.getNamedItem("AttributeId").getNodeValue());
        } catch (Exception e) {
            throw new ParsingException("Required AttributeId missing in " +
                                       "AttributeDesignator", e);
        }
        
        try {
            // there's always a data type
            type = new URI(attrs.getNamedItem("DataType").getNodeValue());
        } catch (Exception e) {

⌨️ 快捷键说明

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