APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jmx.remote.security

public Class FileLoginModule

extends Object
implements LoginModule
Class Inheritance
All Implemented Interfaces
javax.security.auth.spi.LoginModule
Imports
com.sun.jmx.mbeanserver.Util, java.io.File, .IOException, java.util.Arrays, .Map, javax.security.auth.*, javax.security.auth.callback.*, javax.security.auth.login.*, javax.security.auth.spi.*, javax.management.remote.JMXPrincipal, com.sun.jmx.remote.util.ClassLogger, .EnvHelp

This LoginModule performs file-based authentication.

A supplied username and password is verified against the corresponding user credentials stored in a designated password file. If successful then a new JMXPrincipal is created with the user's name and it is associated with the current Subject. Such principals may be identified and granted management privileges in the access control file for JMX remote management or in a Java security policy. By default, the following password file is used:

    ${java.home}/conf/management/jmxremote.password
A different password file can be specified via the passwordFile configuration option.

This module recognizes the following Configuration options:

passwordFile
the path to an alternative password file. It is used instead of the default password file.
useFirstPass
if true, this module retrieves the username and password from the module's shared state, using "javax.security.auth.login.name" and "javax.security.auth.login.password" as the respective keys. The retrieved values are used for authentication. If authentication fails, no attempt for a retry is made, and the failure is reported back to the calling application.
tryFirstPass
if true, this module retrieves the username and password from the module's shared state, using "javax.security.auth.login.name" and "javax.security.auth.login.password" as the respective keys. The retrieved values are used for authentication. If authentication fails, the module uses the CallbackHandler to retrieve a new username and password, and another attempt to authenticate is made. If the authentication fails, the failure is reported back to the calling application.
storePass
if true, this module stores the username and password obtained from the CallbackHandler in the module's shared state, using "javax.security.auth.login.name" and "javax.security.auth.login.password" as the respective keys. This is not performed if existing values already exist for the username and password in the shared state, or if authentication fails.
clearPass
if true, this module clears the username and password stored in the module's shared state after both phases of authentication (login and commit) have completed.
hashPasswords
if true, this module replaces each clear text password with its hash, if present.

Field Summary

Modifier and TypeField and Description
private CallbackHandler
private boolean
private boolean
private static final String
private boolean
private HashedPasswordManager
private static final ClassLogger
private Map<String, ?>
private char[]
private static final String
private static final String
private String
private String
private Map<String, Object>
private boolean
private Subject
private boolean
private boolean
private boolean
private JMXPrincipal
private String
private static final String
private boolean

Constructor Summary

AccessConstructor and Description
public

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.

Abort user authentication (Authentication Phase 2).

private void
attemptAuthentication(boolean
a flag to tell this method whether to retrieve the password from the sharedState.
usePasswdFromSharedState
)

Attempt authentication

private void
cleanState()

Clean out state because of a failed authentication attempt

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.

Complete user authentication (Authentication Phase 2).

private void
getUsernamePassword(boolean
boolean that tells this method whether to retrieve the password from the sharedState.
usePasswdFromSharedState
)

Get the username and password.

public void
initialize(Subject
the Subject to be authenticated.
subject
,
CallbackHandler
a CallbackHandler to acquire the user's name and password.
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 always, since this LoginModule should not be ignored.
login
()

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

Begin user authentication (Authentication Phase 1).

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callbackHandlerback to summary
private CallbackHandler callbackHandler
clearPassback to summary
private boolean clearPass
commitSucceededback to summary
private boolean commitSucceeded
DEFAULT_PASSWORD_FILE_NAMEback to summary
private static final String DEFAULT_PASSWORD_FILE_NAME
hashPasswordsback to summary
private boolean hashPasswords
hashPwdMgrback to summary
private HashedPasswordManager hashPwdMgr
loggerback to summary
private static final ClassLogger logger
optionsback to summary
private Map<String, ?> options
passwordback to summary
private char[] password
PASSWORD_FILE_NAMEback to summary
private static final String PASSWORD_FILE_NAME
PASSWORD_KEYback to summary
private static final String PASSWORD_KEY
passwordFileback to summary
private String passwordFile
passwordFileDisplayNameback to summary
private String passwordFileDisplayName
sharedStateback to summary
private Map<String, Object> sharedState
storePassback to summary
private boolean storePass
subjectback to summary
private Subject subject
succeededback to summary
private boolean succeeded
tryFirstPassback to summary
private boolean tryFirstPass
useFirstPassback to summary
private boolean useFirstPass
userback to summary
private JMXPrincipal user
usernameback to summary
private String username
USERNAME_KEYback to summary
private static final String USERNAME_KEY
userSuppliedPasswordFileback to summary
private boolean userSuppliedPasswordFile

Constructor Detail

FileLoginModuleback to summary
public FileLoginModule()

Method Detail

abortback to summary
public boolean abort() throws LoginException

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

Abort user authentication (Authentication Phase 2).

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.

Returns:boolean

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

Exceptions
LoginException:
if the abort fails.
attemptAuthenticationback to summary
private void attemptAuthentication(boolean usePasswdFromSharedState) throws LoginException

Attempt authentication

Parameters
usePasswdFromSharedState:boolean

a flag to tell this method whether to retrieve the password from the sharedState.

cleanStateback to summary
private void cleanState()

Clean out state because of a failed authentication attempt

commitback to summary
public boolean commit() throws LoginException

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

Complete user authentication (Authentication Phase 2).

This method is called if the LoginContext's overall authentication has succeeded (all the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules have 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 JMXPrincipal with the Subject located in the LoginModule. 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
getUsernamePasswordback to summary
private void getUsernamePassword(boolean usePasswdFromSharedState) throws LoginException

Get the username and password. This method does not return any value. Instead, it sets global name and password variables.

Also note that this method will set the username and password values in the shared state in case subsequent LoginModules want to use them via use/tryFirstPass.

Parameters
usePasswdFromSharedState:boolean

boolean that tells this method whether to retrieve the password from the sharedState.

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 to acquire the user's name and password.

sharedState:Map<String, ?>

shared LoginModule state.

options:Map<String, ?>

options specified in the login Configuration for this particular LoginModule.

loginback to summary
public boolean login() throws LoginException

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

Begin user authentication (Authentication Phase 1).

Acquire the user's name and password and verify them against the corresponding credentials from the password file.

Returns:boolean

true always, since this LoginModule should not be ignored.

Exceptions
LoginException:
if this LoginModule is unable to perform the authentication.
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 that were added by the commit method.

Returns:boolean

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

Exceptions
LoginException:
if the logout fails.