UserLogin.java

<quote>
/**
 *
 */
package org.ssc.webapp;

import java.security.Principal;
import java.util.HashSet;
import java.util.Set;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
/**
 * @author steve
 *
 */
public class UserLogin {
    private String  name;
    private String password;
    private String email;
    // should we have the set of roles here too?
    private Set<String> myRoles;
   
    { // put in a static init block to write to stderr when class is loaded
        // avoid all the other class loading msgs using -verbose:class
        System.err.println("Loading class UserLogin");
    }

    public UserLogin() {
        // just to see what gets displayed as managed bean
        name= "Unknown";
        myRoles = new HashSet<String>();
    }
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
   
    // Faces specific methods
   
    /**
     * @return - string containing names of Roles for this use - NULL if none.
     */
    public String getLoginName() {
        FacesContext fCtx = FacesContext.getCurrentInstance();
        ExternalContext eCtx = fCtx.getExternalContext();
        Principal who = eCtx.getUserPrincipal();
        if ( who != null ) {
            System.err.println("User.getLoginName - from Principal object");
            return who.getName();
        }
        return "Unknown";
    }
   
    /**
     *
     * @return Navigation result "loggedOut" to indicate session is terminated
     */
    public String logoutUser() {
        FacesContext fCtx = FacesContext.getCurrentInstance();
        ExternalContext eCtx = fCtx.getExternalContext();
        eCtx.invalidateSession();
        name = "Unknown";
        System.err.println("User.logout - username should be blank or Unknown");
        return "loggedOut";
    }
}
</quote>
Comments