KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > http > HttpAuthenticator


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.http;
21
22 import java.io.IOException JavaDoc;
23
24 /**
25  *
26  * @author Lee David Painter <a HREF="mailto:lee@3sp.com">&lt;lee@3sp.com&gt;</a>
27  */

28 public abstract class HttpAuthenticator {
29
30     protected PasswordCredentials credentials;
31     protected String JavaDoc authorizationHeader;
32     protected String JavaDoc authenticationHeader;
33     protected HttpConnection connection;
34     protected boolean hasCompleted = false;
35     protected String JavaDoc scheme;
36     protected String JavaDoc uri;
37     protected String JavaDoc host;
38     protected int port;
39     protected boolean secure;
40
41     public static final int AUTHENTICATION_FAILED = 1;
42     public static final int AUTHENTICATION_IN_PROGRESS = 2;
43     public static final int AUTHENTICATION_COMPLETED = 3;
44
45     public HttpAuthenticator(String JavaDoc scheme, String JavaDoc uri, String JavaDoc host, int port, boolean secure) {
46         this.scheme = scheme;
47         this.uri = uri;
48         this.host = host;
49         this.port = port;
50         this.secure = secure;
51     }
52     
53     public abstract String JavaDoc getInformation();
54     
55     public boolean isSecure() {
56         return secure;
57     }
58
59     public String JavaDoc getHost() {
60         return host;
61     }
62
63     public int getPort() {
64         return port;
65     }
66     
67     public String JavaDoc getScheme() {
68         return scheme;
69     }
70
71     public void setURI(String JavaDoc uri) {
72         this.uri = uri;
73     }
74
75     public String JavaDoc getURI() {
76         return uri;
77     }
78
79     public abstract boolean isStateless();
80
81     public String JavaDoc getAuthorizationHeader() {
82         return authorizationHeader;
83     }
84
85     public void setConnection(HttpConnection connection) {
86         this.connection = connection;
87     }
88
89     public void setAuthenicationHeader(String JavaDoc authenticationHeader) {
90         this.authenticationHeader = authenticationHeader;
91     }
92
93     public void setAuthorizationHeader(String JavaDoc authorizationHeader) {
94         this.authorizationHeader = authorizationHeader;
95     }
96
97     public abstract void setChallenge(String JavaDoc challenge);
98
99     public void setCredentials(PasswordCredentials credentials) {
100         this.credentials = credentials;
101     }
102
103     public abstract void authenticate(HttpRequest request, HttpMethod method) throws IOException JavaDoc;
104
105     public abstract int processResponse(HttpResponse response);
106
107     public boolean canAuthenticate() {
108         return true;
109     }
110
111     void complete() {
112         hasCompleted = true;
113     }
114
115     public boolean wantsPrompt() {
116         return !hasCompleted;
117     }
118
119 }
120
Popular Tags