/*  Copyright (c) 2000, 2002 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v1.http; 
import java.util.Vector; 
import java.util.StringTokenizer;
import java.util.Enumeration; 

/**
 * <p> <b>Authentication</b> details can be configured using this class. Details
 * include ... <br>
 * <ol><li><code>authType</code> : Authentication type which can be either <code>
 * </code>basic for basic authentication or <code>externalApp</code> for form
 * based authentication.</li>
 * <li><code>errorPageMessages</code> : Error Messages to be searched by
 * URLSecurityManager to find out if the user is authorized to view the content.
 * </li></ol>
 * <p> Remaining authentication details are directly read from portal's external
 * application.
 *
 */
public class Authentication 
{ 
    
    //variables for storing corresponding	tag	values of provider.xml
    private String mAuthType = "externalApp"; 
    private Vector mErrorMessages = null; 
    
    /**
     * Get method for authType tag in provider.xml
     * @return String value of authType tag.
     *
     */
    public String getAuthType() 
    { 
        return mAuthType; 
    } 
    
    /**
     * Set method for authType tag in provider.xml
     * Valid authentication types are
     * <ul><li>none : Indicates no authentication is required.</li>
     * <li>basic : Indicates BASIC Mode of authentication should be used.</li>
     * <li>externalApp : Indicates FORM based authentiaction should be used.</li>
     * </ul>
     * <p> Authentication details needed are fetched from portal's external
     * application. For more details see articles on External Applications in
     * portalstudio.</p>
     * @param authType Type of authentication needed.
     *
     */
    public void setAuthType(String authType) 
    { 
        mAuthType = authType; 
    } 
    
    /**
     *	Returns	the	error messages which can be	used to	see	if the login 
     *  is successful or not.
     *	@return	Vector error messages. If none present, returns null.
     *
     */
    public Vector getErrorPageMessages() 
    { 
        return mErrorMessages; 
    } 
    
    /**
     *	<p>Sets the error message string. These messages are searched by URLSecurity
     * Manager in order to determine if the user is authorized or not.
     * <p>For example if the user provides wrong username/password, Yahoo login
     * applicaiton displays <b><i>Invalid User</i></b> (or) <b><i>Invalid password
     * </i></b> etc., Such type of strings can be specified for the <code>
     * errorPageMessages</code> tag, seperated by commas (',')
     *
     *	@param mesg	String of error	messages.
     *
     */
    public void setErrorPageMessages(String mesg) 
    { 
        //Make tokens out of the errorMessage string which is 
        //seperated by commas.
        StringTokenizer strTokenizer = new StringTokenizer(mesg,","); 

        if(mErrorMessages == null)
        {
            mErrorMessages = new Vector(strTokenizer.countTokens());
        }
        
        //Extract all tokens to see if the specified messages exist in the url content.
        while (strTokenizer.hasMoreTokens()) 
        { 
            String msg = (String)strTokenizer.nextElement();
            mErrorMessages.addElement(msg);
        }
    }
} 