Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30273/com/sun/xacml/attr
Modified Files:
AttributeDesignator.java AttributeFactory.java
DateAttribute.java DateTimeAttribute.java
IPAddressAttribute.java PortRange.java
StandardAttributeFactory.java TimeAttribute.java
Added Files:
IPv4AddressAttribute.java IPv6AddressAttribute.java
Log Message:
Added support for the XACML 2.0 functions, cleaned up current env handling
and date/time construction, and made most of the factory-related changes
to support the promised 2.0 features
Index: DateAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/DateAttribute.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DateAttribute.java 17 Mar 2004 18:03:38 -0000 1.2
--- DateAttribute.java 13 Jan 2006 22:32:50 -0000 1.3
***************
*** 235,244 ****
*/
public DateAttribute() {
super(identifierURI);
// Get the current time and GMT offset
! Date currDate = new Date();
! int currOffset = DateTimeAttribute.getDefaultTZOffset(currDate);
! long millis = currDate.getTime();
// Now find out the last time it was midnight local time
--- 235,256 ----
*/
public DateAttribute() {
+ this(new Date());
+ }
+
+ /**
+ * Creates a new <code>TimeAttribute</code> that represents
+ * the given date with default timezone values.
+ *
+ * @param date a <code>Date</code> object representing the
+ * instant at which the specified date began (midnight)
+ * in the specified time zone (the actual time value
+ * will be forced to midnight)
+ */
+ public DateAttribute(Date date) {
super(identifierURI);
// Get the current time and GMT offset
! int currOffset = DateTimeAttribute.getDefaultTZOffset(date);
! long millis = date.getTime();
// Now find out the last time it was midnight local time
***************
*** 252,257 ****
// Skip forward by time zone offset.
millis -= currOffset * MILLIS_PER_MINUTE;
! currDate.setTime(millis);
! init(currDate, currOffset, currOffset);
}
--- 264,269 ----
// Skip forward by time zone offset.
millis -= currOffset * MILLIS_PER_MINUTE;
! date.setTime(millis);
! init(date, currOffset, currOffset);
}
Index: AttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/AttributeFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** AttributeFactory.java 17 May 2004 20:33:45 -0000 1.7
--- AttributeFactory.java 13 Jan 2006 22:32:50 -0000 1.8
***************
*** 3,7 ****
* @(#)AttributeFactory.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)AttributeFactory.java
*
! * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 38,45 ****
--- 38,47 ----
import com.sun.xacml.ParsingException;
+ import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.UnknownIdentifierException;
import java.net.URI;
+ import java.util.HashMap;
import java.util.Set;
***************
*** 63,76 ****
private static AttributeFactoryProxy defaultFactoryProxy;
/**
! * static intialiazer that sets up the default factory proxy
! * NOTE: this will change when the right setup mechanism is in place
*/
static {
! defaultFactoryProxy = new AttributeFactoryProxy() {
public AttributeFactory getFactory() {
return StandardAttributeFactory.getFactory();
}
};
};
--- 65,87 ----
private static AttributeFactoryProxy defaultFactoryProxy;
+ // the map of registered factories
+ private static HashMap registeredFactories;
+
/**
! * static intialiazer that sets up the default factory proxy and
! * registers the standard namespaces
*/
static {
! AttributeFactoryProxy proxy = new AttributeFactoryProxy() {
public AttributeFactory getFactory() {
return StandardAttributeFactory.getFactory();
}
};
+
+ registeredFactories = new HashMap();
+ registeredFactories.put(PolicyMetaData.XACML_1_0_IDENTIFIER, proxy);
+ registeredFactories.put(PolicyMetaData.XACML_2_0_IDENTIFIER, proxy);
+
+ defaultFactoryProxy = proxy;
};
***************
*** 94,99 ****
/**
! * Sets the default factory. Note that this is just a placeholder for
! * now, and will be replaced with a more useful mechanism soon.
*/
public static final void setDefaultFactory(AttributeFactoryProxy proxy) {
--- 105,140 ----
/**
! * Returns a factory based on the given identifier. You may register
! * as many factories as you like, and then retrieve them through this
! * interface, but a factory may only be registered once using a given
! * identifier. By default, the standard XACML 1.0 and 2.0 identifiers
! * are regsietered to provide the standard factory.
! *
! * @param identifier the identifier for a factory
! *
! * @return an <code>AttributeFactory</code>
! *
! * @throws UnknownIdentifierException if the given identifier isn't
! * registered
! */
! public static final AttributeFactory getInstance(String identifier)
! throws UnknownIdentifierException
! {
! AttributeFactoryProxy proxy =
! (AttributeFactoryProxy)(registeredFactories.get(identifier));
!
! if (proxy == null)
! throw new UnknownIdentifierException("Uknown AttributeFactory " +
! "identifier: " + identifier);
!
! return proxy.getFactory();
! }
!
! /**
! * Sets the default factory. This does not register the factory proxy as
! * an identifiable factory.
! *
! * @param proxy the <code>AttributeFactoryProxy</code> to set as the new
! * default factory proxy
*/
public static final void setDefaultFactory(AttributeFactoryProxy proxy) {
***************
*** 102,105 ****
--- 143,173 ----
/**
+ * Registers the given factory proxy with the given identifier. If the
+ * identifier is already used, then this throws an exception. If the
+ * identifier is not already used, then it will always be bound to the
+ * given proxy.
+ *
+ * @param identifier the identifier for the proxy
+ * @param proxy the <code>AttributeFactoryProxy</code> to register with
+ * the given identifier
+ *
+ * @throws IllegalArgumentException if the identifier is already used
+ */
+ public static final void registerFactory(String identifier,
+ AttributeFactoryProxy proxy)
+ throws IllegalArgumentException
+ {
+ synchronized (registeredFactories) {
+ if (registeredFactories.containsKey(identifier))
+ throw new IllegalArgumentException("Identifier is already " +
+ "registered as " +
+ "AttributeFactory: " +
+ identifier);
+
+ registeredFactories.put(identifier, proxy);
+ }
+ }
+
+ /**
* Adds a proxy to the factory, which in turn will allow new attribute
* types to be created using the factory. Typically the proxy is
***************
*** 128,132 ****
* factory. The static versions of these methods have been
* left in for now, but are slower and will be removed in
! * a future version.
*
* @param id the name of the attribute type
--- 196,201 ----
* factory. The static versions of these methods have been
* left in for now, but are slower and will be removed in
! * a future version. Note that this operates only on the
! * default factory.
*
* @param id the name of the attribute type
Index: AttributeDesignator.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/AttributeDesignator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AttributeDesignator.java 5 Dec 2005 23:34:51 -0000 1.9
--- AttributeDesignator.java 13 Jan 2006 22:32:50 -0000 1.10
***************
*** 3,7 ****
* @(#)AttributeDesignator.java
*
! * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)AttributeDesignator.java
*
! * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 207,214 ****
throws ParsingException
{
! return getInstance(root, target,
! new PolicyMetaData(
! PolicyMetaData.XACML_VERSION_1_0,
! PolicyMetaData.XPATH_VERSION_UNSPECIFIED));
}
--- 207,211 ----
throws ParsingException
{
! return getInstance(root, target, new PolicyMetaData());
}
--- NEW FILE: IPv4AddressAttribute.java ---
/*
* @(#)IPv4AddressAttribute.java
*
* Copyright 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 java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Subclass of <code>IPAddressAttribute</code> that handles the specifics
* of IPv4. In general, you shouldn't need to interact with this class
* except to create an instance directly.
*
* @since 2.0
* @author Seth Proctor
*/
public class IPv4AddressAttribute extends IPAddressAttribute
{
/**
* Creates the new <code>IPv4AddressAttribute</code> with just the required
* address component.
*
* @param address a non-null <code>InetAddress</code>
*/
public IPv4AddressAttribute(InetAddress address) {
this(address, null, new PortRange());
}
/**
* Creates the new <code>IPv4AddressAttribute</code> with the optional
* address mask.
*
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
*/
public IPv4AddressAttribute(InetAddress address, InetAddress mask) {
this(address, mask, new PortRange());
}
/**
* Creates the new <code>IPv4AddressAttribute</code> with the optional
* port range.
*
* @param address a non-null <code>InetAddress</code>
* @param portRange a non-null <code>PortRange</code>
*/
public IPv4AddressAttribute(InetAddress address, PortRange range) {
this(address, null, range);
}
/**
* Creates the new <code>IPv4AddressAttribute</code> with all the optional
* components.
*
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
* @param portRange a non-null <code>PortRange</code>
*/
public IPv4AddressAttribute(InetAddress address, InetAddress mask,
PortRange range) {
super(address, mask, range);
}
/**
* Returns a new <code>IPv4AddressAttribute</code> that represents
* the name indicated by the <code>String</code> provided. This is a
* protected method because you should never call it directly.
* Instead, you should call <code>getInstance</code> on
* <code>IPAddressAttribute</code> which provides versions that
* take both a <code>String</code> and a <code>Node</code> and
* will determine the protocol version correctly.
*
* @param value a string representing the address
*
* @return a new <code>IPAddressAttribute</code>
*
* @throws UnknownHostException if the address components is invalid
* @throws ParsingException if any of the address components is invalid
*/
protected static IPAddressAttribute getV4Instance(String value)
throws UnknownHostException
{
InetAddress address = null;
InetAddress mask = null;
PortRange range = null;
// start out by seeing where the delimiters are
int maskPos = value.indexOf("/");
int rangePos = value.indexOf(":");
// now check to see which components we have
if (maskPos == rangePos) {
// the sting is just an address
address = InetAddress.getByName(value);
} else if (maskPos != -1) {
// there is also a mask (and maybe a range)
address = InetAddress.getByName(value.substring(0, maskPos));
if (rangePos != -1) {
// there's a range too, so get it and the mask
mask =
InetAddress.getByName(value.substring(maskPos + 1,
rangePos));
range =
PortRange.getInstance(value.substring(rangePos + 1,
value.length()));
} else {
// there's no range, so just get the mask
mask = InetAddress.getByName(value.substring(maskPos + 1,
value.length()));
}
} else {
// there is a range, but no mask
address = InetAddress.getByName(value.substring(0, rangePos));
range = PortRange.getInstance(value.substring(rangePos + 1,
value.length()));
}
// if the range is null, then create it as unbound
range = new PortRange();
return new IPv4AddressAttribute(address, mask, range);
}
/**
*
*/
public String encode() {
String str = getAddress().getHostAddress();
if (getMask() != null)
str += getMask().getHostAddress();
if (! getRange().isUnbound())
str += ":" + getRange().encode();
return str;
}
}
Index: PortRange.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/PortRange.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PortRange.java 16 Dec 2005 22:42:37 -0000 1.1
--- PortRange.java 13 Jan 2006 22:32:51 -0000 1.2
***************
*** 203,207 ****
*/
public boolean equals(Object o) {
! if (! (o instanceof IPAddressAttribute))
return false;
--- 203,207 ----
*/
public boolean equals(Object o) {
! if (! (o instanceof PortRange))
return false;
--- NEW FILE: IPv6AddressAttribute.java ---
/*
* @(#)IPv6AddressAttribute.java
*
* Copyright 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 java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Subclass of <code>IPAddressAttribute</code> that handles the specifics
* of IPv6. In general, you shouldn't need to interact with this class
* except to create an instance directly.
*
* @since 2.0
* @author Seth Proctor
*/
public class IPv6AddressAttribute extends IPAddressAttribute
{
/**
* Creates the new <code>IPv6AddressAttribute</code> with just the required
* address component.
*
* @param address a non-null <code>InetAddress</code>
*/
public IPv6AddressAttribute(InetAddress address) {
this(address, null, new PortRange());
}
/**
* Creates the new <code>IPv6AddressAttribute</code> with the optional
* address mask.
*
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
*/
public IPv6AddressAttribute(InetAddress address, InetAddress mask) {
this(address, mask, new PortRange());
}
/**
* Creates the new <code>IPv6AddressAttribute</code> with the optional
* port range.
*
* @param address a non-null <code>InetAddress</code>
* @param portRange a non-null <code>PortRange</code>
*/
public IPv6AddressAttribute(InetAddress address, PortRange range) {
this(address, null, range);
}
/**
* Creates the new <code>IPv6AddressAttribute</code> with all the optional
* components.
*
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
* @param portRange a non-null <code>PortRange</code>
*/
public IPv6AddressAttribute(InetAddress address, InetAddress mask,
PortRange range) {
super(address, mask, range);
}
/**
* Returns a new <code>IPv6AddressAttribute</code> that represents
* the name indicated by the <code>String</code> provided. This is a
* protected method because you should never call it directly.
* Instead, you should call <code>getInstance</code> on
* <code>IPAddressAttribute</code> which provides versions that
* take both a <code>String</code> and a <code>Node</code> and
* will determine the protocol version correctly.
*
* @param value a string representing the address
*
* @return a new <code>IPAddressAttribute</code>
*
* @throws UnknownHostException if the address components is invalid
* @throws ParsingException if any of the address components is invalid
*/
protected static IPAddressAttribute getV6Instance(String value)
throws UnknownHostException
{
InetAddress address = null;
InetAddress mask = null;
PortRange range = null;
int len = value.length();
// get the required address component
int endIndex = value.indexOf(']');
address = InetAddress.getByName(value.substring(1, endIndex));
// see if there's anything left in the string
if (endIndex != (len - 1)) {
// if there's a mask, it's also an IPv6 address
if (value.charAt(endIndex + 1) == '/') {
int startIndex = endIndex + 3;
endIndex = value.indexOf(']', startIndex);
mask = InetAddress.getByName(value.substring(startIndex,
endIndex));
}
// finally, see if there's a port range, if we're not finished
if ((endIndex != (len - 1)) && (value.charAt(endIndex + 1) == ':'))
range = PortRange.getInstance(value.substring(endIndex + 2,
len));
}
// if the range is null, then create it as unbound
range = new PortRange();
return new IPv6AddressAttribute(address, mask, range);
}
/**
*
*/
public String encode() {
String str = "[" + getAddress().getHostAddress() + "]";
if (getMask() != null)
str += "/[" + getMask().getHostAddress() + "]";
if (! getRange().isUnbound())
str += ":" + getRange().encode();
return str;
}
}
Index: IPAddressAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/IPAddressAttribute.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IPAddressAttribute.java 16 Dec 2005 22:42:37 -0000 1.1
--- IPAddressAttribute.java 13 Jan 2006 22:32:50 -0000 1.2
***************
*** 49,57 ****
* Represents the IPAddress datatype introduced in XACML 2.0. All objects of
* this class are immutable and all methods of the class are thread-safe.
*
* @since 2.0
* @author Seth Proctor
*/
! public class IPAddressAttribute extends AttributeValue
{
--- 49,65 ----
* Represents the IPAddress datatype introduced in XACML 2.0. All objects of
* this class are immutable and all methods of the class are thread-safe.
+ * <p>
+ * To create an instance of an ipAddress from an encoded String or a DOM
+ * Node you should use the <code>getInstance</code> methods provided by
+ * this class. To construct an ipAddress instance directly, you must use
+ * the constructors provided by <code>IPv4AddressAttribute</code> and
+ * <code>IPv6AddressAttribute</code>. These will both create an attribute
+ * of XACML type ipAddress, but will handle the differences in these
+ * two representations correctly.
*
* @since 2.0
* @author Seth Proctor
*/
! public abstract class IPAddressAttribute extends AttributeValue
{
***************
*** 104,139 ****
/**
- * Creates the new <code>IPAddressAttribute</code> with just the required
- * address component.
- *
- * @param address a non-null <code>InetAddress</code>
- */
- public IPAddressAttribute(InetAddress address) {
- this(address, null, new PortRange());
- }
-
- /**
- * Creates the new <code>IPAddressAttribute</code> with the optional
- * address mask.
- *
- * @param address a non-null <code>InetAddress</code>
- * @param mask an <code>InetAddress</code> or null if there is no mask
- */
- public IPAddressAttribute(InetAddress address, InetAddress mask) {
- this(address, mask, new PortRange());
- }
-
- /**
- * Creates the new <code>IPAddressAttribute</code> with the optional
- * port range.
- *
- * @param address a non-null <code>InetAddress</code>
- * @param portRange a <code>PortRange</code>
- */
- public IPAddressAttribute(InetAddress address, PortRange range) {
- this(address, null, range);
- }
-
- /**
* Creates the new <code>IPAddressAttribute</code> with all the optional
* components.
--- 112,115 ----
***************
*** 141,148 ****
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
! * @param portRange a <code>PortRange</code>
*/
! public IPAddressAttribute(InetAddress address, InetAddress mask,
! PortRange range) {
super(identifierURI);
--- 117,124 ----
* @param address a non-null <code>InetAddress</code>
* @param mask an <code>InetAddress</code> or null if there is no mask
! * @param portRange a non-null <code>PortRange</code>
*/
! protected IPAddressAttribute(InetAddress address, InetAddress mask,
! PortRange range) {
super(identifierURI);
***************
*** 189,195 ****
// an IPv6 address starts with a '['
if (value.indexOf('[') == 0)
! return getIPv6Address(value);
else
! return getIPv4Address(value);
} catch (UnknownHostException uhe) {
throw new ParsingException("Failed to parse an IPAddress", uhe);
--- 165,171 ----
// an IPv6 address starts with a '['
if (value.indexOf('[') == 0)
! return IPv6AddressAttribute.getV6Instance(value);
else
! return IPv4AddressAttribute.getV4Instance(value);
} catch (UnknownHostException uhe) {
throw new ParsingException("Failed to parse an IPAddress", uhe);
***************
*** 198,286 ****
/**
- * Handle parsing an IPv4 address
- */
- private static IPAddressAttribute getIPv4Address(String value)
- throws UnknownHostException
- {
- InetAddress address = null;
- InetAddress mask = null;
- PortRange range = null;
-
- // start out by seeing where the delimiters are
- int maskPos = value.indexOf("/");
- int rangePos = value.indexOf(":");
-
- // now check to see which components we have
- if (maskPos == rangePos) {
- // the sting is just an address
- address = InetAddress.getByName(value);
- } else if (maskPos != -1) {
- // there is also a mask (and maybe a range)
- address = InetAddress.getByName(value.substring(0, maskPos));
- if (rangePos != -1) {
- // there's a range too, so get it and the mask
- mask =
- InetAddress.getByName(value.substring(maskPos + 1,
- rangePos));
- range =
- PortRange.getInstance(value.substring(rangePos + 1,
- value.length()));
- } else {
- // there's no range, so just get the mask
- mask = InetAddress.getByName(value.substring(maskPos + 1,
- value.length()));
- }
- } else {
- // there is a range, but no mask
- address = InetAddress.getByName(value.substring(0, rangePos));
- range = PortRange.getInstance(value.substring(rangePos + 1,
- value.length()));
- }
-
- // if the range is null, then create it as unbound
- range = new PortRange();
-
- return new IPAddressAttribute(address, mask, range);
- }
-
-
- /**
- * Handle parsing an IPv6 address
- */
- private static IPAddressAttribute getIPv6Address(String value)
- throws UnknownHostException
- {
- InetAddress address = null;
- InetAddress mask = null;
- PortRange range = null;
- int len = value.length();
-
- // get the required address component
- int endIndex = value.indexOf(']');
- address = InetAddress.getByName(value.substring(1, endIndex));
-
- // see if there's anything left in the string
- if (endIndex != (len - 1)) {
- // if there's a mask, it's also an IPv6 address
- if (value.charAt(endIndex + 1) == '/') {
- int startIndex = endIndex + 3;
- endIndex = value.indexOf(']', startIndex);
- mask = InetAddress.getByName(value.substring(startIndex,
- endIndex));
- }
-
- // finally, see if there's a port range, if we're not finished
- if ((endIndex != (len - 1)) && (value.charAt(endIndex + 1) == ':'))
- range = PortRange.getInstance(value.substring(endIndex + 2,
- len));
- }
-
- // if the range is null, then create it as unbound
- range = new PortRange();
-
- return new IPAddressAttribute(address, mask, range);
- }
-
- /**
* Returns the address represented by this object.
*
--- 174,177 ----
***************
*** 367,384 ****
}
- /**
- *
- */
- public String encode() {
- String str = "[" + address.getHostAddress() + "]";
-
- if (mask != null)
- str += "/[" + mask.getHostAddress() + "]";
-
- if (! range.isUnbound())
- str += ":" + range.encode();
-
- return str;
- }
-
}
--- 258,260 ----
Index: StandardAttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/StandardAttributeFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** StandardAttributeFactory.java 13 Jul 2004 22:39:58 -0000 1.6
--- StandardAttributeFactory.java 13 Jan 2006 22:32:51 -0000 1.7
***************
*** 3,7 ****
* @(#)StandardAttributeFactory
*
! * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)StandardAttributeFactory
*
! * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 37,40 ****
--- 37,43 ----
package com.sun.xacml.attr;
+ import com.sun.xacml.PolicyMetaData;
+ import com.sun.xacml.UnknownIdentifierException;
+
import com.sun.xacml.attr.proxy.AnyURIAttributeProxy;
import com.sun.xacml.attr.proxy.Base64BinaryAttributeProxy;
***************
*** 43,49 ****
--- 46,54 ----
import com.sun.xacml.attr.proxy.DateTimeAttributeProxy;
import com.sun.xacml.attr.proxy.DayTimeDurationAttributeProxy;
+ import com.sun.xacml.attr.proxy.DNSNameAttributeProxy;
import com.sun.xacml.attr.proxy.DoubleAttributeProxy;
import com.sun.xacml.attr.proxy.HexBinaryAttributeProxy;
import com.sun.xacml.attr.proxy.IntegerAttributeProxy;
+ import com.sun.xacml.attr.proxy.IPAddressAttributeProxy;
import com.sun.xacml.attr.proxy.RFC822NameAttributeProxy;
import com.sun.xacml.attr.proxy.StringAttributeProxy;
***************
*** 54,59 ****
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
! import java.util.Map;
import java.util.logging.Logger;
--- 59,65 ----
import java.util.Collections;
import java.util.HashMap;
+ import java.util.HashSet;
import java.util.Iterator;
! import java.util.Set;
import java.util.logging.Logger;
***************
*** 64,68 ****
/**
* This factory supports the standard set of datatypes specified in XACML
! * 1.0 and 1.1. It is the default factory used by the system, and imposes
* a singleton pattern insuring that there is only ever one instance of
* this class.
--- 70,74 ----
/**
* This factory supports the standard set of datatypes specified in XACML
! * 1.x and 2.0. It is the default factory used by the system, and imposes
* a singleton pattern insuring that there is only ever one instance of
* this class.
***************
*** 88,92 ****
// the datatypes supported by this factory
! private static Map supportedDatatypes = null;
// the logger we'll use for all messages
--- 94,102 ----
// the datatypes supported by this factory
! private static HashMap supportedDatatypes = null;
!
! // the supported identifiers for each version of XACML
! private static Set supportedV1Identifiers;
! private static Set supportedV2Identifiers;
// the logger we'll use for all messages
***************
*** 111,114 ****
--- 121,125 ----
supportedDatatypes = new HashMap();
+ // the 1.x datatypes
supportedDatatypes.put(BooleanAttribute.identifier,
new BooleanAttributeProxy());
***************
*** 139,142 ****
--- 150,165 ----
supportedDatatypes.put(RFC822NameAttribute.identifier,
new RFC822NameAttributeProxy());
+
+ supportedV1Identifiers =
+ Collections.unmodifiableSet(supportedDatatypes.keySet());
+
+ // the 2.0 datatypes
+ supportedDatatypes.put(DNSNameAttribute.identifier,
+ new DNSNameAttributeProxy());
+ supportedDatatypes.put(IPAddressAttribute.identifier,
+ new IPAddressAttributeProxy());
+
+ supportedV2Identifiers =
+ Collections.unmodifiableSet(supportedDatatypes.keySet());
}
***************
*** 164,174 ****
/**
! * Returns the set of datatypes that this standard factory supports.
*
! * @return a <code>Map</code> of <code>String</code> to
! * <code>AttributeProxy</code>s
*/
! public Map getStandardDatatypes() {
! return Collections.unmodifiableMap(supportedDatatypes);
}
--- 187,233 ----
/**
! * A convenience method that returns a new instance of an
! * <codeAttributeFactory</code> that supports all of the standard
! * datatypes. The new factory allows adding support for new datatypes.
! * This method should only be used when you need a new, mutable instance
! * (eg, when you want to create a new factory that extends the set of
! * supported datatypes). In general, you should use
! * <code>getFactory</code> which is more efficient and enforces a
! * singleton pattern.
*
! * @return a new factory supporting the standard datatypes
*/
! public static AttributeFactory getNewFactory() {
! // first we make sure that everything has been initialized...
! getFactory();
!
! // ...then we create the new instance
! return new BaseAttributeFactory(supportedDatatypes);
! }
!
! /**
! * Returns the identifiers supported for the given version of XACML.
! * Because this factory supports identifiers from all versions of the
! * XACML specifications, this method is useful for getting a list of
! * which specific identifiers are supported by a given version of XACML.
! *
! * @param xacmlVersion a standard XACML identifier string, as provided
! * in <code>PolicyMetaData</code>
! *
! * @return a <code>Set</code> of identifiers
! *
! * @throws UnknownIdentifierException if the version string is unknown
! */
! public static Set getStandardDatatypes(String xacmlVersion)
! throws UnknownIdentifierException
! {
! if (xacmlVersion.equals(PolicyMetaData.XACML_1_0_IDENTIFIER)) {
! return supportedV1Identifiers;
! } else if (xacmlVersion.equals(PolicyMetaData.XACML_2_0_IDENTIFIER)) {
! return supportedV2Identifiers;
! }
!
! throw new UnknownIdentifierException("Unknown XACML version: " +
! xacmlVersion);
}
Index: DateTimeAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/DateTimeAttribute.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DateTimeAttribute.java 17 Mar 2004 18:03:38 -0000 1.3
--- DateTimeAttribute.java 13 Jan 2006 22:32:50 -0000 1.4
***************
*** 3,7 ****
* @(#)DateTimeAttribute.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)DateTimeAttribute.java
*
! * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 195,203 ****
*/
public DateTimeAttribute() {
super(identifierURI);
! Date currDate = new Date();
! int currOffset = getDefaultTZOffset(currDate);
! init(currDate, 0, currOffset, currOffset);
}
--- 195,216 ----
*/
public DateTimeAttribute() {
+ this(new Date());
+ }
+
+ /**
+ * Creates a new <code>DateTimeAttribute</code> that represents
+ * the supplied date but uses default timezone and offset values.
+ *
+ * @param dateTime a <code>Date</code> object representing the
+ * specified date and time down to second
+ * resolution. If this object has non-zero
+ * milliseconds, they are combined
+ * with the nanoseconds parameter.
+ */
+ public DateTimeAttribute(Date dateTime) {
super(identifierURI);
! int currOffset = getDefaultTZOffset(dateTime);
! init(dateTime, 0, currOffset, currOffset);
}
***************
*** 206,214 ****
* the date supplied.
*
! * @param date a <code>Date</code> object representing the
! * specified date and time down to second
! * resolution. If this object has non-zero
! * milliseconds, they are combined
! * with the nanoseconds parameter.
* @param nanoseconds the number of nanoseconds beyond the
* Date specified in the date parameter
--- 219,227 ----
* the date supplied.
*
! * @param dateTime a <code>Date</code> object representing the
! * specified date and time down to second
! * resolution. If this object has non-zero
! * milliseconds, they are combined
! * with the nanoseconds parameter.
* @param nanoseconds the number of nanoseconds beyond the
* Date specified in the date parameter
***************
*** 221,229 ****
* The offset to GMT, in minutes.
*/
! public DateTimeAttribute(Date date, int nanoseconds, int timeZone,
int defaultedTimeZone) {
super(identifierURI);
! init(date, nanoseconds, timeZone, defaultedTimeZone);
}
--- 234,242 ----
* The offset to GMT, in minutes.
*/
! public DateTimeAttribute(Date dateTime, int nanoseconds, int timeZone,
int defaultedTimeZone) {
super(identifierURI);
! init(dateTime, nanoseconds, timeZone, defaultedTimeZone);
}
Index: TimeAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/TimeAttribute.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TimeAttribute.java 17 Mar 2004 18:03:38 -0000 1.5
--- TimeAttribute.java 13 Jan 2006 22:32:51 -0000 1.6
***************
*** 3,7 ****
* @(#)TimeAttribute.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)TimeAttribute.java
*
! * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 156,164 ****
*/
public TimeAttribute() {
super(identifierURI);
! Date currDate = new Date();
! int currOffset = DateTimeAttribute.getDefaultTZOffset(currDate);
! init(currDate, 0, currOffset, currOffset);
}
--- 156,178 ----
*/
public TimeAttribute() {
+ this(new Date());
+ }
+
+ /**
+ * Creates a new <code>TimeAttribute</code> that represents
+ * the given time but uses the default timezone and offset values.
+ *
+ * @param time a <code>Date</code> object representing the
+ * specified time down to second resolution. This
+ * date should have a date of 01/01/1970. If it does
+ * not, such a date will be forced. If this object
+ * has non-zero milliseconds, they are combined
+ * with the nanoseconds parameter.
+ */
+ public TimeAttribute(Date time) {
super(identifierURI);
! int currOffset = DateTimeAttribute.getDefaultTZOffset(time);
! init(time, 0, currOffset, currOffset);
}
***************
*** 167,171 ****
* the time supplied.
*
! * @param date a <code>Date</code> object representing the
* specified time down to second resolution. This
* date should have a date of 01/01/1970. If it does
--- 181,185 ----
* the time supplied.
*
! * @param time a <code>Date</code> object representing the
* specified time down to second resolution. This
* date should have a date of 01/01/1970. If it does
***************
*** 182,186 ****
* The offset to GMT, in minutes.
*/
! public TimeAttribute(Date date, int nanoseconds, int timeZone,
int defaultedTimeZone) {
super(identifierURI);
--- 196,200 ----
* The offset to GMT, in minutes.
*/
! public TimeAttribute(Date time, int nanoseconds, int timeZone,
int defaultedTimeZone) {
super(identifierURI);
***************
*** 190,196 ****
if ((timeZone == TZ_UNSPECIFIED) &&
(defaultedTimeZone == TZ_UNSPECIFIED))
! throw new ProcessingException("default timezone must be specified");
! init(date, nanoseconds, timeZone, defaultedTimeZone);
}
--- 204,211 ----
if ((timeZone == TZ_UNSPECIFIED) &&
(defaultedTimeZone == TZ_UNSPECIFIED))
! throw new ProcessingException("default timezone must be specified"
! + "when a timezone is provided");
! init(time, nanoseconds, timeZone, defaultedTimeZone);
}
|