Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/ctx
In directory sc8-pr-cvs1:/tmp/cvs-serv6049/com/sun/xacml/ctx
Modified Files:
Attribute.java RequestCtx.java
Added Files:
Subject.java
Log Message:
Added new Subject interface for RequestCtx and fixed Attribute encoding bug
--- NEW FILE: Subject.java ---
/*
* @(#)Subject.java
*
* Copyright 2003 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.ctx;
import com.sun.xacml.Indenter;
import com.sun.xacml.attr.AttributeDesignator;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.Collections;
import java.util.Set;
/**
* This class represents the collection of <code>Attribute</code>s associated
* with a particular subject.
*
* @author seth proctor
*/
public class Subject
{
// the subject's category
private URI category;
// the attributes associated with the subject
private Set attributes;
/**
* <code>URI</code> form of the default subject category
*/
public static final URI DEFAULT_CATEGORY;
// the exception thrown if the default category was invalid
private static RuntimeException earlyException = null;
/**
* Tries to initialize the default category, keeping track of the
* exception for later use (if there was a problem). Note that this
* should never happen, but the error case will be reported correctly
* if the default string is invalid.
*/
static {
URI defaultURI = null;
try {
defaultURI = new URI(AttributeDesignator.SUBJECT_CATEGORY_DEFAULT);
} catch (Exception e) {
earlyException = new IllegalArgumentException("invalid URI");
earlyException.initCause(e);
}
DEFAULT_CATEGORY = defaultURI;
}
/**
* Creates a new collection of subject attributes using the default
* subject cateorgy.
*
* @param attributes a non-null <code>Set</code> of <code>Attribute</code>
* objects
*/
public Subject(Set attributes) {
this(null, attributes);
if (earlyException != null)
throw earlyException;
}
/**
* Creates a new collection of subject attributes using the given
* subject category.
*
* @param category the subject category or null for the default category
* @param attributes a non-null <code>Set</code> of <code>Attribute</code>
* objects
*/
public Subject(URI category, Set attributes) {
if (category == null)
this.category = DEFAULT_CATEGORY;
else
this.category = category;
this.attributes = Collections.unmodifiableSet(attributes);
}
/**
* Returns the category of this subject's attributes.
*
* @return the category
*/
public URI getCategory() {
return category;
}
/**
* Returns the <code>Attribute</code>s associated with this subject.
*
* @return the immutable <code>Set</code> of <code>Attribute</code>s
*/
public Set getAttributes() {
return attributes;
}
}
Index: Attribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/ctx/Attribute.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Attribute.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- Attribute.java 22 Jul 2003 15:05:45 -0000 1.2
***************
*** 247,251 ****
if (value != null)
! encoded += ">" + value.encode() + "</Attribute>";
else
encoded += "/>";
--- 247,251 ----
if (value != null)
! encoded += ">" + value.encodeWithTags(false) + "</Attribute>";
else
encoded += "/>";
Index: RequestCtx.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/ctx/RequestCtx.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** RequestCtx.java 3 Jun 2003 18:27:04 -0000 1.3
--- RequestCtx.java 22 Jul 2003 15:05:45 -0000 1.4
***************
*** 99,109 ****
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> containing the subject data, formed
! * as described in <code>getSubjects</code>
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
* @param environment a <code>Set</code> of environment attributes
*/
! public RequestCtx(Set subjects, Set resource, Set action, Set environment) {
this(subjects, resource, action, environment, null, null);
}
--- 99,109 ----
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> of <code>Subject</code>s
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
* @param environment a <code>Set</code> of environment attributes
*/
! public RequestCtx(Set subjects, Set resource, Set action,
! Set environment) {
this(subjects, resource, action, environment, null, null);
}
***************
*** 112,117 ****
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> containing the subject data, formed
! * as described in <code>getSubjects</code>
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
--- 112,116 ----
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> of <code>Subject</code>s
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
***************
*** 127,132 ****
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> containing the subject data, formed
! * as described in <code>getSubjects</code>
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
--- 126,130 ----
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> of <code>Subject</code>s
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
***************
*** 144,149 ****
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> containing the subject data, formed
! * as described in <code>getSubjects</code>
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
--- 142,146 ----
* Constructor that creates a <code>RequestCtx</code> from components.
*
! * @param subjects a <code>Set</code> of <code>Subject</code>s
* @param resource a <code>Set</code> of <code>Attribute</code>s
* @param action a <code>Set</code> of <code>Attribute</code>s
***************
*** 158,167 ****
public RequestCtx(Set subjects, Set resource, Set action,
Set environment, Node documentRoot,
! String resourceContent) throws IllegalArgumentException{
// make sure subjects is well formed
Iterator sIter = subjects.iterator();
while (sIter.hasNext()){
! if (!(sIter.next() instanceof List))
throw new IllegalArgumentException("Subjects input is not " +
"well formed");
--- 155,164 ----
public RequestCtx(Set subjects, Set resource, Set action,
Set environment, Node documentRoot,
! String resourceContent) throws IllegalArgumentException {
// make sure subjects is well formed
Iterator sIter = subjects.iterator();
while (sIter.hasNext()){
! if (!(sIter.next() instanceof Subject))
throw new IllegalArgumentException("Subjects input is not " +
"well formed");
***************
*** 236,262 ****
if (tag.equals("Subject")) {
// see if there is a category
! ArrayList list = new ArrayList();
! Node catNode = node.getAttributes().
! getNamedItem("SubjectCategory");
!
! try {
! URI category = null;
! if (catNode != null)
category = new URI(catNode.getNodeValue());
! else
! category = new URI(AttributeDesignator.
! SUBJECT_CATEGORY_DEFAULT);
!
! list.add(category);
! } catch (Exception e) {
! throw new ParsingException("Invalid Category URI", e);
}
!
// now we get the attributes
! list.add(parseAttributes(node));
// finally, add the list to the set of subject attributes
! newSubjects.add(list);
} else if (tag.equals("Resource")) {
// For now, this code doesn't parse the content, since it's
--- 233,253 ----
if (tag.equals("Subject")) {
// see if there is a category
! Node catNode =
! node.getAttributes().getNamedItem("SubjectCategory");
! URI category = null;
! if (catNode != null) {
! try {
category = new URI(catNode.getNodeValue());
! } catch (Exception e) {
! throw new ParsingException("Invalid Category URI", e);
! }
}
!
// now we get the attributes
! Set attributes = parseAttributes(node);
// finally, add the list to the set of subject attributes
! newSubjects.add(new Subject(category, attributes));
} else if (tag.equals("Resource")) {
// For now, this code doesn't parse the content, since it's
***************
*** 326,336 ****
/**
! * Returns the subjects associated with this request. Note that this is
! * a <code>Set</code> that contains any number of <code>List</code>s.
! * Each <code>List</code> contains exactly two items: a <code>URI</code>
! * specifying the category, and a <code>Set</code> that contains
! * <code>Attribute</code>s listed in that category.
*
! * @return a <code>Set</code> of <code>List</code> objects
*/
public Set getSubjects() {
--- 317,323 ----
/**
! * Returns a <code>Set</code> containing <code>Subject</code> objects.
*
! * @return the request's subject attributes
*/
public Set getSubjects() {
***************
*** 341,345 ****
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return the <code>Set</code>
*/
public Set getResource() {
--- 328,332 ----
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return the request's resource attributes
*/
public Set getResource() {
***************
*** 350,354 ****
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return the request's action
*/
public Set getAction() {
--- 337,341 ----
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return the request's action attributes
*/
public Set getAction() {
***************
*** 359,363 ****
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return a <code>Set</code> of <code>Attribute</code> objects
*/
public Set getEnvironmentAttributes() {
--- 346,350 ----
* Returns a <code>Set</code> containing <code>Attribute</code> objects.
*
! * @return the request's environment attributes
*/
public Set getEnvironmentAttributes() {
***************
*** 412,423 ****
Iterator it = subjects.iterator();
while (it.hasNext()) {
! List list = (List)(it.next());
! String category = ((URI)(list.get(0))).toString();
! Set attrs = (Set)(list.get(1));
out.println(indent + "<Subject SubjectCategory=\"" +
! category + "\">");
! encodeAttributes(attrs, out, depth + 2, indenter);
out.println(indent + "</Subject>");
--- 399,409 ----
Iterator it = subjects.iterator();
while (it.hasNext()) {
! Subject subject = (Subject)(it.next());
out.println(indent + "<Subject SubjectCategory=\"" +
! subject.getCategory().toString() + "\">");
! encodeAttributes(subject.getAttributes(), out, depth + 2,
! indenter);
out.println(indent + "</Subject>");
|