de.fhg.igd.atlas.core
Class CookieManager

java.lang.Object
  extended byde.fhg.igd.atlas.core.CookieManager

public class CookieManager
extends Object

Provides all methods needed for the Location Service Protocol (LSP) which deal with cookie generation and storage.

Version:
"$Id: CookieManager.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Jan Peters

Field Summary
protected  AgentContext agentContext_
          The reference to the agent context (needed to read, update and delete the current and temporary cookie of the agent).
static int COOKIE_LENGTH
          The length of a cookie in bytes.
static byte[] NULL_COOKIE
          The unique null cookie, which is used to distinguish between Init, Update and Delete register requests within the Location Service Protocol.
static String PATH_TO_CURRENT_COOKIE
          The path and filename within the agent resource to store the current cookie.
static String PATH_TO_TMP_COOKIE
          The path and filename within the agent resource to store the temporary cookie, which is needed for the backup protocol.
static String SR_ALG
          The algorithm used to calculate secure randoms for cookie generation.
 
Constructor Summary
CookieManager(AgentContext agentContext)
          Creates an new instance of this class.
 
Method Summary
 boolean existsCurrentCookie()
          Checks if a current cookie is existent.
 boolean existsTmpCookie()
          Checks if a temporary cookie is existent.
static byte[] generateCookie()
          Generates a new cookie of length COOKIE_LENGTH.
protected  byte[] readCookieFromResource(Resource agentResource, String path)
          Reads a cookie from the given path within the agent resource.
 byte[] readCurrentCookie()
          Reads the current cookie from the agent resource.
 byte[] readTmpCookie()
          Reads the temporary cookie from the agent resource.
 void removeCurrentCookie()
          Removes the current cookie of the agent within the agent resource and the agent context.
 void removeTmpCookie()
          Removes the temporary cookie of the agent within the agent resource and the agent context.
protected  void writeCookieToResource(Resource agentResource, byte[] cookie, String path)
          Writes the given cookie to the given path within the agent resource.
 void writeCurrentCookie(byte[] cookie)
          Writes the given cookie as current cookie to the agent resource and to the agent context.
 void writeTmpCookie(byte[] cookie)
          Writes the given cookie as temporary cookie to the agent resource and to the agent context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SR_ALG

public static final String SR_ALG
The algorithm used to calculate secure randoms for cookie generation.

See Also:
Constant Field Values

PATH_TO_CURRENT_COOKIE

public static String PATH_TO_CURRENT_COOKIE
The path and filename within the agent resource to store the current cookie.


PATH_TO_TMP_COOKIE

public static String PATH_TO_TMP_COOKIE
The path and filename within the agent resource to store the temporary cookie, which is needed for the backup protocol.


NULL_COOKIE

public static final byte[] NULL_COOKIE
The unique null cookie, which is used to distinguish between Init, Update and Delete register requests within the Location Service Protocol.


COOKIE_LENGTH

public static final int COOKIE_LENGTH
The length of a cookie in bytes.

See Also:
Constant Field Values

agentContext_

protected AgentContext agentContext_
The reference to the agent context (needed to read, update and delete the current and temporary cookie of the agent).

Constructor Detail

CookieManager

public CookieManager(AgentContext agentContext)
Creates an new instance of this class. The given agentContext is used to obtain the current or temporary cookie directly or from the resource of the agent. If the agent resource is existent it obtains priority concerning the state of the cookies. Only in the case when the agent resource is not valid any more, those cookies are used, which are stored directly within the agents context. This happens, if the agent has migrated and the agent context is still available (when the agent state changes from migrated to invalid)

Parameters:
agentContext - The context of an agent.
Method Detail

generateCookie

public static byte[] generateCookie()
                             throws NoSuchAlgorithmException
Generates a new cookie of length COOKIE_LENGTH.

Returns:
The generated cookie.
Throws:
NoSuchAlgorithmException - if the generation of secure randoms is not supported.

removeCurrentCookie

public void removeCurrentCookie()
                         throws IOException
Removes the current cookie of the agent within the agent resource and the agent context.

Throws:
IOException - if an error occures during access to the agents resource.

removeTmpCookie

public void removeTmpCookie()
                     throws IOException
Removes the temporary cookie of the agent within the agent resource and the agent context.

Throws:
IOException - if an error occures during access to the agents resource.

existsCurrentCookie

public boolean existsCurrentCookie()
Checks if a current cookie is existent. If the agent resource is not valid any more, this method checks whether the current cookie is existent within agent context.

Returns:
true if the current cookie is existent; false otherwise.

existsTmpCookie

public boolean existsTmpCookie()
Checks if a temporary cookie is existent. If the agent resource is not valid any more, this method checks whether the temporary cookie is existent within agent context.

Returns:
true if the temporary cookie is existent; false otherwise.

readCurrentCookie

public byte[] readCurrentCookie()
                         throws IOException
Reads the current cookie from the agent resource. If the agent resource is not valid any more, this method tries to read the current cookie from the agent context.

Returns:
The current cookie of the agent if existent; the NULL_COOKIE otherwise
Throws:
IOException - if an error occures during access to the agents resource.

readTmpCookie

public byte[] readTmpCookie()
                     throws IOException
Reads the temporary cookie from the agent resource. If the agent resource is not valid any more, this method tries to read the temporary cookie from the agent context.

Returns:
The temporary cookie of the agent if existent; the NULL_COOKIE otherwise.
Throws:
IOException - if an error occures during access to the agents resource.

readCookieFromResource

protected byte[] readCookieFromResource(Resource agentResource,
                                        String path)
                                 throws IOException
Reads a cookie from the given path within the agent resource.

Parameters:
path - The path within the agent resource.
Returns:
The cookie, if existent; the NULL_COOKIE otherwise.
Throws:
IOException - if an error occures during access to the agents resource.

writeCurrentCookie

public void writeCurrentCookie(byte[] cookie)
                        throws IOException
Writes the given cookie as current cookie to the agent resource and to the agent context.

Returns:
The cookie.
Throws:
IOException - if an error occures during access to the agents resource.

writeTmpCookie

public void writeTmpCookie(byte[] cookie)
                    throws IOException
Writes the given cookie as temporary cookie to the agent resource and to the agent context.

Returns:
The cookie.
Throws:
IOException - if an error occures during access to the agents resource.

writeCookieToResource

protected void writeCookieToResource(Resource agentResource,
                                     byte[] cookie,
                                     String path)
                              throws IOException
Writes the given cookie to the given path within the agent resource.

Parameters:
path - The path within the agent resource.
Returns:
The cookie.
Throws:
IOException - if an error occures during access to the agents resource.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.