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); ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access