1 7 8 package java.net; 9 10 39 40 public abstract 43 class Authenticator { 44 45 private static Authenticator theAuthenticator; 47 48 private String requestingHost; 49 private InetAddress requestingSite; 50 private int requestingPort; 51 private String requestingProtocol; 52 private String requestingPrompt; 53 private String requestingScheme; 54 private URL requestingURL; 55 private RequestorType requestingAuthType; 56 57 62 public enum RequestorType { 63 66 PROXY, 67 70 SERVER 71 } 72 73 private void reset() { 74 requestingHost = null; 75 requestingSite = null; 76 requestingPort = -1; 77 requestingProtocol = null; 78 requestingPrompt = null; 79 requestingScheme = null; 80 requestingURL = null; 81 requestingAuthType = RequestorType.SERVER; 82 } 83 84 85 105 public synchronized static void setDefault(Authenticator a) { 106 SecurityManager sm = System.getSecurityManager(); 107 if (sm != null) { 108 NetPermission setDefaultPermission 109 = new NetPermission ("setDefaultAuthenticator"); 110 sm.checkPermission(setDefaultPermission); 111 } 112 113 theAuthenticator = a; 114 } 115 116 143 public static PasswordAuthentication requestPasswordAuthentication( 144 InetAddress addr, 145 int port, 146 String protocol, 147 String prompt, 148 String scheme) { 149 150 SecurityManager sm = System.getSecurityManager(); 151 if (sm != null) { 152 NetPermission requestPermission 153 = new NetPermission ("requestPasswordAuthentication"); 154 sm.checkPermission(requestPermission); 155 } 156 157 Authenticator a = theAuthenticator; 158 if (a == null) { 159 return null; 160 } else { 161 synchronized(a) { 162 a.reset(); 163 a.requestingSite = addr; 164 a.requestingPort = port; 165 a.requestingProtocol = protocol; 166 a.requestingPrompt = prompt; 167 a.requestingScheme = scheme; 168 return a.getPasswordAuthentication(); 169 } 170 } 171 } 172 173 204 public static PasswordAuthentication requestPasswordAuthentication( 205 String host, 206 InetAddress addr, 207 int port, 208 String protocol, 209 String prompt, 210 String scheme) { 211 212 SecurityManager sm = System.getSecurityManager(); 213 if (sm != null) { 214 NetPermission requestPermission 215 = new NetPermission ("requestPasswordAuthentication"); 216 sm.checkPermission(requestPermission); 217 } 218 219 Authenticator a = theAuthenticator; 220 if (a == null) { 221 return null; 222 } else { 223 synchronized(a) { 224 a.reset(); 225 a.requestingHost = host; 226 a.requestingSite = addr; 227 a.requestingPort = port; 228 a.requestingProtocol = protocol; 229 a.requestingPrompt = prompt; 230 a.requestingScheme = scheme; 231 return a.getPasswordAuthentication(); 232 } 233 } 234 } 235 236 269 public static PasswordAuthentication requestPasswordAuthentication( 270 String host, 271 InetAddress addr, 272 int port, 273 String protocol, 274 String prompt, 275 String scheme, 276 URL url, 277 RequestorType reqType) { 278 279 SecurityManager sm = System.getSecurityManager(); 280 if (sm != null) { 281 NetPermission requestPermission 282 = new NetPermission ("requestPasswordAuthentication"); 283 sm.checkPermission(requestPermission); 284 } 285 286 Authenticator a = theAuthenticator; 287 if (a == null) { 288 return null; 289 } else { 290 synchronized(a) { 291 a.reset(); 292 a.requestingHost = host; 293 a.requestingSite = addr; 294 a.requestingPort = port; 295 a.requestingProtocol = protocol; 296 a.requestingPrompt = prompt; 297 a.requestingScheme = scheme; 298 a.requestingURL = url; 299 a.requestingAuthType = reqType; 300 return a.getPasswordAuthentication(); 301 } 302 } 303 } 304 305 314 protected final String getRequestingHost() { 315 return requestingHost; 316 } 317 318 326 protected final InetAddress getRequestingSite() { 327 return requestingSite; 328 } 329 330 335 protected final int getRequestingPort() { 336 return requestingPort; 337 } 338 339 349 protected final String getRequestingProtocol() { 350 return requestingProtocol; 351 } 352 353 359 protected final String getRequestingPrompt() { 360 return requestingPrompt; 361 } 362 363 370 protected final String getRequestingScheme() { 371 return requestingScheme; 372 } 373 374 380 protected PasswordAuthentication getPasswordAuthentication() { 381 return null; 382 } 383 384 393 protected URL getRequestingURL () { 394 return requestingURL; 395 } 396 397 405 protected RequestorType getRequestorType () { 406 return requestingAuthType; 407 } 408 } 409 410 411 412 413 414 415 | Popular Tags |