Package com.sun.enterprise.security
Class SecurityContext
- java.lang.Object
-
- com.sun.enterprise.security.common.AbstractSecurityContext
-
- com.sun.enterprise.security.SecurityContext
-
- All Implemented Interfaces:
AppServSecurityContext,Serializable
@Service @PerLookup public class SecurityContext extends AbstractSecurityContext
This class that extends AbstractSecurityContext that gets stored in Thread Local Storage. If the current thread creates child threads, the SecurityContext stored in the current thread is automatically propagated to the child threads. This class is used on the server side to represent the security context.- Author:
- Harish Prabandham, Harpreet Singh
- See Also:
ThreadLocal,InheritableThreadLocal, Serialized Form
-
-
Field Summary
-
Fields inherited from class com.sun.enterprise.security.common.AbstractSecurityContext
additionalPrincipal, callerPrincipal, subject
-
-
Constructor Summary
Constructors Constructor Description SecurityContext()SecurityContext(String username, Subject subject)SecurityContext(String username, Subject subject, String realm)SecurityContext(Subject subject)Create a SecurityContext with the given subject having a DistinguishedPrincipalCredential.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandidServerGenerateCredentials()PrincipalgetCallerPrincipal()This method returns the caller principal.static SecurityContextgetCurrent()This method gets the SecurityContext stored in the Thread Local Store (TLS) of the current thread.AppServSecurityContextgetCurrentSecurityContext()static PrincipalgetDefaultCallerPrincipal()static SecurityContextgetDefaultSecurityContext()static SubjectgetDefaultSubject()Set<Principal>getPrincipalSet()SubjectgetSubject()This method should be implemented by the subclasses to return the Credentials of the caller principal.static SecurityContextinit()Initialize the SecurityContext and handle the unauthenticated principal caseAppServSecurityContextnewInstance(String username, Subject subject)AppServSecurityContextnewInstance(String username, Subject subject, String realm)voidpostConstruct()static voidreset(SecurityContext securityContext)No need to unmarshall the unauthenticated principal....static voidsetCurrent(SecurityContext securityContext)This method sets the SecurityContext stored in the TLS.voidsetCurrentSecurityContext(AppServSecurityContext context)set the current security contextvoidsetSecurityContextWithPrincipal(Principal principal)set the SecurityContext with given Principalstatic voidsetUnauthenticatedContext()voidsetUnauthenticatedSecurityContext()set the unauthenticated contextStringtoString()-
Methods inherited from class com.sun.enterprise.security.common.AbstractSecurityContext
getAdditionalPrincipal, setAdditionalPrincipal
-
-
-
-
Constructor Detail
-
SecurityContext
public SecurityContext(Subject subject)
Create a SecurityContext with the given subject having a DistinguishedPrincipalCredential.This is used for a JASPIC environment.
- Parameters:
subject-
-
SecurityContext
public SecurityContext()
-
-
Method Detail
-
init
public static SecurityContext init()
Initialize the SecurityContext and handle the unauthenticated principal case
-
getDefaultSecurityContext
public static SecurityContext getDefaultSecurityContext()
-
getDefaultSubject
public static Subject getDefaultSubject()
-
getDefaultCallerPrincipal
public static Principal getDefaultCallerPrincipal()
-
reset
public static void reset(SecurityContext securityContext)
No need to unmarshall the unauthenticated principal....
-
getCurrent
public static SecurityContext getCurrent()
This method gets the SecurityContext stored in the Thread Local Store (TLS) of the current thread.- Returns:
- The current Security Context stored in TLS. It returns null if SecurityContext could not be found in the current thread.
-
setCurrent
public static void setCurrent(SecurityContext securityContext)
This method sets the SecurityContext stored in the TLS.- Parameters:
securityContext- The Security Context that should be stored in TLS. This public static method needs to be protected such that it can only be called by container code. Otherwise it can be called by application code to set its subject (which the EJB security manager will use to create a domain combiner, and then everything the ejb does will be run as the corresponding subject.
-
setUnauthenticatedContext
public static void setUnauthenticatedContext()
-
didServerGenerateCredentials
public boolean didServerGenerateCredentials()
-
getCallerPrincipal
public Principal getCallerPrincipal()
This method returns the caller principal. This information may be redundant since the same information can be inferred by inspecting the Credentials of the caller.- Specified by:
getCallerPrincipalin interfaceAppServSecurityContext- Specified by:
getCallerPrincipalin classAbstractSecurityContext- Returns:
- The caller Principal.
-
getSubject
public Subject getSubject()
Description copied from class:AbstractSecurityContextThis method should be implemented by the subclasses to return the Credentials of the caller principal.- Specified by:
getSubjectin interfaceAppServSecurityContext- Specified by:
getSubjectin classAbstractSecurityContext- Returns:
- A credentials object associated with the current client invocation.
-
postConstruct
public void postConstruct()
-
newInstance
public AppServSecurityContext newInstance(String username, Subject subject, String realm)
- Returns:
- a new instance
-
newInstance
public AppServSecurityContext newInstance(String username, Subject subject)
- Returns:
- a new instance
-
setCurrentSecurityContext
public void setCurrentSecurityContext(AppServSecurityContext context)
Description copied from interface:AppServSecurityContextset the current security context
-
getCurrentSecurityContext
public AppServSecurityContext getCurrentSecurityContext()
- Returns:
- the current security context
-
setUnauthenticatedSecurityContext
public void setUnauthenticatedSecurityContext()
Description copied from interface:AppServSecurityContextset the unauthenticated context
-
setSecurityContextWithPrincipal
public void setSecurityContextWithPrincipal(Principal principal)
Description copied from interface:AppServSecurityContextset the SecurityContext with given Principal
-
-