Subversion Repositories general

Rev

Rev 1015 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.hostadmiral.core.model;

import java.util.Date;

import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.DigestMd5;

/**
 *
 * @hibernate.class table="passwords"
 * @hibernate.discriminator column="digest" type="string"
 */
public abstract class PasswordStoreAbstract
        implements PasswordStore, Cloneable
{
        private   Long   id;
        private   Date   modStamp;
        private   User   modUser;
        protected String digest;
        protected String password;

        /**
         *
         * @hibernate.id generator-class="native"
         */
        public Long getId()
        {
                return id;
        }

        protected void setId(Long id)
        {
                this.id = id;
        }

        /**
         *
         * @hibernate.timestamp column="mod_stamp"
         */
        public Date getModStamp()
        {
                return modStamp;
        }

        protected void setModStamp(Date modStamp)
        {
                this.modStamp = modStamp;
        }

        /**
         *
         * @hibernate.many-to-one column="mod_user"
         */
        public User getModUser()
        {
                return modUser;
        }

        protected void setModUser(User modUser)
        {
                this.modUser = modUser;
        }

        /**
         * returns digest name, e.g. "MD5"
         */
        public String getDigest()
        {
                return digest;
        }

        /**
         * to store to persistent store
         *
         * @hibernate.property
         */
        public String getPassword()
        {
                return password;
        }

        /**
         * to store from persistent store
         */
        public void setPassword(String password)
        {
                this.password = password;
        }

        /**
         * to set by user
         */
        public void setNewPassword(String password)
                throws ModelException
        {
                this.password = encode(password);
        }

        public boolean checkPassword(String password)
                throws ModelException
        {
                return this.password.equals(encode(password));
        }

    protected abstract String encode(String password)
                throws ModelException;

        public Object clone()
                throws CloneNotSupportedException
        {
                PasswordStoreAbstract theClone = (PasswordStoreAbstract)super.clone();
                theClone.password = password;
                return theClone;
        }

        public boolean getReversable()
        {
                return false;
        }

        public String getOriginalPassword()
                throws UnsupportedOperationException
        {
                throw new UnsupportedOperationException("Not able to restore original password");
        }
}