1 19 20 package com.maverick.http; 21 22 import java.io.IOException ; 23 24 28 public abstract class HttpAuthenticator { 29 30 protected PasswordCredentials credentials; 31 protected String authorizationHeader; 32 protected String authenticationHeader; 33 protected HttpConnection connection; 34 protected boolean hasCompleted = false; 35 protected String scheme; 36 protected String uri; 37 protected String 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 scheme, String uri, String 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 getInformation(); 54 55 public boolean isSecure() { 56 return secure; 57 } 58 59 public String getHost() { 60 return host; 61 } 62 63 public int getPort() { 64 return port; 65 } 66 67 public String getScheme() { 68 return scheme; 69 } 70 71 public void setURI(String uri) { 72 this.uri = uri; 73 } 74 75 public String getURI() { 76 return uri; 77 } 78 79 public abstract boolean isStateless(); 80 81 public String getAuthorizationHeader() { 82 return authorizationHeader; 83 } 84 85 public void setConnection(HttpConnection connection) { 86 this.connection = connection; 87 } 88 89 public void setAuthenicationHeader(String authenticationHeader) { 90 this.authenticationHeader = authenticationHeader; 91 } 92 93 public void setAuthorizationHeader(String authorizationHeader) { 94 this.authorizationHeader = authorizationHeader; 95 } 96 97 public abstract void setChallenge(String 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 ; 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 |