Code cleanups.
This commit is contained in:
parent
3521c76d53
commit
b1b94d870e
|
@ -26,7 +26,6 @@ import org.eclipse.jetty.util.TypeUtil;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Credentials. The Credential class represents an abstract mechanism for
|
||||
* checking authentication credentials. A credential instance either represents
|
||||
|
@ -39,15 +38,12 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* This class includes an implementation for unix Crypt an MD5 digest.
|
||||
*
|
||||
* @see Password
|
||||
*
|
||||
*/
|
||||
public abstract class Credential implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -7760551052768181572L;
|
||||
private static final Logger LOG = Log.getLogger(Credential.class);
|
||||
|
||||
private static final long serialVersionUID = -7760551052768181572L;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Check a credential
|
||||
*
|
||||
|
@ -59,7 +55,6 @@ public abstract class Credential implements Serializable
|
|||
*/
|
||||
public abstract boolean check(Object credentials);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* 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
|
||||
|
@ -76,15 +71,13 @@ public abstract class Credential implements Serializable
|
|||
return new Password(credential);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Unix Crypt Credentials
|
||||
*/
|
||||
public static class Crypt extends Credential
|
||||
{
|
||||
private static final long serialVersionUID = -2027792997664744210L;
|
||||
|
||||
public static final String __TYPE = "CRYPT:";
|
||||
private static final String __TYPE = "CRYPT:";
|
||||
|
||||
private final String _cooked;
|
||||
|
||||
|
@ -100,58 +93,49 @@ public abstract class Credential implements Serializable
|
|||
credentials=new String((char[])credentials);
|
||||
if (!(credentials instanceof String) && !(credentials instanceof Password))
|
||||
LOG.warn("Can't check " + credentials.getClass() + " against CRYPT");
|
||||
|
||||
String passwd = credentials.toString();
|
||||
return _cooked.equals(UnixCrypt.crypt(passwd, _cooked));
|
||||
}
|
||||
|
||||
public static String crypt(String user, String pw)
|
||||
{
|
||||
return "CRYPT:" + UnixCrypt.crypt(pw, user);
|
||||
return __TYPE + UnixCrypt.crypt(pw, user);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* MD5 Credentials
|
||||
*/
|
||||
public static class MD5 extends Credential
|
||||
{
|
||||
private static final long serialVersionUID = 5533846540822684240L;
|
||||
|
||||
public static final String __TYPE = "MD5:";
|
||||
|
||||
public static final Object __md5Lock = new Object();
|
||||
|
||||
private static final String __TYPE = "MD5:";
|
||||
private static final Object __md5Lock = new Object();
|
||||
private static MessageDigest __md;
|
||||
|
||||
private final byte[] _digest;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
MD5(String digest)
|
||||
{
|
||||
digest = digest.startsWith(__TYPE) ? digest.substring(__TYPE.length()) : digest;
|
||||
_digest = TypeUtil.parseBytes(digest, 16);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public byte[] getDigest()
|
||||
{
|
||||
return _digest;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean check(Object credentials)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] digest = null;
|
||||
|
||||
if (credentials instanceof char[])
|
||||
credentials=new String((char[])credentials);
|
||||
if (credentials instanceof Password || credentials instanceof String)
|
||||
{
|
||||
byte[] digest;
|
||||
synchronized (__md5Lock)
|
||||
{
|
||||
if (__md == null) __md = MessageDigest.getInstance("MD5");
|
||||
|
@ -193,7 +177,6 @@ public abstract class Credential implements Serializable
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static String digest(String password)
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue