FileDocCategorySizeDatePackage
DefaultUser.javaAPI DocApache James 2.3.14279Fri Jan 12 12:56:32 GMT 2007org.apache.james.userrepository

DefaultUser

public class DefaultUser extends Object implements Serializable, org.apache.james.services.User
Implementation of User Interface. Instances of this class do not allow the the user name to be reset.
version
CVS $Revision: 494012 $

Fields Summary
private static final long
serialVersionUID
private String
userName
private String
hashedPassword
private String
algorithm
Constructors Summary
public DefaultUser(String name, String hashAlg)
Standard constructor.

param
name the String name of this user
param
hashAlg the algorithm used to generate the hash of the password


                               
         
        userName = name;
        algorithm = hashAlg;
    
public DefaultUser(String name, String passwordHash, String hashAlg)
Constructor for repositories that are construcing user objects from separate fields, e.g. databases.

param
name the String name of this user
param
passwordHash the String hash of this users current password
param
hashAlg the String algorithm used to generate the hash of the password

        userName = name;
        hashedPassword = passwordHash;
        algorithm = hashAlg;
    
Methods Summary
protected java.lang.StringgetHashAlgorithm()
Method to access the hashing algorithm of the password.

return
the name of the hashing algorithm used for this user's password

        return algorithm;
    
protected java.lang.StringgetHashedPassword()
Method to access hash of password

return
the String of the hashed Password

        return hashedPassword;
    
public java.lang.StringgetUserName()
Accessor for immutable name

return
the String of this users name

        return userName;
    
public booleansetPassword(java.lang.String newPass)
Sets new password from String. No checks made on guessability of password.

param
newPass the String that is the new password.
return
true if newPass successfuly hashed

        try {
            hashedPassword = DigestUtil.digestString(newPass, algorithm);
            return true;
        } catch (NoSuchAlgorithmException nsae) {
            throw new RuntimeException("Security error: " + nsae);
        }
    
public booleanverifyPassword(java.lang.String pass)
Method to verify passwords.

param
pass the String that is claimed to be the password for this user
return
true if the hash of pass with the current algorithm matches the stored hash.

        try {
            String hashGuess = DigestUtil.digestString(pass, algorithm);
            return hashedPassword.equals(hashGuess);
        } catch (NoSuchAlgorithmException nsae) {
        throw new RuntimeException("Security error: " + nsae);
    }