### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.net Index: src/org/eclipse/ui/internal/net/Activator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/Activator.java,v retrieving revision 1.2 diff -u -r1.2 Activator.java --- src/org/eclipse/ui/internal/net/Activator.java 20 Nov 2008 15:50:07 -0000 1.2 +++ src/org/eclipse/ui/internal/net/Activator.java 15 May 2010 06:35:45 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,8 +13,16 @@ *******************************************************************************/ package org.eclipse.ui.internal.net; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.eclipse.core.net.proxy.IProxyData; +import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; /** * The activator class controls the plug-in life cycle @@ -27,6 +35,9 @@ // The shared instance private static Activator plugin; + // The bundle context + private BundleContext context; + /** * The constructor */ @@ -44,12 +55,41 @@ } public void start(BundleContext context) throws Exception { - super.start(context); + super.start(context); + this.context = context; } public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); + context = null; } + public PasswordAuthentication getProxyPasswordAuthentication(URL url) { + if (context == null || url == null) { + return null; + } + + ServiceReference proxyServiceReference = context.getServiceReference(IProxyService.class.getName()); + IProxyService proxyService = (IProxyService) context.getService(proxyServiceReference); + IProxyData[] proxyDatas = null; + try { + URI uri = url.toURI(); + proxyDatas = proxyService.select(uri); + } + catch (URISyntaxException e) { + // Nothing to do. + } + context.ungetService(proxyServiceReference); + + if (proxyDatas != null && proxyDatas.length > 0) { + IProxyData proxyData = proxyDatas[0]; + if (proxyData.isRequiresAuthentication()) { + String userName = proxyData.getUserId(); + String password = proxyData.getPassword(); + return new PasswordAuthentication(userName, password.toCharArray()); + } + } + return null; + } } Index: src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.net/src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java,v retrieving revision 1.1 diff -u -r1.1 NetAuthenticator.java --- src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java 26 Feb 2007 18:16:44 -0000 1.1 +++ src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java 15 May 2010 06:35:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,12 @@ *******************************************************************************/ package org.eclipse.ui.internal.net.auth; -import java.net.*; +import java.net.Authenticator; +import java.net.InetAddress; +import java.net.PasswordAuthentication; +import java.net.URL; + +import org.eclipse.ui.internal.net.Activator; public class NetAuthenticator extends Authenticator { @@ -18,7 +23,16 @@ * @see Authenticator#getPasswordAuthentication() */ protected PasswordAuthentication getPasswordAuthentication() { - // String protocol = getRequestingProtocol(); + RequestorType requestorType = getRequestorType(); + if (requestorType == RequestorType.PROXY) { + URL url = getRequestingURL(); + PasswordAuthentication passwordAuthentication = Activator.getDefault().getProxyPasswordAuthentication(url); + if (passwordAuthentication != null) { + return passwordAuthentication; + } + } + + // String protocol = getRequestingProtocol(); InetAddress address = getRequestingSite(); // can be null; // int port = getRequestingPort(); String prompt = getRequestingPrompt(); // realm or message, not documented that can be null