Subversion Repositories bacoAlunos

Rev

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

package pt.estgp.estgweb.domain;

import pt.estgp.estgweb.utils.RoleManager;
import pt.estgp.estgweb.Globals;

import java.util.Date;
import java.util.List;
import java.io.Serializable;

import org.apache.log4j.Logger;

/**
 * @author Jorge Machado
 * @date 2/Mar/2008
 * @time 10:27:25
 * @see pt.estgp.estgweb.domain
 */

public abstract class GenericUserImpl extends GenericUser implements IOwned
{

    private static 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(GenericUserImpl.class);

    public GenericUserImpl()
    {
    }

    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
    {
        return getId();
    }

    public void addRole(1.5.0/docs/api/java/lang/String.html">String role)
    {
        setRoles(RoleManager.addRole(super.getRoles(), role));
    }
    public void removeRole(1.5.0/docs/api/java/lang/String.html">String role)
    {
        setRoles(RoleManager.removeRole(super.getRoles(), role));
    }

    public boolean hasRole(1.5.0/docs/api/java/lang/String.html">String r)
    {
        if (r == null || getRoles() == null || getRoles().length() == 0)
            return false;
        for (1.5.0/docs/api/java/lang/String.html">String role : RoleManager.getRolesFromSerial(getRoles()))
        {
            if (role.equals(r))
                return true;
        }
        return false;
    }

    public boolean hasRole(List<String> roles)
    {
        return RoleManager.hasRole(this,roles);
    }

    public GenericUser getOwner()
    {
        return this;
    }

    /**
     * @return a list of role Strings
     */

    public List<String> getOwnerRoles()
    {
        return getRolesList();
    }

    /**
     * Not implemented here
     * @return null
     */

    public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole()
    {
        logger.warn("Invoke not implemented method in class:" + getClass().getName());
        return null;
    }

    public List<String> getRolesList()
    {
        return RoleManager.getRolesFromSerial(getRoles());
    }

    public boolean isSuperuser()
    {
        return super.isSuperuser() || hasRole(Globals.SUPER_USER_ROLE);
    }

    public boolean isAdmin()
    {
        return hasRole(Globals.ADMIN_ROLE);
    }

    public boolean isSuperuserOrAdmin()
    {
        return isSuperuser() || isAdmin();
    }
}