@NotThreadSafe public class JaasSecurityContext extends Object implements SecurityContext
security context
that provides authentication and authorization through the JAAS
login context
.Modifier and Type | Class and Description |
---|---|
static class |
JaasSecurityContext.UserPasswordCallbackHandler
A simple
callback handler implementation that attempts to provide a user ID and password to any
callbacks that it handles. |
Constructor and Description |
---|
JaasSecurityContext(LoginContext loginContext)
Creates a new JAAS security context based on the given login context.
|
JaasSecurityContext(String realmName)
Create a
JaasSecurityContext with the supplied application
configuration name . |
JaasSecurityContext(String realmName,
CallbackHandler callbackHandler)
Create a
JaasSecurityContext with the supplied application
configuration name and the given callback handler. |
JaasSecurityContext(String realmName,
String userId,
char[] password)
Create a
JaasSecurityContext with the supplied application
configuration name and a JAAS callback handler to create a new JAAS
login context with the given user ID and password. |
JaasSecurityContext(String realmName,
Subject subject)
|
JaasSecurityContext(Subject subject)
Creates a new JAAS security context based on the user name and roles from the given subject.
|
Modifier and Type | Method and Description |
---|---|
String |
getUserName()
Returns the authenticated user's name
|
boolean |
hasRole(String roleName)
Returns whether the authenticated user has the given role.
|
boolean |
isAnonymous()
Return whether this security context is an anonymous context.
|
void |
logout()
Logs the user out of the authentication mechanism.
|
public JaasSecurityContext(String realmName) throws LoginException
JaasSecurityContext
with the supplied application
configuration name
.realmName
- the name of the JAAS application configuration name
; may not be nullIllegalArgumentException
- if the name
is nullLoginException
- if there name
is invalid (or there is no login context named "other"), or if the
default callback handler JAAS property was not set or could not be loadedpublic JaasSecurityContext(String realmName, Subject subject) throws LoginException
realmName
- the name of the JAAS application configuration name
subject
- the subject to authenticateLoginException
- if there name
is invalid (or there is no login context named "other"), if the default
callback handler JAAS property was not set or could not be loaded, or if the subject
is null or
unknownpublic JaasSecurityContext(String realmName, String userId, char[] password) throws LoginException
JaasSecurityContext
with the supplied application
configuration name
and a JAAS callback handler
to create a new JAAS
login context
with the given user ID and password.realmName
- the name of the JAAS application configuration name
userId
- the user ID to use for authenticationpassword
- the password to use for authenticationLoginException
- if there name
is invalid (or there is no login context named "other"), or if the
callbackHandler
is nullpublic JaasSecurityContext(String realmName, CallbackHandler callbackHandler) throws LoginException
JaasSecurityContext
with the supplied application
configuration name
and the given callback handler.realmName
- the name of the JAAS application configuration name
; may not be nullcallbackHandler
- the callback handler to use during the login process; may not be nullLoginException
- if there name
is invalid (or there is no login context named "other"), or if the
callbackHandler
is nullpublic JaasSecurityContext(LoginContext loginContext) throws LoginException
login
has not already
been invoked on the login context, this constructor will attempt to invoke it.loginContext
- the login context to use; may not be nullLoginException
- if the context has not already had its login method
invoked and an
error occurs attempting to invoke the login method.LoginContext
public JaasSecurityContext(Subject subject)
subject
- the subject to use as the provider of the user name and roles for this security context; may not be nullpublic boolean isAnonymous()
SecurityContext
isAnonymous
in interface SecurityContext
public String getUserName()
SecurityContext
getUserName
in interface SecurityContext
public boolean hasRole(String roleName)
SecurityContext
hasRole
in interface SecurityContext
roleName
- the name of the role to check. The name of the role will always come from ModeShape and will be one of
ModeShape's built-in roles.ModeShapeRoles
public void logout()
SecurityContext
For some authentication mechanisms, this will be implemented as a no-op.
logout
in interface SecurityContext
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.