KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > security > UpdateManagerAuthenticator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.update.internal.ui.security;
12
13 import java.net.*;
14
15 /**
16  * Update Manager Authenticator Sadly there can only be one registered per VM
17  */

18 public class UpdateManagerAuthenticator extends Authenticator {
19     //private Authentication savedPasswordAuthentication;
20

21     /*
22      * @see Authenticator#getPasswordAuthentication()
23      */

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

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