com.sfs.beans.UserBean.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.beans.UserBean.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.beans;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang.StringUtils;

/**
 * The Class UserBean.
 *
 * @author David Harrison 6th September 2004
 */
public class UserBean implements java.io.Serializable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The dn. */
    private String dn;

    /** The user name. */
    private String userName;

    /** The member of. */
    private Collection<String> memberOf = new ArrayList<String>();

    /** The preferred name. */
    private String preferredName;

    /** The last name. */
    private String lastName;

    /** The password. */
    private String password;

    /** The email. */
    private String email;

    /** The logged in. */
    private boolean loggedIn = false;

    /** The privileges logged in override (default false). */
    private boolean overridePrivileges = false;

    /**
     * Sets the dN.
     *
     * @param dnVal the new dN
     */
    public final void setDN(final String dnVal) {
        this.dn = dnVal;
    }

    /**
     * Gets the dN.
     *
     * @return the dN
     */
    public final String getDN() {
        if (this.dn != null) {
            /* Ensure there are no spaces after ',' */
            this.dn = StringUtils.replace(this.dn, ", ", ",");
        }
        return this.dn;
    }

    /**
     * Sets the user name.
     *
     * @param userNameVal the new user name
     */
    public final void setUserName(final String userNameVal) {
        this.userName = userNameVal;
    }

    /**
     * Gets the user name.
     *
     * @return the user name
     */
    public final String getUserName() {
        return this.userName;
    }

    /**
     * Sets the member of.
     *
     * @param role the new role
     */
    public final void setMemberOf(final String role) {
        if (this.memberOf == null) {
            this.memberOf = new ArrayList<String>();
        }
        this.memberOf.add(role);
    }

    /**
     * Sets the member of.
     *
     * @param memberOfCol the new member of
     */
    public final void setMemberOf(final Collection<String> memberOfCol) {
        this.memberOf = memberOfCol;
    }

    /**
     * Gets the member of.
     *
     * @return the member of
     */
    public final Collection<String> getMemberOf() {
        if (this.memberOf == null) {
            this.memberOf = new ArrayList<String>();
        }
        return this.memberOf;
    }

    /**
     * Sets the preferred name.
     *
     * @param preferredNameVal the new preferred name
     */
    public final void setPreferredName(final String preferredNameVal) {
        this.preferredName = preferredNameVal;
    }

    /**
     * Gets the preferred name.
     *
     * @return the preferred name
     */
    public final String getPreferredName() {
        return this.preferredName;
    }

    /**
     * Sets the last name.
     *
     * @param lastNameVal the new last name
     */
    public final void setLastName(final String lastNameVal) {
        this.lastName = lastNameVal;
    }

    /**
     * Gets the last name.
     *
     * @return the last name
     */
    public final String getLastName() {
        return this.lastName;
    }

    /**
     * Sets the password.
     *
     * @param passwordVal the new password
     */
    public final void setPassword(final String passwordVal) {
        this.password = passwordVal;
    }

    /**
     * Gets the password.
     *
     * @return the password
     */
    public final String getPassword() {
        return this.password;
    }

    /**
     * Sets the email.
     *
     * @param emailVal the new email
     */
    public final void setEmail(final String emailVal) {
        this.email = emailVal;
    }

    /**
     * Gets the email.
     *
     * @return the email
     */
    public final String getEmail() {
        return this.email;
    }

    /**
     * Sets the logged in.
     *
     * @param loggedInVal the new logged in
     */
    public final void setLoggedIn(final boolean loggedInVal) {
        this.loggedIn = loggedInVal;
    }

    /**
     * Gets the logged in.
     *
     * @return the logged in
     */
    public final boolean getLoggedIn() {
        return this.loggedIn;
    }

    /**
     * Sets the override privileges flag.
     *
     * @param overridePrivilegesVal the new override privileges flag
     */
    public final void setOverridePrivileges(final boolean overridePrivilegesVal) {
        this.overridePrivileges = overridePrivilegesVal;
    }

    /**
     * Gets the override privileges flag.
     *
     * @return the override privileges flag
     */
    public final boolean getOverridePrivileges() {
        return this.overridePrivileges;
    }

    /**
     * Checks if is member of.
     *
     * @param group the group
     *
     * @return true, if is member of
     */
    public final boolean isMemberOf(final String group) {
        boolean value = false;
        if (this.memberOf != null) {
            for (String groupName : this.memberOf) {
                if (StringUtils.equalsIgnoreCase(groupName, group)) {
                    value = true;
                }
            }
        }
        return value;
    }

    /**
     * Checks if is financial user.
     *
     * @return true, if is financial user
     */
    public final boolean isFinancialUser() {
        boolean financialUser = false;

        if (isMemberOf("Administrator")) {
            financialUser = true;
        } else {
            if (isMemberOf("Finance")) {
                financialUser = true;
            }
        }
        return financialUser;
    }
}