com.waveset.policy
Class PolicyImplementation

java.lang.Object
  extended bycom.waveset.policy.PolicyImplementation
Direct Known Subclasses:
EchoPolicy, LighthouseAccountPolicy, StringQualityPolicy

public abstract class PolicyImplementation
extends java.lang.Object

Interface for classes that implement "policies". These will be the implementation classes behind the Policy objects stored in the repository.

I decided to make this an abstract class rather than interface so we could supply a collection of utility methods that most concrete subclasses will need.

A policy in the simplest case is just a validation function for a field in some object. In early prototyping, policies were "rules" which were functions of more than one value. This got lost along the way. If we want to resurect the notion that policies can be fed more than one value, they will have to be named, and the recognized names will have to be part of the prototype Policy object created by the implementation class. These could be called "policy arguments" to distinguish them from "policy attributes".

Resources have a similar notion with "account attributes", but the attributes are embodied in a User object that is passed in. Here we would probably just take a HashMap of name/values.

UPDATE: The interface has been extended to provide a generate() method. This method is responsible for generating an identifier that is consistent with the policy. The introduction of this, makes PolicyImplementation less extensible, its really only suitable for single string validation rules. We could consider separating id generation into another pluggable class, or splitting policy into two branches, one a simple string validator with generation, and another a more complex muli-valued rule.


Field Summary
static java.lang.Integer ALL_CHARS
          Defines a value used to specify that all characters checked or generated should be of the a specific character type (e.g.
static java.lang.String code_id
           
static java.lang.Integer NO_VALUE
          Defines a value used to specify that no value has been set for char rules whose valid values includes '0'.
protected static Trace trace
           
 
Constructor Summary
PolicyImplementation()
           
 
Method Summary
abstract  void check(Policy policy, java.lang.Object value, java.util.Map params, java.util.List pwdhistory, java.lang.String owner)
          similar to check, above.
abstract  void check(Policy policy, java.lang.Object value, java.lang.String owner)
          Analyzes a single value for adherance to the policy.
protected  void checkPolicyArg(Policy p)
          Checks to see if the supplied Policy object matches the implementation class.
 java.lang.Object generate(Policy policy)
          Generates a object that would pass the check() method for this policy.
 java.lang.Object generate(Policy policy, java.util.Map params, java.util.List pwdHistory)
          Generate an object that would pass the check() method for this policy.
 byte[] generateByteArray(Policy policy)
          Generates a object that would pass the check() method for this policy.
 java.lang.Object getAllowedAttributeValues(java.lang.String name)
          To help the GUI edit policy parameters, return possible values for an attribute.
protected  java.lang.Object getAttributeFromUser(Policy p, WSUser user, java.lang.String name, java.lang.Object defaultValue)
          Retrieves a policy attribute expected to be an object, stored on the user.
protected  boolean getBooleanAttribute(Policy p, java.lang.String name, boolean defaultValue)
          Retrieves a policy attribute expected to be a boolean.
 LighthouseContext getContext()
           
protected  int getIntAttribute(Policy p, java.lang.String name, int defaultValue)
          Retrieves a policy attribute expected to be an integer.
protected  int getIntAttribute(Policy p, java.lang.String name, int defaultValue, int len)
          Retrieves a policy attribute whose value can be either an integer or "All".
protected  java.lang.Object getObjectAttribute(Policy p, java.lang.String name, java.lang.Object defaultValue)
          Retrieves a policy attribute expected to be an object.
abstract  Policy getPrototype()
          Returns the prototype instance of this policy.
protected  java.lang.String getStringAttribute(Policy p, java.lang.String name, java.lang.String defaultValue)
          Retrieves a policy attribute expected to be a String If the attribute does not exist, or has no value, the "default" value is returned.
protected  java.util.List getStringListAttribute(Policy p, java.lang.String name, java.util.List defaultValues)
          Retrieves a policy attribute expected to be a list of Strings If the attribute does not exist, or has no value, the "default" value is returned.
protected  java.lang.String getUserPropertyName(Policy p)
           
 java.lang.Object getValue(Policy policy, java.util.Map params, java.lang.String owner)
          similar to check, above.
protected  void setAttributeOnUser(Policy p, WSUser user, java.lang.String name, java.lang.Object value)
          Set the value of a policy attribute on a user.
 void setContext(LighthouseContext ctx)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static final Trace trace

ALL_CHARS

public static final java.lang.Integer ALL_CHARS
Defines a value used to specify that all characters checked or generated should be of the a specific character type (e.g. numeric, alpha, upper, lower, etc.) (said another way, the limit = len)


NO_VALUE

public static final java.lang.Integer NO_VALUE
Defines a value used to specify that no value has been set for char rules whose valid values includes '0'.

Constructor Detail

PolicyImplementation

public PolicyImplementation()
Method Detail

getPrototype

public abstract Policy getPrototype()
                             throws WavesetException
Returns the prototype instance of this policy. All policy implementations must be able to return a Policy object that contains a default list of policy attributes. This is how implementations communicate what attributes they support. The attribute values of the returned object are then customized as necessary. The prototype object has no name.

Throws:
WavesetException

check

public abstract void check(Policy policy,
                           java.lang.Object value,
                           java.lang.String owner)
                    throws PolicyViolation,
                           WavesetException
Analyzes a single value for adherance to the policy.

A policy object representing a particular "instance" of this policy implementation is passed in. This object supplies zero or more "policy attributes" which can be used to tailor the behavior of the policy.

Throws:
PolicyViolation - if the value violates the policy.
WavesetException - if an internal error was encountered.

check

public abstract void check(Policy policy,
                           java.lang.Object value,
                           java.util.Map params,
                           java.util.List pwdhistory,
                           java.lang.String owner)
                    throws PolicyViolation,
                           WavesetException
similar to check, above. This policy check takes a map parameter that can be used in a policy-specific way to evaluate adherence. It also take a list of previous passwords that will be used to ensure that the new password is not in the list (history checking) For passwords, the parameter is a map of name value pairs that are attributes on the user object.

Throws:
PolicyViolation
WavesetException

getValue

public java.lang.Object getValue(Policy policy,
                                 java.util.Map params,
                                 java.lang.String owner)
                          throws WavesetException
similar to check, above. This takes the same parameters as check but returns a value. This can be used to get values for policies that the caller wants to check - like an expiration date or questions.

Throws:
WavesetException - if an internal error was encountered.

getAllowedAttributeValues

public java.lang.Object getAllowedAttributeValues(java.lang.String name)
To help the GUI edit policy parameters, return possible values for an attribute.

Returns:
an Integer if this is an integer attribute

generate

public java.lang.Object generate(Policy policy)
                          throws WavesetException
Generates a object that would pass the check() method for this policy.

Throws:
WavesetException

generate

public java.lang.Object generate(Policy policy,
                                 java.util.Map params,
                                 java.util.List pwdHistory)
                          throws WavesetException
Generate an object that would pass the check() method for this policy.

Throws:
WavesetException

generateByteArray

public byte[] generateByteArray(Policy policy)
                         throws WavesetException
Generates a object that would pass the check() method for this policy. Returns a byte array to be used when generating private data like passwords

Throws:
WavesetException

checkPolicyArg

protected void checkPolicyArg(Policy p)
                       throws WavesetException
Checks to see if the supplied Policy object matches the implementation class.

Throws:
WavesetException

getIntAttribute

protected int getIntAttribute(Policy p,
                              java.lang.String name,
                              int defaultValue)
                       throws WavesetException
Retrieves a policy attribute expected to be an integer. If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

getBooleanAttribute

protected boolean getBooleanAttribute(Policy p,
                                      java.lang.String name,
                                      boolean defaultValue)
                               throws WavesetException
Retrieves a policy attribute expected to be a boolean. If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

getObjectAttribute

protected java.lang.Object getObjectAttribute(Policy p,
                                              java.lang.String name,
                                              java.lang.Object defaultValue)
                                       throws WavesetException
Retrieves a policy attribute expected to be an object. If the attribute does not exist, or has no value, or is a List with no values, the "defaultValue" is returned.

Throws:
WavesetException

getIntAttribute

protected int getIntAttribute(Policy p,
                              java.lang.String name,
                              int defaultValue,
                              int len)
                       throws WavesetException
Retrieves a policy attribute whose value can be either an integer or "All". If "All", then the value of the integer returned is the value of "len". If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

getStringAttribute

protected java.lang.String getStringAttribute(Policy p,
                                              java.lang.String name,
                                              java.lang.String defaultValue)
                                       throws WavesetException
Retrieves a policy attribute expected to be a String If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

getStringListAttribute

protected java.util.List getStringListAttribute(Policy p,
                                                java.lang.String name,
                                                java.util.List defaultValues)
                                         throws WavesetException
Retrieves a policy attribute expected to be a list of Strings If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

getUserPropertyName

protected java.lang.String getUserPropertyName(Policy p)

getAttributeFromUser

protected java.lang.Object getAttributeFromUser(Policy p,
                                                WSUser user,
                                                java.lang.String name,
                                                java.lang.Object defaultValue)
                                         throws WavesetException
Retrieves a policy attribute expected to be an object, stored on the user. These are per-user policy values like the round robin question index and are often changed by checking a policy or getting its value. If the attribute does not exist, or has no value, the "default" value is returned.

Throws:
WavesetException

setAttributeOnUser

protected void setAttributeOnUser(Policy p,
                                  WSUser user,
                                  java.lang.String name,
                                  java.lang.Object value)
                           throws WavesetException
Set the value of a policy attribute on a user. Applications should use this rather than directly modifying the GenericObject map returned by getPolicyAttributes.

Might want a variant of this that takes a WSAttribute for symetry with getPolicyAttribute?

Throws:
WavesetException

setContext

public void setContext(LighthouseContext ctx)

getContext

public LighthouseContext getContext()