Recent articles:
Popular archives:
Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can,
or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing
heavily in Java's future as a platform for platforms
Also see:
Discuss: Tim Bray on 'What Sun Should Do'
Page 3 of 6
With any of these approaches, note that you can change some of the JAAS-related system property settings (as well as many
other Java security settings) in the Java security properties file. This file, java.security, is located in the <jre-home>/lib/security directory and written in the standard Java properties file format.
Using JAAS authentication from your application typically involves the following steps:
LoginContextCallbackHandler to the LoginContext, for gathering or processing authentication data
LoginContext's login() method
Subject (assuming login succeeds)
Here's a minimal example:
LoginContext lc = new LoginContext("MyExample");
try {
lc.login();
} catch (LoginException) {
// Authentication failed.
}
// Authentication successful, we can now continue.
// We can use the returned Subject if we like.
Subject sub = lc.getSubject();
Subject.doAs(sub, new MyPrivilegedAction());
Underneath the covers, a few other things occur:
LoginContext finds the configuration entry "MyExample" in a JAAS configuration file (which you configured) to determine which LoginModules to load (see Figure 2)
LoginContext calls each LoginModule's login() method
login() method performs the authentication or enlists a CallbackHandlerCallbackHandler uses one or more Callbacks to interact with the user and gather input
Subject instance is populated with authentication details such as Principals and credentials
We'll explain further details below, but to begin, let's look at the key JAAS classes and interfaces involved in the process. These are typically divided into the following three groups:
| Common | Subject, Principal, credential (credential is not any specific class, but can be any object)
|
| Authentication | LoginContext, LoginModule, CallbackHandler, Callback
|
| Authorization | Policy, AuthPermission, PrivateCredentialPermission
|
Most of these classes and interfaces are in the javax.security.auth package's subpackages, with some prebuilt implementations in the com.sun.security.auth package, included only in J2SE 1.4.
Note: Because we focus on authentication in this article, we don't delve into the authorization classes.
The Subject class represents an authenticated entity: an end-user or administrator, or a Web service, device, or another process. The
class contains three sets of security information types:
Principals
Principals represent Subject identities. They implement the java.security.Principal interface (which predates JAAS) and java.io.Serializable. A Subject's most important method is getName(), which returns an identity's string name. Since a Subject instance contains an array of Principals, it can thus have multiple names. Because a social security number, login ID, email address, and so on, can all represent
one user, multiple identities prove common in the real world.