Package org.restlet.ext.crypto
Class DigestVerifier<T extends SecretVerifier>
- java.lang.Object
-
- org.restlet.security.SecretVerifier
-
- org.restlet.ext.crypto.DigestVerifier<T>
-
- All Implemented Interfaces:
Verifier
- Direct Known Subclasses:
HttpDigestVerifier
public class DigestVerifier<T extends SecretVerifier> extends SecretVerifier
Wrapper verifier that can verify digested secrets. If the provided secret is a digest, then the local secret must either be a digest of the same algorithm or the wrapped verifier must be aLocalVerifierreturning secrets in clear.
If the provided secret is a regular secret, then the local secret can be in any digest algorithm or a regular secret.- See Also:
Digest,DigestAuthenticator
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringalgorithmThe digest algorithm of provided secrets.private java.lang.StringwrappedAlgorithmThe digest algorithm of secrets returned by the wrapped verifier.private TwrappedVerifierThe wrapped secret verifier.-
Fields inherited from interface org.restlet.security.Verifier
RESULT_INVALID, RESULT_MISSING, RESULT_STALE, RESULT_UNKNOWN, RESULT_UNSUPPORTED, RESULT_VALID
-
-
Constructor Summary
Constructors Constructor Description DigestVerifier(java.lang.String algorithm, T wrappedVerifier, java.lang.String wrappedAlgorithm)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected char[]digest(java.lang.String identifier, char[] secret, java.lang.String algorithm)Computes the digest of a secret according to a specified algorithm.java.lang.StringgetAlgorithm()Returns the digest algorithm of provided secrets.java.lang.StringgetWrappedAlgorithm()Returns the digest algorithm of secrets returned by the wrapped verifier.char[]getWrappedSecret(java.lang.String identifier)Returns the wrapped secret associated to a given identifier.char[]getWrappedSecretDigest(java.lang.String identifier)Returns the digest of the wrapped secret associated to a given identifier.TgetWrappedVerifier()Returns the wrapped secret verifier.voidsetAlgorithm(java.lang.String algorithm)Sets the digest algorithm of provided secrets.voidsetWrappedAlgorithm(java.lang.String wrappedAlgorithm)Sets the digest algorithm of secrets returned by the wrapped verifier.voidsetWrappedVerifier(T wrappedVerifier)Sets the wrapped secret verifier.intverify(java.lang.String identifier, char[] secret)Verifies that the identifier/secret couple is valid.-
Methods inherited from class org.restlet.security.SecretVerifier
compare, createUser, getIdentifier, getSecret, verify
-
-
-
-
Field Detail
-
algorithm
private java.lang.String algorithm
The digest algorithm of provided secrets.
-
wrappedAlgorithm
private java.lang.String wrappedAlgorithm
The digest algorithm of secrets returned by the wrapped verifier.
-
wrappedVerifier
private T extends SecretVerifier wrappedVerifier
The wrapped secret verifier.
-
-
Constructor Detail
-
DigestVerifier
public DigestVerifier(java.lang.String algorithm, T wrappedVerifier, java.lang.String wrappedAlgorithm)Constructor.- Parameters:
algorithm- The digest algorithm of provided secrets.wrappedVerifier- The wrapped secret verifier.wrappedAlgorithm- The digest algorithm of secrets provided by the wrapped verifier.- See Also:
Digest
-
-
Method Detail
-
digest
protected char[] digest(java.lang.String identifier, char[] secret, java.lang.String algorithm)Computes the digest of a secret according to a specified algorithm. By default, MD5 hashes (represented as a sequence of 32 hexadecimal digits) and SHA-1 hashes are supported. For additional algorithm, override this method.- Parameters:
identifier- The user identifier.secret- The regular secret to digest.algorithm- The digest algorithm to use.- Returns:
- The digested secret.
- See Also:
Digest
-
getAlgorithm
public java.lang.String getAlgorithm()
Returns the digest algorithm of provided secrets. Provided secrets are the ones sent by clients when attempting to authenticate.- Returns:
- The digest algorithm of input secrets.
-
getWrappedAlgorithm
public java.lang.String getWrappedAlgorithm()
Returns the digest algorithm of secrets returned by the wrapped verifier. The secrets from the wrapped verifier are the ones used by the verifier to compare those sent by clients when attempting to authenticate.- Returns:
- The digest algorithm of secrets returned by the wrapped verifier.
-
getWrappedSecret
public char[] getWrappedSecret(java.lang.String identifier)
Returns the wrapped secret associated to a given identifier. This method can only be called if the wrapped verifier is aLocalVerifier.- Parameters:
identifier- The identifier to lookup.- Returns:
- The secret associated to the identifier or null.
-
getWrappedSecretDigest
public char[] getWrappedSecretDigest(java.lang.String identifier)
Returns the digest of the wrapped secret associated to a given identifier. If the wrapped algorithm is null it returns the digest of the wrapped secret, otherwise the algorithms must be identical. This method can only be called if the wrapped verifier is aLocalVerifier.- Parameters:
identifier- The identifier to lookup.- Returns:
- The secret associated to the identifier or null.
-
getWrappedVerifier
public T getWrappedVerifier()
Returns the wrapped secret verifier.- Returns:
- The wrapped secret verifier.
-
setAlgorithm
public void setAlgorithm(java.lang.String algorithm)
Sets the digest algorithm of provided secrets. Provided secrets are the ones sent by clients when attempting to authenticate.- Parameters:
algorithm- The digest algorithm of secrets provided by the user.- See Also:
Digest
-
setWrappedAlgorithm
public void setWrappedAlgorithm(java.lang.String wrappedAlgorithm)
Sets the digest algorithm of secrets returned by the wrapped verifier. The secrets from the wrapped verifier are the ones used by the verifier to compare those sent by clients when attempting to authenticate.- Parameters:
wrappedAlgorithm- The digest algorithm of secrets returned by the wrapped verifier.- See Also:
Digest
-
setWrappedVerifier
public void setWrappedVerifier(T wrappedVerifier)
Sets the wrapped secret verifier.- Parameters:
wrappedVerifier- The wrapped secret verifier.
-
verify
public int verify(java.lang.String identifier, char[] secret)Description copied from class:SecretVerifierVerifies that the identifier/secret couple is valid. It throws an IllegalArgumentException in case the identifier is either null or does not identify a user.- Specified by:
verifyin classSecretVerifier- Parameters:
identifier- The user identifier to match.secret- The provided secret to verify.- Returns:
- Result of the verification based on the RESULT_* constants.
-
-