org.acegisecurity.context
Class SecurityContextHolder

java.lang.Object
  extended by org.acegisecurity.context.SecurityContextHolder

public class SecurityContextHolder
extends Object

Associates a given SecurityContext with the current execution thread and any new threads the current execution thread may spawn.

To guarantee that getContext() never returns null, this class defaults to returning SecurityContextImpl if no SecurityContext has ever been associated with the current thread of execution. Despite this behaviour, in general another class will select the concrete SecurityContext implementation to use and expressly set an instance of that implementation against the SecurityContextHolder.

Version:
$Id: SecurityContextHolder.java,v 1.4 2005/11/17 00:55:49 benalex Exp $
Author:
Ben Alex
See Also:
ThreadLocal, HttpSessionContextIntegrationFilter

Constructor Summary
SecurityContextHolder()
           
 
Method Summary
static SecurityContext getContext()
          Obtains the SecurityContext associated with the current thread of execution.
static void setContext(SecurityContext context)
          Associates a new SecurityContext with the current thread of execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecurityContextHolder

public SecurityContextHolder()
Method Detail

setContext

public static void setContext(SecurityContext context)
Associates a new SecurityContext with the current thread of execution.

Parameters:
context - the new SecurityContext (may not be null)

getContext

public static SecurityContext getContext()
Obtains the SecurityContext associated with the current thread of execution. If no SecurityContext has been associated with the current thread of execution, a new instance of SecurityContextImpl is associated with the current thread and then returned.

Returns:
the current SecurityContext (guaranteed to never be null)


Copyright © 2004-2005 Acegi Technology Pty Limited. All Rights Reserved.