Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30273/com/sun/xacml/combine
Modified Files:
CombiningAlgFactory.java StandardCombiningAlgFactory.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: CombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/CombiningAlgFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** CombiningAlgFactory.java 17 May 2004 20:33:45 -0000 1.9
--- CombiningAlgFactory.java 13 Jan 2006 22:32:51 -0000 1.10
***************
*** 3,7 ****
* @(#)CombiningAlgFactory.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)CombiningAlgFactory.java
*
! * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 37,44 ****
--- 37,46 ----
package com.sun.xacml.combine;
+ import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.UnknownIdentifierException;
import java.net.URI;
+ import java.util.HashMap;
import java.util.Set;
***************
*** 57,70 ****
private static CombiningAlgFactoryProxy 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 CombiningAlgFactoryProxy() {
public CombiningAlgFactory getFactory() {
return StandardCombiningAlgFactory.getFactory();
}
};
};
--- 59,81 ----
private static CombiningAlgFactoryProxy 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 {
! CombiningAlgFactoryProxy proxy = new CombiningAlgFactoryProxy() {
public CombiningAlgFactory getFactory() {
return StandardCombiningAlgFactory.getFactory();
}
};
+
+ registeredFactories = new HashMap();
+ registeredFactories.put(PolicyMetaData.XACML_1_0_IDENTIFIER, proxy);
+ registeredFactories.put(PolicyMetaData.XACML_2_0_IDENTIFIER, proxy);
+
+ defaultFactoryProxy = proxy;
};
***************
*** 88,93 ****
/**
! * 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(CombiningAlgFactoryProxy proxy)
--- 99,135 ----
/**
! * 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 a <code>CombiningAlgFactory</code>
! *
! * @throws UnknownIdentifierException if the given identifier isn't
! * registered
! */
! public static final CombiningAlgFactory getInstance(String identifier)
! throws UnknownIdentifierException
! {
! CombiningAlgFactoryProxy proxy =
! (CombiningAlgFactoryProxy)(registeredFactories.get(identifier));
!
! if (proxy == null)
! throw new UnknownIdentifierException("Uknown CombiningAlgFactory "
! + "identifier: " +
! identifier);
!
! return proxy.getFactory();
! }
!
! /**
! * Sets the default factory. This does not register the factory proxy as
! * an identifiable factory.
! *
! * @param proxy the <code>CombiningAlgFactoryProxy</code> to set as the
! * new default factory proxy
*/
public static final void setDefaultFactory(CombiningAlgFactoryProxy proxy)
***************
*** 97,100 ****
--- 139,169 ----
/**
+ * 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>CombiningAlgFactoryProxy</code> to register with
+ * the given identifier
+ *
+ * @throws IllegalArgumentException if the identifier is already used
+ */
+ public static final void registerFactory(String identifier,
+ CombiningAlgFactoryProxy proxy)
+ throws IllegalArgumentException
+ {
+ synchronized (registeredFactories) {
+ if (registeredFactories.containsKey(identifier))
+ throw new IllegalArgumentException("Identifier is already " +
+ "registered as " +
+ "CombiningAlgFactory: " +
+ identifier);
+
+ registeredFactories.put(identifier, proxy);
+ }
+ }
+
+ /**
* Adds a combining algorithm to the factory. This single instance will
* be returned to anyone who asks the factory for an algorithm with the
Index: StandardCombiningAlgFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/combine/StandardCombiningAlgFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** StandardCombiningAlgFactory.java 13 Jul 2004 22:39:58 -0000 1.6
--- StandardCombiningAlgFactory.java 13 Jan 2006 22:32:51 -0000 1.7
***************
*** 3,7 ****
* @(#)StandardCombiningAlgFactory.java
*
! * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)StandardCombiningAlgFactory.java
*
! * 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.combine;
+ import com.sun.xacml.PolicyMetaData;
+ import com.sun.xacml.UnknownIdentifierException;
+
import java.util.Collections;
import java.util.HashSet;
***************
*** 48,52 ****
/**
* This factory supports the standard set of algorithms 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.
--- 51,55 ----
/**
* This factory supports the standard set of algorithms 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.
***************
*** 74,77 ****
--- 77,83 ----
private static Set supportedAlgorithms = null;
+ // identifiers for the supported algorithms
+ private static Set supportedAlgIds;
+
// the logger we'll use for all messages
private static final Logger logger =
***************
*** 93,113 ****
supportedAlgorithms = new HashSet();
supportedAlgorithms.add(new DenyOverridesRuleAlg());
supportedAlgorithms.add(new DenyOverridesPolicyAlg());
!
supportedAlgorithms.add(new OrderedDenyOverridesRuleAlg());
supportedAlgorithms.add(new OrderedDenyOverridesPolicyAlg());
supportedAlgorithms.add(new PermitOverridesRuleAlg());
supportedAlgorithms.add(new PermitOverridesPolicyAlg());
supportedAlgorithms.add(new OrderedPermitOverridesRuleAlg());
supportedAlgorithms.add(new OrderedPermitOverridesPolicyAlg());
supportedAlgorithms.add(new FirstApplicableRuleAlg());
supportedAlgorithms.add(new FirstApplicablePolicyAlg());
supportedAlgorithms.add(new OnlyOneApplicablePolicyAlg());
}
--- 99,133 ----
supportedAlgorithms = new HashSet();
+ supportedAlgIds = new HashSet();
supportedAlgorithms.add(new DenyOverridesRuleAlg());
+ supportedAlgIds.add(DenyOverridesRuleAlg.algId);
supportedAlgorithms.add(new DenyOverridesPolicyAlg());
! supportedAlgIds.add(DenyOverridesPolicyAlg.algId);
!
supportedAlgorithms.add(new OrderedDenyOverridesRuleAlg());
+ supportedAlgIds.add(OrderedDenyOverridesRuleAlg.algId);
supportedAlgorithms.add(new OrderedDenyOverridesPolicyAlg());
+ supportedAlgIds.add(OrderedDenyOverridesPolicyAlg.algId);
supportedAlgorithms.add(new PermitOverridesRuleAlg());
+ supportedAlgIds.add(PermitOverridesRuleAlg.algId);
supportedAlgorithms.add(new PermitOverridesPolicyAlg());
+ supportedAlgIds.add(PermitOverridesPolicyAlg.algId);
supportedAlgorithms.add(new OrderedPermitOverridesRuleAlg());
+ supportedAlgIds.add(OrderedPermitOverridesRuleAlg.algId);
supportedAlgorithms.add(new OrderedPermitOverridesPolicyAlg());
+ supportedAlgIds.add(OrderedPermitOverridesPolicyAlg.algId);
supportedAlgorithms.add(new FirstApplicableRuleAlg());
+ supportedAlgIds.add(FirstApplicableRuleAlg.algId);
supportedAlgorithms.add(new FirstApplicablePolicyAlg());
+ supportedAlgIds.add(FirstApplicablePolicyAlg.algId);
supportedAlgorithms.add(new OnlyOneApplicablePolicyAlg());
+ supportedAlgIds.add(OnlyOneApplicablePolicyAlg.algId);
+
+ supportedAlgIds = Collections.unmodifiableSet(supportedAlgIds);
}
***************
*** 135,144 ****
/**
! * Returns the set of algorithms that this standard factory supports.
*
! * @return a <code>Set</code> of <code>CombiningAlgorithm</code>s
*/
! public Set getStandardAlgorithms() {
! return Collections.unmodifiableSet(supportedAlgorithms);
}
--- 155,199 ----
/**
! * A convenience method that returns a new instance of a
! * <code>CombiningAlgFactory</code> that supports all of the standard
! * algorithms. The new factory allows adding support for new algorithms.
! * 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 algorithms). In general, you should use
! * <code>getFactory</code> which is more efficient and enforces a
! * singleton pattern.
*
! * @return a new factory supporting the standard algorithms
*/
! public static CombiningAlgFactory getNewFactory() {
! // first we make sure everything's been initialized...
! getFactory();
!
! // ...then we create the new instance
! return new BaseCombiningAlgFactory(supportedAlgorithms);
! }
!
! /**
! * 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 getStandardAlgorithms(String xacmlVersion)
! throws UnknownIdentifierException
! {
! if ((xacmlVersion.equals(PolicyMetaData.XACML_1_0_IDENTIFIER)) ||
! (xacmlVersion.equals(PolicyMetaData.XACML_2_0_IDENTIFIER)))
! return supportedAlgIds;
!
! throw new UnknownIdentifierException("Unknown XACML version: " +
! xacmlVersion);
}
|