View | Details | Raw Unified | Return to bug 286631 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/net/Activator.java (-2 / +42 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-20 Link Here
13
 *******************************************************************************/
13
 *******************************************************************************/
14
package org.eclipse.ui.internal.net;
14
package org.eclipse.ui.internal.net;
15
15
16
import java.net.PasswordAuthentication;
17
import java.net.URI;
18
import java.net.URISyntaxException;
19
import java.net.URL;
20
21
import org.eclipse.core.net.proxy.IProxyData;
22
import org.eclipse.core.net.proxy.IProxyService;
16
import org.eclipse.ui.plugin.AbstractUIPlugin;
23
import org.eclipse.ui.plugin.AbstractUIPlugin;
17
import org.osgi.framework.BundleContext;
24
import org.osgi.framework.BundleContext;
25
import org.osgi.framework.ServiceReference;
18
26
19
/**
27
/**
20
 * The activator class controls the plug-in life cycle
28
 * The activator class controls the plug-in life cycle
Lines 27-32 Link Here
27
	// The shared instance
35
	// The shared instance
28
	private static Activator plugin;
36
	private static Activator plugin;
29
37
38
	// The bundle context
39
	private BundleContext context;
40
30
	/**
41
	/**
31
	 * The constructor
42
	 * The constructor
32
	 */
43
	 */
Lines 44-55 Link Here
44
	}
55
	}
45
56
46
	public void start(BundleContext context) throws Exception {
57
	public void start(BundleContext context) throws Exception {
47
		super.start(context);
58
	  super.start(context);
59
	  this.context = context;
48
	}
60
	}
49
61
50
	public void stop(BundleContext context) throws Exception {
62
	public void stop(BundleContext context) throws Exception {
51
		plugin = null;
63
		plugin = null;
52
		super.stop(context);
64
		super.stop(context);
65
		context = null;
53
	}
66
	}
54
67
68
	public PasswordAuthentication getProxyPasswordAuthentication(URL url) {
69
	  if (context == null || url == null) {
70
	    return null;
71
	  }
72
73
	  ServiceReference proxyServiceReference = context.getServiceReference(IProxyService.class.getName());
74
	  IProxyService proxyService = (IProxyService) context.getService(proxyServiceReference);
75
	  IProxyData[] proxyDatas = null;
76
	  try {
77
	    URI uri = url.toURI();
78
	    proxyDatas = proxyService.select(uri);
79
	  }
80
	  catch (URISyntaxException e) {
81
	    // Nothing to do.
82
	  }
83
	  context.ungetService(proxyServiceReference);
84
85
	  if (proxyDatas != null && proxyDatas.length > 0) {
86
	    IProxyData proxyData = proxyDatas[0];
87
	    if (proxyData.isRequiresAuthentication()) {
88
	      String userName = proxyData.getUserId();
89
	      String password = proxyData.getPassword();
90
	      return new PasswordAuthentication(userName, password.toCharArray());
91
	    }
92
	  }
93
	  return null;
94
	}
55
}
95
}
(-)src/org/eclipse/ui/internal/net/auth/NetAuthenticator.java (-3 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net.auth;
11
package org.eclipse.ui.internal.net.auth;
12
12
13
import java.net.*;
13
import java.net.Authenticator;
14
import java.net.InetAddress;
15
import java.net.PasswordAuthentication;
16
import java.net.URL;
17
18
import org.eclipse.ui.internal.net.Activator;
14
19
15
public class NetAuthenticator extends Authenticator {
20
public class NetAuthenticator extends Authenticator {
16
	
21
	
Lines 18-24 Link Here
18
	 * @see Authenticator#getPasswordAuthentication()
23
	 * @see Authenticator#getPasswordAuthentication()
19
	 */
24
	 */
20
	protected PasswordAuthentication getPasswordAuthentication() {
25
	protected PasswordAuthentication getPasswordAuthentication() {
21
		// String protocol = getRequestingProtocol();
26
        RequestorType requestorType = getRequestorType();
27
        if (requestorType == RequestorType.PROXY) {
28
          URL url = getRequestingURL();
29
          PasswordAuthentication passwordAuthentication = Activator.getDefault().getProxyPasswordAuthentication(url);
30
          if (passwordAuthentication != null) {
31
            return passwordAuthentication;
32
          }
33
        }
34
35
        // String protocol = getRequestingProtocol();
22
		InetAddress address = getRequestingSite(); // can be null;
36
		InetAddress address = getRequestingSite(); // can be null;
23
		// int port = getRequestingPort();
37
		// int port = getRequestingPort();
24
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null
38
		String prompt = getRequestingPrompt(); // realm or message, not documented that can be null

Return to bug 286631