java.lang.Object
org.codelibs.jcifs.smb.impl.NtlmPasswordAuthenticator
- All Implemented Interfaces:
Serializable,Cloneable,Principal,Credentials,CredentialsInternal
- Direct Known Subclasses:
Kerb5Authenticator,NtlmNtHashAuthenticator,NtlmPasswordAuthentication
public class NtlmPasswordAuthenticator
extends Object
implements Principal, CredentialsInternal, Serializable
This class stores and encrypts NTLM user credentials.
Contrary to
NtlmPasswordAuthentication this does not cause guest authentication
when the "guest" username is supplied. Use NtlmPasswordAuthenticator.AuthenticationType instead.- Author:
- mbechler
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAuthentication strategy -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstruct anonymous credentialsNtlmPasswordAuthenticator(String username, String password) Create username/password credentialsNtlmPasswordAuthenticator(String domain, String username, String password) Create username/password credentials with specified domainprotectedNtlmPasswordAuthenticator(String userInfo, String defDomain, String defUser, String defPassword) Create an NtlmPasswordAuthenticator from user info with defaults.protectedNtlmPasswordAuthenticator(String userInfo, String defDomain, String defUser, String defPassword, NtlmPasswordAuthenticator.AuthenticationType type) Create authenticator from URL userInfo stringNtlmPasswordAuthenticator(String domain, String username, String password, NtlmPasswordAuthenticator.AuthenticationType type) Create username/password credentials with specified domainCreate an NtlmPasswordAuthenticator with the specified authentication type. -
Method Summary
Modifier and TypeMethodDescriptionclone()Create a copy of the credentials.protected static voidcloneInternal(NtlmPasswordAuthenticator cloned, NtlmPasswordAuthenticator toClone) Clone internal fields from one authenticator to another.createContext(CIFSContext tc, String targetDomain, String host, byte[] initialToken, boolean doSigning) Create an SSP context for authentication.booleanCompares twoNtlmPasswordAuthenticationobjects for equality.byte[]getAnsiHash(CIFSContext tc, byte[] chlng) Computes the 24 byte ANSI password hash given the 8 byte server challenge.getName()Return the domain and username in the format:domain\\username.protected byte[]Get the NT hash of the passwordReturns the password in plain text ornullif the raw password hashes were used to construct thisNtlmPasswordAuthenticationobject which will be the case when NTLM HTTP Authentication is used.byte[]getSigningKey(CIFSContext tc, byte[] chlng) Get the signing key for this authenticationGet the original specified user domainGet the security subject associated with these credentials.byte[]getUnicodeHash(CIFSContext tc, byte[] chlng) Computes the 24 byte Unicode password hash given the 8 byte server challenge.Returns the domain.Returns the username.byte[]getUserSessionKey(CIFSContext tc, byte[] chlng) Returns the effective user session key.voidgetUserSessionKey(CIFSContext tc, byte[] chlng, byte[] dest, int offset) Calculates the effective user session key.Guess the authentication type based on the username formatinthashCode()Return the upcased username hash code.booleanCheck if these are anonymous credentials.booleanisGuest()Check if these are guest credentials.booleanisPreferredMech(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism) Check if the given mechanism is preferred for this credentialvoidrefresh()Refresh the credentials.toString()Return the domain and username in the format:domain\\username.<T extends Credentials>
TUnwrap credentials to a specific type.
-
Constructor Details
-
NtlmPasswordAuthenticator
public NtlmPasswordAuthenticator()Construct anonymous credentials -
NtlmPasswordAuthenticator
Create an NtlmPasswordAuthenticator with the specified authentication type.- Parameters:
type- the authentication type to use
-
NtlmPasswordAuthenticator
Create username/password credentials- Parameters:
username- the username for authenticationpassword- the password for authentication
-
NtlmPasswordAuthenticator
Create username/password credentials with specified domain- Parameters:
domain- the domain for authenticationusername- the username for authenticationpassword- the password for authentication
-
NtlmPasswordAuthenticator
public NtlmPasswordAuthenticator(String domain, String username, String password, NtlmPasswordAuthenticator.AuthenticationType type) Create username/password credentials with specified domain- Parameters:
domain- the authentication domainusername- the username for authenticationpassword- the password for authenticationtype- authentication type
-
NtlmPasswordAuthenticator
protected NtlmPasswordAuthenticator(String userInfo, String defDomain, String defUser, String defPassword) Create an NtlmPasswordAuthenticator from user info with defaults.- Parameters:
userInfo- the user information stringdefDomain- the default domain if not specifieddefUser- the default username if not specifieddefPassword- the default password if not specified
-
NtlmPasswordAuthenticator
protected NtlmPasswordAuthenticator(String userInfo, String defDomain, String defUser, String defPassword, NtlmPasswordAuthenticator.AuthenticationType type) Create authenticator from URL userInfo string- Parameters:
userInfo- the userInfo string from URLdefDomain- the default domain to use if not specifieddefUser- the default username to use if not specifieddefPassword- the default password to use if not specifiedtype- the authentication type to use
-
-
Method Details
-
guessAuthenticationType
Guess the authentication type based on the username format- Returns:
- the guessed authentication type
-
unwrap
Description copied from interface:CredentialsUnwrap credentials to a specific type.- Specified by:
unwrapin interfaceCredentials- Type Parameters:
T- the credential type to unwrap to- Parameters:
t- the class of the credential type to unwrap to- Returns:
- instance for type, null if the type cannot be unwrapped
-
getSubject
Description copied from interface:CredentialsInternalGet the security subject associated with these credentials.- Specified by:
getSubjectin interfaceCredentialsInternal- Returns:
- subject associated with the credentials
-
refresh
Description copied from interface:CredentialsInternalRefresh the credentials.- Specified by:
refreshin interfaceCredentialsInternal- Throws:
CIFSException- if refresh fails
-
createContext
public SSPContext createContext(CIFSContext tc, String targetDomain, String host, byte[] initialToken, boolean doSigning) throws SmbException Create an SSP context for authentication.- Specified by:
createContextin interfaceCredentialsInternal- Parameters:
tc- the CIFS contexttargetDomain- the target domain for authenticationhost- the target hostinitialToken- initial authentication token, if anydoSigning- whether message signing should be enabled- Returns:
- a new SSP authentication context
- Throws:
SmbException- if context creation fails- See Also:
-
clone
Description copied from interface:CredentialsInternalCreate a copy of the credentials.- Specified by:
clonein interfaceCredentialsInternal- Overrides:
clonein classObject- Returns:
- a copy of the credentials
-
cloneInternal
protected static void cloneInternal(NtlmPasswordAuthenticator cloned, NtlmPasswordAuthenticator toClone) Clone internal fields from one authenticator to another.- Parameters:
cloned- the target authenticator to copy totoClone- the source authenticator to copy from
-
getUserDomain
Returns the domain.- Specified by:
getUserDomainin interfaceCredentials- Returns:
- the domain the user account is in
-
getSpecifiedUserDomain
Get the original specified user domain- Returns:
- the original specified user domain
-
getUsername
Returns the username.- Returns:
- the username
-
getPassword
Returns the password in plain text ornullif the raw password hashes were used to construct thisNtlmPasswordAuthenticationobject which will be the case when NTLM HTTP Authentication is used. There is no way to retrieve a users password in plain text unless it is supplied by the user at runtime.- Returns:
- the password
-
getName
Return the domain and username in the format:domain\\username. This is equivalent totoString(). -
equals
Compares twoNtlmPasswordAuthenticationobjects for equality. TwoNtlmPasswordAuthenticationobjects are equal if their caseless domain and username fields are equal -
hashCode
public int hashCode()Return the upcased username hash code. -
toString
Return the domain and username in the format:domain\\username. This is equivalent togetName(). -
isAnonymous
public boolean isAnonymous()Description copied from interface:CredentialsCheck if these are anonymous credentials.- Specified by:
isAnonymousin interfaceCredentials- Returns:
- whether these are anonymous credentials
-
isGuest
public boolean isGuest()Description copied from interface:CredentialsCheck if these are guest credentials.- Specified by:
isGuestin interfaceCredentials- Returns:
- whether these are guest credentials
-
isPreferredMech
public boolean isPreferredMech(org.bouncycastle.asn1.ASN1ObjectIdentifier mechanism) Check if the given mechanism is preferred for this credential- Parameters:
mechanism- the mechanism to check- Returns:
- whether the given mechanism is the preferred one for this credential
-
getAnsiHash
Computes the 24 byte ANSI password hash given the 8 byte server challenge.- Parameters:
tc- the CIFS contextchlng- the server challenge- Returns:
- the hash for the given challenge
- Throws:
GeneralSecurityException- if a security error occurs
-
getUnicodeHash
Computes the 24 byte Unicode password hash given the 8 byte server challenge.- Parameters:
tc- the CIFS contextchlng- the server challenge- Returns:
- the hash for the given challenge
- Throws:
GeneralSecurityException- if a security error occurs
-
getSigningKey
public byte[] getSigningKey(CIFSContext tc, byte[] chlng) throws SmbException, GeneralSecurityException Get the signing key for this authentication- Parameters:
tc- the CIFS contextchlng- the server challenge- Returns:
- the signing key
- Throws:
SmbException- if an SMB error occursGeneralSecurityException- if a security error occurs
-
getUserSessionKey
Returns the effective user session key.- Parameters:
tc- the CIFS contextchlng- The server challenge.- Returns:
- A
byte[]containing the effective user session key, used in SMB MAC signing and NTLMSSP signing and sealing.
-
getUserSessionKey
public void getUserSessionKey(CIFSContext tc, byte[] chlng, byte[] dest, int offset) throws SmbException Calculates the effective user session key.- Parameters:
tc- context to usechlng- The server challenge.dest- The destination array in which the user session key will be placed.offset- The offset in the destination array at which the session key will start.- Throws:
SmbException- if an SMB error occurs
-
getNTHash
protected byte[] getNTHash()Get the NT hash of the password- Returns:
- the NT hash
-