/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package org.apache.james.nntpserver;

/**
 * Provides Authentication Credentials.
 *
 * Helps manage the Protocol Authentication state, resets
 * authenticated flag as need be.
 *
 * Helps avoid unnecessary re authentication.
 *
 * @author  Harmeet <harmeet@kodemuse.com> 
 */
public class AuthState
{
    private String userID;
    private String password;
    private boolean authenticated;
    
    // ---- methods invoked by authentication service -----
    /**
     * @return value of authenticated flag.
     */
    public boolean isAuthenticated() {
        return authenticated;
    }
    
    /**
     * Get the value of userID.
     * @return value of userID.
     */
    public String getUserID() {
        return userID;
    }
    
    /**
     * Get the value of password.
     * @return value of password.
     */
    public String getPassword() {
        return password;
    }
    
    // ---- mutator methods called only by protocol handler -----

    /**
     * @param v  Value to assign to indicate authentication done or not.
     */
    void setAuthenticated(boolean  v) {
        this.authenticated = v;
    }
    
    /**
     * Set the value of userID. reset authentication state
     * @param v  Value to assign to userID.
     */
    void setUserID(String  v) {
        reset();
        this.userID = v;
    }
    
    /**
     * Set the value of password. reset authentication flag
     * @param v  Value to assign to password.
     */
    void setPassword(String  v) {
        this.authenticated = false;
        this.password = v;
    }

    /** reset to initial state */
    void reset() {
        userID = password = null;
        authenticated = false;
    }
}
