Subversion Repositories general

Rev

Rev 925 | Rev 949 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.hostadmiral.core.model;

import ak.hostadmiral.util.Digest;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;

/**
 *
 * @hibernate.class table="mailboxes"
 */
public class Mailbox
        extends GeneralModelObject
{
        private String     login;
        private String     password;
        private InetDomain domain;
        private User       owner;
        private Boolean    virusCheck;
        private Boolean    spamCheck;
        private SystemUser systemUser;

        protected Mailbox()
        {
        }

        /**
         *
         * @hibernate.property
         */
        public String getLogin()
        {
                return login;
        }

        protected void setLogin(String login)
        {
                this.login = login;
        }

        public void setLogin(User editor, String login)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.login = login;
        }

        /**
         *
         * @hibernate.property
         */
        protected String getPassword()
        {
                return password;
        }

        protected void setPassword(String password)
        {
                this.password = password;
        }

        public void setPassword(User editor, String password)
                throws ModelException
        {
                if(password == null)
                        throw new NullPointerException("Null password");

                this.password = Digest.encode(password);
        }

        /**
         *
         * @hibernate.many-to-one
         */
        public InetDomain getDomain()
        {
                return domain;
        }

        protected void setDomain(InetDomain domain)
        {
                this.domain = domain;
        }

        public void setDomain(User editor, InetDomain domain)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.domain = domain;
        }

        /**
         *
         * @hibernate.many-to-one
         */
        public User getOwner()
        {
                return owner;
        }

        protected void setOwner(User owner)
        {
                this.owner = owner;
        }

        public void setOwner(User editor, User owner)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.owner = owner;
        }

        /**
         *
         * @hibernate.property
         */
        public Boolean getVirusCheck()
        {
                return virusCheck;
        }

        protected void setVirusCheck(Boolean virusCheck)
        {
                this.virusCheck = virusCheck;
        }

        public void setVirusCheck(User editor, Boolean virusCheck)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.virusCheck = virusCheck;
        }

        /**
         *
         * @hibernate.property
         */
        public Boolean getSpamCheck()
        {
                return spamCheck;
        }

        protected void setSpamCheck(Boolean spamCheck)
        {
                this.spamCheck = spamCheck;
        }

        public void setSpamCheck(User editor, Boolean spamCheck)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.spamCheck = spamCheck;
        }

        /**
         *
         * @hibernate.many-to-one
         */
        public SystemUser getSystemUser()
        {
                return systemUser;
        }

        protected void setSystemUser(SystemUser systemUser)
        {
                this.systemUser = systemUser;
        }

        public void setSystemUser(User editor, SystemUser systemUser)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.systemUser = systemUser;
        }

        public String getTypeKey()
        {
                return ak.hostadmiral.core.CoreResources.TYPE_MAILBOX;
        }

        public String getIdentKey()
        {
                return ak.hostadmiral.core.CoreResources.IDENT_MAILBOX;
        }

        public Object[] getIdentParams()
        {
                return new Object[] { getLogin(), getDomain().getName() };
        }

        public boolean viewableBy(User user)
        {
                return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
        }

        public boolean editableBy(User user)
        {
                return user.isSuperuser() || user.equals(domain.getOwner());
        }

        public boolean deleteableBy(User user)
        {
                return user.isSuperuser() || user.equals(domain.getOwner());
        }

        protected static boolean allowedToCreate(MailboxManager manager, User editor)
                throws ModelException
        {
                return editor.isSuperuser()
                        || InetDomainManager.getInstance().areInetDomainsAvailable(editor);
        }
}