APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.security.auth.module

public Class KeyStoreLoginModule

extends Object
implements LoginModule
Class Inheritance
All Implemented Interfaces
javax.security.auth.spi.LoginModule
Imports
java.io.File, .IOException, .InputStream, java.net.MalformedURLException, .URL, java.security.*, java.security.cert.*, .Certificate, .X509Certificate, java.util.*, javax.security.auth.Destroyable, .DestroyFailedException, .Subject, javax.security.auth.x500.*, javax.security.auth.callback.Callback, .CallbackHandler, .ConfirmationCallback, .NameCallback, .PasswordCallback, .TextOutputCallback, .UnsupportedCallbackException, javax.security.auth.login.FailedLoginException, .LoginException, javax.security.auth.spi.LoginModule, sun.security.util.Password

Provides a JAAS login module that prompts for a key store alias and populates the subject with the alias's principal and credentials. Stores an X500Principal for the subject distinguished name of the first certificate in the alias's credentials in the subject's principals, the alias's certificate path in the subject's public credentials, and a X500PrivateCredential whose certificate is the first certificate in the alias's certificate path and whose private key is the alias's private key in the subject's private credentials.

Recognizes the following options in the configuration file:

keyStoreURL
A URL that specifies the location of the key store. Defaults to a URL pointing to the .keystore file in the directory specified by the user.home system property. The input stream from this URL is passed to the KeyStore.load method. "NONE" may be specified if a null stream must be passed to the KeyStore.load method. "NONE" should be specified if the KeyStore resides on a hardware token device, for example.
keyStoreType
The key store type. If not specified, defaults to the result of calling KeyStore.getDefaultType(). If the type is "PKCS11", then keyStoreURL must be "NONE" and privateKeyPasswordURL must not be specified.
keyStoreProvider
The key store provider. If not specified, uses the standard search order to find the provider.
keyStoreAlias
The alias in the key store to login as. Required when no callback handler is provided. No default value.
keyStorePasswordURL
A URL that specifies the location of the key store password. Required when no callback handler is provided and protected is false. No default value.
privateKeyPasswordURL
A URL that specifies the location of the specific private key password needed to access the private key for this alias. The keystore password is used if this value is needed and not specified.
protected
This value should be set to "true" if the KeyStore has a separate, protected authentication path (for example, a dedicated PIN-pad attached to a smart card). Defaults to "false". If "true" keyStorePasswordURL and privateKeyPasswordURL must not be specified.
Since
1.4

Field Summary

Modifier and TypeField and Description
private static final int
private static final TextOutputCallback
private CallbackHandler
private CertPath
private final ConfirmationCallback
private boolean
private Certificate[]
private static final int
private KeyStore
private String
private char[]
private String
private String
private String
private String
private static final int
private static final String
private static final int
private boolean
private Map<String, ?>
private static final String
private X500Principal
private X500PrivateCredential
private char[]
private String
private static final int
private boolean
private Map<String, Object>
private int
private Subject
private static final int
private boolean
private static final int

Constructor Summary

AccessConstructor and Description
public
KeyStoreLoginModule()

Creates a KeyStoreLoginModule.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

false if this LoginModule's own login and/or commit attempts failed, and true otherwise.
abort
()

Implements javax.security.auth.spi.LoginModule.abort.

This method is called if the LoginContext's overall authentication failed.

private void
private void
private void
public boolean

Returns:

true if this LoginModule's own login and commit attempts succeeded, or false otherwise.
commit
()

Implements javax.security.auth.spi.LoginModule.commit.

Abstract method to commit the authentication process (phase 2).

private boolean
private void
debugPrint(String message)

private void
getAliasAndPasswords(int env)

Get the alias and passwords to use for looking up in the KeyStore.

private void
getKeyStoreInfo()

Get the credentials from the KeyStore.

public void
initialize(Subject
the Subject to be authenticated.
subject
,
CallbackHandler
a CallbackHandler for communicating with the end user (prompting for usernames and passwords, for example), which may be null.
callbackHandler
,
Map<String, ?>
shared LoginModule state.
sharedState
,
Map<String, ?>
options specified in the login Configuration for this particular LoginModule.
options
)

Implements javax.security.auth.spi.LoginModule.initialize.

Initialize this LoginModule.

public boolean

Returns:

true in all cases (this LoginModule should not be ignored).
login
()

Implements javax.security.auth.spi.LoginModule.login.

Authenticate the user.

public boolean

Returns:

true in all cases since this LoginModule should not be ignored.
logout
()

Implements javax.security.auth.spi.LoginModule.logout.

Logout a user.

private void
private static URL
newURL(String spec)

private void
private void
prompt(NameCallback aliasCallback, PasswordCallback storePassCallback, PasswordCallback keyPassCallback)

private void
private void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTHENTICATEDback to summary
private static final int AUTHENTICATED
bannerCallbackback to summary
private static final TextOutputCallback bannerCallback
callbackHandlerback to summary
private CallbackHandler callbackHandler
certPback to summary
private CertPath certP
confirmationCallbackback to summary
private final ConfirmationCallback confirmationCallback
debugback to summary
private boolean debug
fromKeyStoreback to summary
private Certificate[] fromKeyStore
INITIALIZEDback to summary
private static final int INITIALIZED
keyStoreback to summary
private KeyStore keyStore
keyStoreAliasback to summary
private String keyStoreAlias
keyStorePasswordback to summary
private char[] keyStorePassword
keyStorePasswordURLback to summary
private String keyStorePasswordURL
keyStoreProviderback to summary
private String keyStoreProvider
keyStoreTypeback to summary
private String keyStoreType
keyStoreURLback to summary
private String keyStoreURL
LOGGED_INback to summary
private static final int LOGGED_IN
NONEback to summary
private static final String NONE
NORMALback to summary
private static final int NORMAL
nullStreamback to summary
private boolean nullStream
optionsback to summary
private Map<String, ?> options
P11KEYSTOREback to summary
private static final String P11KEYSTORE
principalback to summary
private X500Principal principal
privateCredentialback to summary
private X500PrivateCredential privateCredential
privateKeyPasswordback to summary
private char[] privateKeyPassword
privateKeyPasswordURLback to summary
private String privateKeyPasswordURL
PROTECTED_PATHback to summary
private static final int PROTECTED_PATH
protectedPathback to summary
private boolean protectedPath
sharedStateback to summary
private Map<String, Object> sharedState
statusback to summary
private int status
subjectback to summary
private Subject subject
TOKENback to summary
private static final int TOKEN
tokenback to summary
private boolean token
UNINITIALIZEDback to summary
private static final int UNINITIALIZED

Constructor Detail

KeyStoreLoginModuleback to summary
public KeyStoreLoginModule()

Creates a KeyStoreLoginModule.

Method Detail

abortback to summary
public boolean abort() throws LoginException

Implements javax.security.auth.spi.LoginModule.abort.

This method is called if the LoginContext's overall authentication failed. (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules did not succeed).

If this LoginModule's own authentication attempt succeeded (checked by retrieving the private state saved by the login and commit methods), then this method cleans up any state that was originally saved.

If the loaded KeyStore's provider extends java.security.AuthProvider, then the provider's logout method is invoked.

Returns:boolean

false if this LoginModule's own login and/or commit attempts failed, and true otherwise.

Exceptions
LoginException:
if the abort fails.
checkAliasback to summary
private void checkAlias() throws LoginException
checkKeyPassback to summary
private void checkKeyPass() throws LoginException
checkStorePassback to summary
private void checkStorePass() throws LoginException
commitback to summary
public boolean commit() throws LoginException

Implements javax.security.auth.spi.LoginModule.commit.

Abstract method to commit the authentication process (phase 2).

This method is called if the LoginContext's overall authentication succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules succeeded).

If this LoginModule's own authentication attempt succeeded (checked by retrieving the private state saved by the login method), then this method associates a X500Principal for the subject distinguished name of the first certificate in the alias's credentials in the subject's principals, the alias's certificate path in the subject's public credentials, and a X500PrivateCredential whose certificate is the first certificate in the alias's certificate path and whose private key is the alias's private key in the subject's private credentials. If this LoginModule's own authentication attempted failed, then this method removes any state that was originally saved.

Returns:boolean

true if this LoginModule's own login and commit attempts succeeded, or false otherwise.

Exceptions
LoginException:
if the commit fails
commitInternalback to summary
private boolean commitInternal() throws LoginException
debugPrintback to summary
private void debugPrint(String message)
getAliasAndPasswordsback to summary
private void getAliasAndPasswords(int env) throws LoginException

Get the alias and passwords to use for looking up in the KeyStore.

Annotations
@SuppressWarnings:fallthrough
getKeyStoreInfoback to summary
private void getKeyStoreInfo() throws LoginException

Get the credentials from the KeyStore.

initializeback to summary
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options)

Implements javax.security.auth.spi.LoginModule.initialize.

Initialize this LoginModule.

Parameters
subject:Subject

the Subject to be authenticated.

callbackHandler:CallbackHandler

a CallbackHandler for communicating with the end user (prompting for usernames and passwords, for example), which may be null.

sharedState:Map<String, ?>

shared LoginModule state.

options:Map<String, ?>

options specified in the login Configuration for this particular LoginModule.

Annotations
@SuppressWarnings:unchecked
loginback to summary
public boolean login() throws LoginException

Implements javax.security.auth.spi.LoginModule.login.

Authenticate the user.

Get the Keystore alias and relevant passwords. Retrieve the alias's principal and credentials from the Keystore.

Returns:boolean

true in all cases (this LoginModule should not be ignored).

Exceptions
LoginException:

Doc from javax.security.auth.spi.LoginModule.login.

if the authentication fails

FailedLoginException:
if the authentication fails.
logoutback to summary
public boolean logout() throws LoginException

Implements javax.security.auth.spi.LoginModule.logout.

Logout a user.

This method removes the Principals, public credentials and the private credentials that were added by the commit method.

If the loaded KeyStore's provider extends java.security.AuthProvider, then the provider's logout method is invoked.

Returns:boolean

true in all cases since this LoginModule should not be ignored.

Exceptions
LoginException:
if the logout fails.
logoutInternalback to summary
private void logoutInternal() throws LoginException
newURLback to summary
private static URL newURL(String spec) throws MalformedURLException
Annotations
@SuppressWarnings:deprecation
processOptionsback to summary
private void processOptions()
promptback to summary
private void prompt(NameCallback aliasCallback, PasswordCallback storePassCallback, PasswordCallback keyPassCallback) throws LoginException
saveAliasback to summary
private void saveAlias(NameCallback cb)
saveKeyPassback to summary
private void saveKeyPass(PasswordCallback c)
saveStorePassback to summary
private void saveStorePass(PasswordCallback c)