JSecurity

org.jsecurity.web.attr
Class CookieAttribute<T>

java.lang.Object
  extended by org.jsecurity.web.attr.AbstractWebAttribute<T>
      extended by org.jsecurity.web.attr.CookieAttribute<T>
All Implemented Interfaces:
WebAttribute<T>

public class CookieAttribute<T>
extends AbstractWebAttribute<T>

A CookieAttribute stores an object as a Cookie for access on later requests.

Since:
0.2
Author:
Les Hazlewood, Peter Ledbrook

Field Summary
static int DEFAULT_MAX_AGE
          -1, indicating the cookie should expire when the browser closes.
static String DEFAULT_PATH
          null, indicating the cookie should be set on the request context root.
static boolean DEFAULT_SECURE
          Default value is false.
static int INDEFINITE
          This is the same value as Integer.MAX_VALUE, and while Tomcat does fine with cookie max age with this value, Jetty apparently has problems with it.
static int ONE_YEAR
          The number of seconds in one year (= 60 * 60 * 24 * 365).
 
Fields inherited from class org.jsecurity.web.attr.AbstractWebAttribute
checkRequestParams, checkRequestParamsFirst, DEFAULT_NAME, mutable, name
 
Constructor Summary
CookieAttribute()
           
CookieAttribute(String name)
          Constructs a CookieAttribute using a Cookie with the specified name using the request context's path and with a maxAge of -1, indicating the Cookie will persist until browser shutdown.
CookieAttribute(String name, int maxAge)
          Constructs a CookieAttribute using a Cookie with the specified name and maxAge.
CookieAttribute(String name, String path)
          Constructs a CookieAttribute using a Cookie with the specified name and path.
CookieAttribute(String name, String path, int maxAge)
          Constructs a CookieAttribute using a Cookie with the specified name, path, and maxAge.
CookieAttribute(String name, String path, int maxAge, Class<? extends PropertyEditor> editorClass)
          Constructs a CookieAttribute using a Cookie with the specified name, path, and maxAge, utilizing the specified PropertyEditor to perform value/string conversion on the object stored as a cookie.
 
Method Summary
 int getMaxAge()
          Returns the Cookie's maxAge setting.
 String getPath()
          Returns the Cookie's path setting.
 boolean isSecure()
           
 T onRetrieveValue(ServletRequest request, ServletResponse response)
           
 void onStoreValue(T value, ServletRequest servletRequest, ServletResponse servletResponse)
           
 void removeValue(ServletRequest servletRequest, ServletResponse response)
           
 void setMaxAge(int maxAge)
          Sets the Cookie's maxAge setting.
 void setPath(String path)
          Sets the Cookie's path setting.
 void setSecure(boolean secure)
           
 
Methods inherited from class org.jsecurity.web.attr.AbstractWebAttribute
fromStringValue, getEditorClass, getFromRequestParam, getName, isCheckRequestParams, isCheckRequestParamsFirst, isMutable, retrieveValue, setCheckRequestParams, setCheckRequestParamsFirst, setEditorClass, setMutable, setName, storeValue, toStringValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_YEAR

public static final int ONE_YEAR
The number of seconds in one year (= 60 * 60 * 24 * 365).

See Also:
Constant Field Values

INDEFINITE

public static final int INDEFINITE
This is the same value as Integer.MAX_VALUE, and while Tomcat does fine with cookie max age with this value, Jetty apparently has problems with it. If you're using Jetty, you might want to use the ONE_YEAR constant or another value.

See Also:
Constant Field Values

DEFAULT_PATH

public static final String DEFAULT_PATH
null, indicating the cookie should be set on the request context root.


DEFAULT_MAX_AGE

public static final int DEFAULT_MAX_AGE
-1, indicating the cookie should expire when the browser closes.

See Also:
Constant Field Values

DEFAULT_SECURE

public static final boolean DEFAULT_SECURE
Default value is false.

See Also:
Constant Field Values
Constructor Detail

CookieAttribute

public CookieAttribute()

CookieAttribute

public CookieAttribute(String name)
Constructs a CookieAttribute using a Cookie with the specified name using the request context's path and with a maxAge of -1, indicating the Cookie will persist until browser shutdown.

Parameters:
name - the Cookie name

CookieAttribute

public CookieAttribute(String name,
                       String path)
Constructs a CookieAttribute using a Cookie with the specified name and path.

A null path value means the request context's path will be used by default.

The Cookie's maxAge will be -1, indicating the Cookie will persist until browser shutdown.

Parameters:
name - the Cookie name
path - the Cookie path.

CookieAttribute

public CookieAttribute(String name,
                       int maxAge)
Constructs a CookieAttribute using a Cookie with the specified name and maxAge.

The Cookie's path will be the Request's context path.

Parameters:
name - the Cookie name;
maxAge - the Cookie maxAge

CookieAttribute

public CookieAttribute(String name,
                       String path,
                       int maxAge)
Constructs a CookieAttribute using a Cookie with the specified name, path, and maxAge.

Parameters:
name - the Cookie name
path - the Cookie path.
maxAge - the Cookie maxAge

CookieAttribute

public CookieAttribute(String name,
                       String path,
                       int maxAge,
                       Class<? extends PropertyEditor> editorClass)
Constructs a CookieAttribute using a Cookie with the specified name, path, and maxAge, utilizing the specified PropertyEditor to perform value/string conversion on the object stored as a cookie.

Parameters:
name - the Cookie name
path - the Cookie path.
maxAge - the Cookie maxAge
editorClass - the PropertyEditor to perform value/string conversion on the object stored as a Cookie.
Method Detail

getPath

public String getPath()
Returns the Cookie's path setting. If null, the request's context path will be used.

The default is null.

Returns:
the Cookie's path, or null if the request's context path should be used as the path when the cookie is created.

setPath

public void setPath(String path)
Sets the Cookie's path setting. If the argument is null, the request's context path will be used.

The default is null.

Parameters:
path - the Cookie's path, or null if the request's context path should be used as the path when the cookie is created.

getMaxAge

public int getMaxAge()
Returns the Cookie's maxAge setting. Please see that JavaDoc for the semantics on the repercussions of negative, zero, and positive values for the maxAge.

The default value is -1, meaning the cookie will expire when the browser is closed.

Returns:
the Cookie's maxAge

setMaxAge

public void setMaxAge(int maxAge)
Sets the Cookie's maxAge setting. Please see that JavaDoc for the semantics on the repercussions of negative, zero, and positive values for the maxAge.

The default value is -1, meaning the cookie will expire when the browser is closed.

Parameters:
maxAge - the Cookie's maxAge

isSecure

public boolean isSecure()

setSecure

public void setSecure(boolean secure)

onRetrieveValue

public T onRetrieveValue(ServletRequest request,
                         ServletResponse response)
Specified by:
onRetrieveValue in class AbstractWebAttribute<T>

onStoreValue

public void onStoreValue(T value,
                         ServletRequest servletRequest,
                         ServletResponse servletResponse)
Specified by:
onStoreValue in class AbstractWebAttribute<T>

removeValue

public void removeValue(ServletRequest servletRequest,
                        ServletResponse response)

JSecurity

Copyright © 2004-2008 JSecurity.