Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.security

public abstract Class Credential

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.eclipse.jetty.util.security.Credential.Crypt, org.eclipse.jetty.util.security.Credential.MD5, org.eclipse.jetty.util.security.Password
Imports
java.io.Serializable, java.nio.charset.StandardCharsets, java.security.MessageDigest, java.util.List, .ServiceLoader, java.util.stream.Collectors, org.eclipse.jetty.util.StringUtil, org.eclipse.jetty.util.thread.AutoLock

Credentials. The Credential class represents an abstract mechanism for checking authentication credentials. A credential instance either represents a secret, or some data that could only be derived from knowing the secret.

Often a Credential is related to a Password via a one way algorithm, so while a Password itself is a Credential, a UnixCrypt or MD5 digest of a a password is only a credential that can be checked against the password.

This class includes an implementation for unix Crypt an MD5 digest.

See Also
Password

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Credential.Crypt

Unix Crypt Credentials

public static class
Credential.MD5

MD5 Credentials

Field Summary

Modifier and TypeField and Description
private static final List<CredentialProvider>
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static boolean

Returns:

whether the two byte arrays are equal
byteEquals
(byte[]
the first byte array to compare (should be known value)
known
,
byte[]
the second byte array to compare (should be unknown value)
unknown
)

Utility method that replaces Arrays.equals() to avoid timing attacks.

public abstract boolean

Returns:

True if the credentials indicated that the shared secret is known to both this Credential and the passed credential.
check
(Object
The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.
credentials
)

Check a credential

public static Credential

Returns:

A Credential or Password instance.
getCredential
(String
String representation of the credential
credential
)

Get a credential from a String.

protected static boolean

Returns:

whether the two strings are equal
stringEquals
(String
the first string to compare (should be known string)
known
,
String
the second string to compare (should be the unknown string)
unknown
)

Utility method that replaces String.equals() to avoid timing attacks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CREDENTIAL_PROVIDERSback to summary
private static final List<CredentialProvider> CREDENTIAL_PROVIDERS
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Credentialback to summary
public Credential()

Method Detail

byteEqualsback to summary
protected static boolean byteEquals(byte[] known, byte[] unknown)

Utility method that replaces Arrays.equals() to avoid timing attacks. The length of the loop executed will always be the length of the unknown credential

Parameters
known:byte[]

the first byte array to compare (should be known value)

unknown:byte[]

the second byte array to compare (should be unknown value)

Returns:boolean

whether the two byte arrays are equal

checkback to summary
public abstract boolean check(Object credentials)

Check a credential

Parameters
credentials:Object

The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.

Returns:boolean

True if the credentials indicated that the shared secret is known to both this Credential and the passed credential.

getCredentialback to summary
public static Credential getCredential(String credential)

Get a credential from a String. If the credential String starts with a known Credential type (eg "CRYPT:" or "MD5:" ) then a Credential of that type is returned. Otherwise, it tries to find a credential provider whose prefix matches with the start of the credential String. Else the credential is assumed to be a Password.

Parameters
credential:String

String representation of the credential

Returns:Credential

A Credential or Password instance.

stringEqualsback to summary
protected static boolean stringEquals(String known, String unknown)

Utility method that replaces String.equals() to avoid timing attacks. The length of the loop executed will always be the length of the unknown credential

Parameters
known:String

the first string to compare (should be known string)

unknown:String

the second string to compare (should be the unknown string)

Returns:boolean

whether the two strings are equal

org.eclipse.jetty.util.security back to summary

public Class Credential.Crypt

extends Credential
Class Inheritance

Unix Crypt Credentials

Field Summary

Modifier and TypeField and Description
private static final String
private final String
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
Crypt(String cooked)

Method Summary

Modifier and TypeMethod and Description
public boolean
check(Object
The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.
credentials
)

Implements abstract org.eclipse.jetty.util.security.Credential.check.

Check a credential

public static String
crypt(String user, String pw)

public boolean
equals(Object
the reference object with which to compare.
credential
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

Inherited from org.eclipse.jetty.util.security.Credential:
byteEqualsgetCredentialstringEquals

Field Detail

__TYPEback to summary
private static final String __TYPE
_cookedback to summary
private final String _cooked
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.eclipse.jetty.util.security.Credential.serialVersionUID.

Constructor Detail

Cryptback to summary
pack-priv Crypt(String cooked)

Method Detail

checkback to summary
public boolean check(Object credentials)

Implements abstract org.eclipse.jetty.util.security.Credential.check.

Doc from org.eclipse.jetty.util.security.Credential.check.

Check a credential

Parameters
credentials:Object

The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.

Returns:boolean

True if the credentials indicated that the shared secret is known to both this Credential and the passed credential.

Annotations
@Override
cryptback to summary
public static String crypt(String user, String pw)
equalsback to summary
public boolean equals(Object credential)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
credential:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
org.eclipse.jetty.util.security back to summary

public Class Credential.MD5

extends Credential
Class Inheritance

MD5 Credentials

Field Summary

Modifier and TypeField and Description
private static MessageDigest
private static final AutoLock
private static final String
private final byte[]
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
MD5(String digest)

Method Summary

Modifier and TypeMethod and Description
public boolean
check(Object
The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.
credentials
)

Implements abstract org.eclipse.jetty.util.security.Credential.check.

Check a credential

public static String
digest(String password)

Used only by Command Line Password utility

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public byte[]
Inherited from org.eclipse.jetty.util.security.Credential:
byteEqualsgetCredentialstringEquals

Field Detail

__mdback to summary
private static MessageDigest __md
__md5Lockback to summary
private static final AutoLock __md5Lock
__TYPEback to summary
private static final String __TYPE
_digestback to summary
private final byte[] _digest
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.eclipse.jetty.util.security.Credential.serialVersionUID.

Constructor Detail

MD5back to summary
pack-priv MD5(String digest)

Method Detail

checkback to summary
public boolean check(Object credentials)

Implements abstract org.eclipse.jetty.util.security.Credential.check.

Doc from org.eclipse.jetty.util.security.Credential.check.

Check a credential

Parameters
credentials:Object

The credential to check against. This may either be another Credential object, a Password object or a String which is interpreted by this credential.

Returns:boolean

True if the credentials indicated that the shared secret is known to both this Credential and the passed credential.

Annotations
@Override
digestback to summary
public static String digest(String password)

Used only by Command Line Password utility

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDigestback to summary
public byte[] getDigest()