Thread: [Sunxacml-commit] sunxacml/com/sun/xacml EvaluationCtx.java,1.3,1.4
Brought to you by:
farrukh_najmi,
sethp
From: <se...@us...> - 2003-08-11 21:01:06
|
Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml In directory sc8-pr-cvs1:/tmp/cvs-serv21844/com/sun/xacml Modified Files: EvaluationCtx.java Log Message: TimeAttribute fix for DST and new Time & current env features plus some small fixes and cleanups Index: EvaluationCtx.java =================================================================== RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/EvaluationCtx.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EvaluationCtx.java 22 Jul 2003 15:05:45 -0000 1.3 --- EvaluationCtx.java 11 Aug 2003 20:48:44 -0000 1.4 *************** *** 40,44 **** --- 40,47 ---- import com.sun.xacml.attr.AttributeValue; import com.sun.xacml.attr.BagAttribute; + import com.sun.xacml.attr.DateAttribute; + import com.sun.xacml.attr.DateTimeAttribute; import com.sun.xacml.attr.StringAttribute; + import com.sun.xacml.attr.TimeAttribute; import com.sun.xacml.cond.EvaluationResult; *************** *** 69,72 **** --- 72,85 ---- * class is typically instantiated whenever the PDP gets a request and * needs to perform an evaluation as a result. + * <p> + * Note that this class does some optional caching for current date, time, + * and dateTime values (defined by a boolean flag to the constructors). The + * XACML specification requires that these values always be available, but it + * does not specify whether or not they must remain constant over the course + * of an evaluation if the values are being generated by the PDP (if the + * values are provided in the Request, then obviously they will remain + * constant). The default behavior is for these environment values to be cached, + * so that (for example) the current time remains constant over the course + * of an evaluation. * * @author Seth Proctor *************** *** 120,126 **** private int scope; /** * Constructs a new <code>EvaluationCtx</code> based on the given ! * request. * * @param request the request --- 133,147 ---- private int scope; + // the cached current date, time, and datetime, which we may or may + // not be using depending on how this object was constructed + private DateAttribute currentDate; + private TimeAttribute currentTime; + private DateTimeAttribute currentDateTime; + private boolean useCachedEnvValues; + /** * Constructs a new <code>EvaluationCtx</code> based on the given ! * request. The resulting context will cache current date, time, and ! * dateTime values so they remain constant for this evaluation. * * @param request the request *************** *** 130,134 **** */ public EvaluationCtx(RequestCtx request) throws ParsingException { ! this(request, null); } --- 151,173 ---- */ public EvaluationCtx(RequestCtx request) throws ParsingException { ! this(request, null, true); ! } ! ! /** ! * Constructs a new <code>EvaluationCtx</code> based on the given ! * request. ! * ! * @param request the request ! * @param cacheEnvValues whether or not to cache the current time, date, ! * and dateTime so they are constant for the scope ! * of this evaluation ! * ! * @throws ParsingException if a required attribute is missing, or if there ! * are any problems dealing with the request data ! */ ! public EvaluationCtx(RequestCtx request, boolean cacheEnvValues) ! throws ParsingException ! { ! this(request, null, cacheEnvValues); } *************** *** 136,140 **** * Constructs a new <code>EvaluationCtx</code> based on the given * request, and supports looking outside the original request for attribute ! * values using the <code>AttributeFinder</code>. * * @param request the request --- 175,181 ---- * Constructs a new <code>EvaluationCtx</code> based on the given * request, and supports looking outside the original request for attribute ! * values using the <code>AttributeFinder</code>. The resulting context ! * will cache current date, time, and dateTime values so they remain ! * constant for this evaluation. * * @param request the request *************** *** 148,151 **** --- 189,212 ---- throws ParsingException { + this(request, finder, true); + } + + /** + * Constructs a new <code>EvaluationCtx</code> based on the given + * request, and supports looking outside the original request for attribute + * values using the <code>AttributeFinder</code>. + * + * @param request the request + * @param finder an <code>AttributeFinder</code> to use in looking for + * attributes that aren't in the request + * @param cacheEnvValues whether or not to cache the current time, date, + * and dateTime so they are constant for the scope + * of this evaluation + * + * @throws ParsingException if a required attribute is missing, or if there + * are any problems dealing with the request data + */ + public EvaluationCtx(RequestCtx request, AttributeFinder finder, + boolean cacheEnvValues) throws ParsingException { // keep track of the finder this.finder = finder; *************** *** 154,157 **** --- 215,225 ---- requestRoot = request.getDocumentRoot(); + // initialize the cached date/time values so it's clear we haven't + // retrieved them yet + this.useCachedEnvValues = cacheEnvValues; + currentDate = null; + currentTime = null; + currentDateTime = null; + // get the subjects, make sure they're correct, and setup tables subjectMap = new HashMap(); *************** *** 366,369 **** --- 434,509 ---- attr.getIssuer(), attr.getIssueInstant(), resourceId)); + } + + /** + * Returns the cached value for the current time. If The value has never + * been set by a call to <code>setCurrentTime</code>, or if caching is + * not enabled in this instance, then this will return null. Note that this + * only applies to dynamically resolved values, not those supplied in the + * Request. + * + * @return the current time or null + */ + public TimeAttribute getCurrentTime() { + return currentTime; + } + + /** + * Sets the current time for this evaluation. If caching is not enabled + * for this instance then the value is ignored. + * + * @param currentTime the dynamically resolved current time + */ + public void setCurrentTime(TimeAttribute currentTime) { + if (useCachedEnvValues) + this.currentTime = currentTime; + } + + /** + * Returns the cached value for the current date. If The value has never + * been set by a call to <code>setCurrentDate</code>, or if caching is + * not enabled in this instance, then this will return null. Note that this + * only applies to dynamically resolved values, not those supplied in the + * Request. + * + * @return the current date or null + */ + public DateAttribute getCurrentDate() { + return currentDate; + } + + /** + * Sets the current date for this evaluation. If caching is not enabled + * for this instance then the value is ignored. + * + * @param currentDate the dynamically resolved current date + */ + public void setCurrentDate(DateAttribute currentDate) { + if (useCachedEnvValues) + this.currentDate = currentDate; + } + + /** + * Returns the cached value for the current dateTime. If The value has never + * been set by a call to <code>setCurrentDateTime</code>, or if caching is + * not enabled in this instance, then this will return null. Note that this + * only applies to dynamically resolved values, not those supplied in the + * Request. + * + * @return the current date or null + */ + public DateTimeAttribute getCurrentDateTime() { + return currentDateTime; + } + + /** + * Sets the current dateTime for this evaluation. If caching is not enabled + * for this instance then the value is ignored. + * + * @param currentDateTime the dynamically resolved current dateTime + */ + public void setCurrentDateTime(DateTimeAttribute currentDateTime) { + if (useCachedEnvValues) + this.currentDateTime = currentDateTime; } |