Name
Package javax.security.auth.login
Synopsis
This
package
defines the
LoginContext
class which is one of the primary JAAS
classes used by application programmers. To authenticate a user, an
application creates a LoginContext
object,
specifying the application name (used to lookup the type of
authentication required for that application in the
Configuration
) and usually specifying a
javax.security.auth.callback.CallbackHandler
for
communication between the user and the underlying login modules.
Next, the application calls the login(
)
method of the LoginContext
to perform the actual
login. If this method returns without throwing a
LoginException
, then the user was sucessfully
authenticated, and the getSubject(
)
method of
LoginContext
returns a
javax.security.auth.Subject
representing the user.
The code might look like this:
import javax.security.auth.*; import javax.security.auth.callback.*; import javax.security.auth.login.*; // Get a default GUI-based CallbackHandler CallbackHandler h = new com.sun.security.auth.callback.DialogCallbackHandler( ); // Try to create a LoginContext for use with this application LoginContext context; try { context = new LoginContext("MyAppName", h); } catch(LoginException e) { System.err.println("LoginContext configuration error: " + e.getMessage( )); System.exit(-1); } // Now use that context to authenticate the user try { context.login( ); } catch(LoginException e) { System.err.println("Authentication failed: " + e.getMessage( )); System.exit(-1); ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.