Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/voytechs/html/util/Authentication.java


1   /*
2    * File: Authentication.java
3    * Auth: Mark Bednarczyk
4    * Desc:
5    * Date: 2001-07-04
6    *   Id: $Id: Authentication.java,v 1.1.1.1 2002/01/23 23:52:45 voytechs Exp $
7    ********************************************
8    * $Log: Authentication.java,v $
9    * Revision 1.1.1.1  2002/01/23 23:52:45  voytechs
10   * Initial public release, BETA 1.0 - voytechs
11   *
12   * Revision 1.1  2001/09/04 15:33:55  markbe
13   * Initial revision
14   *
15   */
16  package com.voytechs.html.util;
17  
18  import java.io.*;
19  import java.util.*;
20  
21  import sun.misc.BASE64Decoder;
22  
23  
24  /**
25   * 
26   */
27  public abstract class Authentication {
28    /* Internal attributes */
29  
30    private String authString = null;
31  
32    private String user = null;
33    private String password = null;
34    /**
35     *
36     * @param
37     * @exception
38     */
39    public Authentication() {
40    }
41  
42    /**
43     * Process current HTTP request for authentication information.
44     */
45    protected void setAuthString(String authString) {
46  
47      if(authString == null)
48        return; // Nothing to do.
49  
50      // Check to see if the authString changed if yes, the a new user.
51      if(this.authString == null || this.authString.equals(authString) == false) {
52        this.authString = authString;
53  
54        // Decode the authString
55        decode();
56      }
57    }
58  
59    public boolean isLoggedIn() {
60      return(authString != null);
61    }
62  
63    /**
64     * Environment specific way of asking for password using the HTTP protocol.
65     */
66    public abstract void askForPassword(String message);
67  
68    public void decode() {
69      String userInfo = authString.substring(6).trim();
70      BASE64Decoder decoder = new BASE64Decoder();
71  
72      String nameAndPassword = "undecoded:FAILURE";
73      try {
74        nameAndPassword = new String(decoder.decodeBuffer(userInfo));
75      }
76      catch(IOException e) {}
77      
78      int index = nameAndPassword.indexOf(":");
79  
80      user = nameAndPassword.substring(0, index);
81      password = nameAndPassword.substring(index +1);
82  
83    }
84  
85    public String getUser() {
86      return(user);
87    }
88  
89    public String getPassword() {
90      return(password);
91    }
92  
93    /**
94     * Test function for Authentication
95     * @param args command line arguments
96     */
97    public static void main(String [] args) {
98    }
99  
100 } /* END OF: Authentication */