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 |
} |