public class JAASRealm extends RealmBase
Implementation of Realm that authenticates users via the Java
Authentication and Authorization Service (JAAS). JAAS support requires
either JDK 1.4 (which includes it as part of the standard platform) or
JDK 1.3 (with the plug-in jaas.jar file).
The value configured for the appName property is passed to
the javax.security.auth.login.LoginContext constructor, to
specify the application name used to select the set of relevant
LoginModules required.
The JAAS Specification describes the result of a successful login as a
javax.security.auth.Subject instance, which can contain zero
or more java.security.Principal objects in the return value
of the Subject.getPrincipals() method. However, it provides
no guidance on how to distinguish Principals that describe the individual
user (and are thus appropriate to return as the value of
request.getUserPrincipal() in a web application) from the Principal(s)
that describe the authorized roles for this user. To maintain as much
independence as possible from the underlying LoginMethod
implementation executed by JAAS, the following policy is implemented by
this Realm:
LoginModule is assumed to return a
Subject with at least one Principal instance
representing the user himself or herself, and zero or more separate
Principals representing the security roles authorized
for this user.Principal representing the user, the Principal
name is an appropriate value to return via the Servlet API method
HttpServletRequest.getRemoteUser().Principals representing the security roles, the
name is the name of the authorized security role.java.security.Principal - one that identifies class(es)
representing a user, and one that identifies class(es) representing
a security role.Principals returned by
Subject.getPrincipals(), it will identify the first
Principal that matches the "user classes" list as the
Principal for this user.Principals returned by
Subject.getPrincipals(), it will accumulate the set of
all Principals matching the "role classes" list as
identifying the security roles for this user.Subject without a Principal that
matches the "user classes" list.| Modifier and Type | Field and Description |
|---|---|
protected String |
appName
The application name passed to the JAAS
LoginContext,
which uses it to select the set of relevant LoginModules. |
protected static String |
info
Descriptive information about this Realm implementation.
|
protected static String |
name
Descriptive information about this Realm implementation.
|
protected ArrayList<String> |
roleClasses
The list of role class names, split out for easy processing.
|
protected String |
roleClassNames
Comma-delimited list of
javax.security.Principal classes
that represent security roles. |
protected ArrayList<String> |
userClasses
The set of user class names, split out for easy processing.
|
protected String |
userClassNames
Comma-delimited list of
javax.security.Principal classes
that represent individual users. |
checkIfRequestIsSecure, container, controller, debug, digest, digestEncoding, lifecycle, log, md, md5Encoder, md5Helper, rb, started, support, validateAFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENTAUTHENTICATE_NEEDED, AUTHENTICATE_NOT_NEEDED, AUTHENTICATED_NOT_AUTHORIZED| Constructor and Description |
|---|
JAASRealm() |
| Modifier and Type | Method and Description |
|---|---|
Principal |
authenticate(String username,
char[] credentials)
Return the Principal associated with the specified username and
credentials, if there is one; otherwise return
null. |
protected Principal |
createPrincipal(String username,
Subject subject)
Construct and return a
java.security.Principal instance
representing the authenticated user for the specified Subject. |
String |
getAppName()
getter for the appName member variable
|
protected String |
getName()
Return a short name for this Realm implementation.
|
protected char[] |
getPassword(String username)
Return the password associated with the given principal's user name.
|
protected Principal |
getPrincipal(String username)
Return the Principal associated with the given user name.
|
String |
getRoleClassNames() |
String |
getUserClassNames() |
void |
setAppName(String name)
Deprecated.
JAAS should use the Engine ( domain ) name and webpp/host overrides
|
void |
setContainer(Container container)
Set the Container with which this Realm has been associated.
|
void |
setRoleClassNames(String roleClassNames) |
void |
setUserClassNames(String userClassNames) |
void |
start()
Prepare for active use of the public methods of this Component.
|
void |
stop()
Gracefully shut down active use of the public methods of this Component.
|
addLifecycleListener, addPropertyChangeListener, authenticate, authenticate, authenticate, backgroundProcess, destroy, digest, disableProxyCaching, findLifecycleListeners, findSecurityConstraints, findSecurityConstraints, getAlternateAuthType, getAlternatePrincipal, getContainer, getController, getDebug, getDigest, getDigest, getDigestEncoding, getInfo, getRealmName, getValidate, hasMessageDigest, hasResourcePermission, hasRole, hasRole, hasUserDataPermission, hasUserDataPermission, invokeAuthenticateDelegate, invokePostAuthenticateDelegate, isSecurityExtensionEnabled, log, log, logout, preAuthenticateCheck, removeLifecycleListener, removePropertyChangeListener, setController, setDebug, setDigest, setDigestEncoding, setRealmName, setValidateprotected String appName
LoginContext,
which uses it to select the set of relevant LoginModules.protected static final String info
protected static final String name
protected ArrayList<String> roleClasses
protected ArrayList<String> userClasses
protected String roleClassNames
javax.security.Principal classes
that represent security roles.protected String userClassNames
javax.security.Principal classes
that represent individual users.public void setAppName(String name)
public String getAppName()
public void setContainer(Container container)
RealmBasesetContainer in interface RealmsetContainer in class RealmBasecontainer - The associated Containerpublic String getRoleClassNames()
public void setRoleClassNames(String roleClassNames)
public String getUserClassNames()
public void setUserClassNames(String userClassNames)
public Principal authenticate(String username, char[] credentials)
null.
If there are any errors with the JDBC connection, executing
the query or anything we return null (don't authenticate). This
event is also logged, and the connection will be closed so that
a subsequent request will automatically re-open it.authenticate in interface Realmauthenticate in class RealmBaseusername - Username of the Principal to look upcredentials - Password or other credentials to use in
authenticating this usernameprotected String getName()
protected char[] getPassword(String username)
getPassword in class RealmBaseprotected Principal getPrincipal(String username)
getPrincipal in class RealmBaseprotected Principal createPrincipal(String username, Subject subject)
java.security.Principal instance
representing the authenticated user for the specified Subject. If no
such Principal can be constructed, return null.subject - The Subject representing the logged in userpublic void start()
throws LifecycleException
start in interface Lifecyclestart in class RealmBaseLifecycleException - if this component detects a fatal error
that prevents it from being startedpublic void stop()
throws LifecycleException
stop in interface Lifecyclestop in class RealmBaseLifecycleException - if this component detects a fatal error
that needs to be reportedCopyright © 2019. All rights reserved.