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

public final Class HashedPasswordManager

extends Object
Class Inheritance
Imports
com.sun.jmx.remote.util.ClassLogger, java.io.*, java.nio.ByteBuffer, .CharBuffer, java.nio.channels.FileLock, java.security.MessageDigest, .NoSuchAlgorithmException, .SecureRandom, java.util.Arrays, .Base64, .HashMap, .Map, java.util.concurrent.atomic.AtomicBoolean

HashedPasswordManager loads passwords from the password file and optionally hashes them.

This class accepts Unicode UTF-8 encoded file

Each entry in the password file contains a username followed by a password. Password can be in clear text or as a hash. Hashed passwords must follow the below format. hashedPassword = base64_encoded_64_byte_salt W base64_encoded_hash W hash_algorithm where, W = spaces, base64_encoded_64_byte_salt = 64 byte random salt, base64_encoded_hash = hash_algorithm(password + salt), hash_algorithm = Algorithm string as specified in hash_algorithm is an optional field. If not specified, SHA3-512 will be assumed.

If passwords are in clear, they will be over-written by their hash if hashing is requested by setting com.sun.management.jmxremote.password.toHashes property to true in the management.properties file and if the password file is writable and if the system security policy allows writing into the password file, if a security manager is configured

In order to change the password for a role, replace the hashed password entry with a new clear text password or a new hashed password. If the new password is in clear, it will be replaced with its hash when a new login attempt is made.

A given role should have at most one entry in this file. If a role has no entry, it has no access. If multiple entries are found for the same role name, then the last one will be used.

A user generated hashed password file can also be used instead of a clear-text password file. If generated by the user, hashed passwords must follow the format specified above.

External Specification
Java Security Standard Algorithm Names

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private boolean
private static final ClassLogger
private final String
private final SecureRandom
private final boolean
private final Map<String, HashedPasswordManager.UserCredentials>

Constructor Summary

AccessConstructor and Description
public
HashedPasswordManager(String
UTF-8 encoded input file to read passwords from
filename
,
boolean
Request for clear passwords to be hashed
shouldHashPasswords
)

Creates a new password manager for the input password file

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean

Returns:

true if authentication succeeds, false otherwise
authenticate
(String
Input username
userName
,
char[]
Input password
inputPassword
)

Authenticate the supplied credentials against the one present in the file

private String[]
getHash(String algorithm, String password)

public synchronized void
loadPasswords()

Load passwords from the password file.

private String[]
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DefaultHashAlgorithmback to summary
private static final String DefaultHashAlgorithm
DefaultSaltLengthback to summary
private static final int DefaultSaltLength
isLoggedback to summary
private boolean isLogged
loggerback to summary
private static final ClassLogger logger
passwordFileback to summary
private final String passwordFile
randomback to summary
private final SecureRandom random
shouldHashPasswordsback to summary
private final boolean shouldHashPasswords
userCredentialsMapback to summary
private final Map<String, HashedPasswordManager.UserCredentials> userCredentialsMap

Constructor Detail

HashedPasswordManagerback to summary
public HashedPasswordManager(String filename, boolean shouldHashPasswords)

Creates a new password manager for the input password file

Parameters
filename:String

UTF-8 encoded input file to read passwords from

shouldHashPasswords:boolean

Request for clear passwords to be hashed

Method Detail

authenticateback to summary
public synchronized boolean authenticate(String userName, char[] inputPassword)

Authenticate the supplied credentials against the one present in the file

Parameters
userName:String

Input username

inputPassword:char[]

Input password

Returns:boolean

true if authentication succeeds, false otherwise

getHashback to summary
private String[] getHash(String algorithm, String password)
loadPasswordsback to summary
public synchronized void loadPasswords() throws IOException

Load passwords from the password file.

This method should be called for every login attempt to load new/changed credentials, if any.

If hashing is requested, clear passwords will be over-written with their SHA3-512 hash

Exceptions
IOException:
If unable to access the file
readPasswordFileback to summary
private String[] readPasswordFile() throws IOException
writePasswordFileback to summary
private void writePasswordFile(String input) throws IOException
com.sun.jmx.remote.security back to summary

private final Class HashedPasswordManager.UserCredentials

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.jmx.remote.security.HashedPasswordManager.UserCredentials

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
UserCredentials(String userName, String hashAlgorithm, String b64Salt, String b64Hash)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

b64Hashback to summary
private final String b64Hash
b64Saltback to summary
private final String b64Salt
hashAlgorithmback to summary
private final String hashAlgorithm
userNameback to summary
private final String userName

Constructor Detail

UserCredentialsback to summary
public UserCredentials(String userName, String hashAlgorithm, String b64Salt, String b64Hash)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override