KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > net > auth > NetAuthenticator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.net.auth;
12
13 import java.net.*;
14
15 public class NetAuthenticator extends Authenticator {
16     
17     /*
18      * @see Authenticator#getPasswordAuthentication()
19      */

20     protected PasswordAuthentication getPasswordAuthentication() {
21         // String protocol = getRequestingProtocol();
22
InetAddress address = getRequestingSite(); // can be null;
23
// int port = getRequestingPort();
24
String JavaDoc prompt = getRequestingPrompt(); // realm or message, not documented that can be null
25
// String scheme = getRequestingScheme(); // not documented that can be null
26

27          // get the host name from the address since #getRequestingHost
28
// is not available in the foundation 1.0 class libraries
29
String JavaDoc hostString = null;
30         if (address != null) {
31             hostString = address.getHostName();
32         }
33         if (hostString == null) {
34             hostString = ""; //$NON-NLS-1$
35
}
36         String JavaDoc promptString = prompt;
37         if (prompt == null) {
38             promptString = ""; //$NON-NLS-1$
39
}
40
41         Authentication auth = UserValidationDialog.getAuthentication(
42                 hostString, promptString);
43         if (auth != null)
44             return new PasswordAuthentication(auth.getUser(), auth
45                     .getPassword().toCharArray());
46         else
47             return null;
48     }
49 }
50
Popular Tags