diff options
75 files changed, 4060 insertions, 485 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java index cb1d33a7..b95aac7a 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java @@ -94,6 +94,21 @@ public class CoreUtil { } /** + * Returns true, if <code>o1</code> is equal to <code>o2</code> or <code>o1</code> and <code>o2</code> are + * <code>null</code>. + * + * @see Object#equals(Object) + * @since 3.7 + */ + public static boolean areEqual(Object o1, Object o2) { + if (o1 == null) { + return (o2 == null); + } else { + return o1.equals(o2); + } + } + + /** * Compares <code>o1</code> and <code>o2</code>. * * @since 3.7 diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java index 7ac54018..578e8605 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/ExtensionPointReader.java @@ -1,4 +1,5 @@ package org.eclipse.mylyn.commons.core; + /******************************************************************************* * Copyright (c) 2011 Tasktop Technologies. * All rights reserved. This program and the accompanying materials @@ -10,7 +11,6 @@ package org.eclipse.mylyn.commons.core; * Tasktop Technologies - initial API and implementation *******************************************************************************/ - import java.util.ArrayList; import java.util.List; @@ -75,10 +75,15 @@ public class ExtensionPointReader<T> { public IStatus read() { items.clear(); - MultiStatus result = new MultiStatus(pluginId, 0, "Extensions failed to load", null); //$NON-NLS-1$ - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = registry.getExtensionPoint(classAttributeId + "." + extensionId); //$NON-NLS-1$ + if (registry == null) { + return Status.CANCEL_STATUS; + } + + MultiStatus result = new MultiStatus(pluginId, 0, NLS.bind( + "Extensions for {0}/{1} failed to load", pluginId, elementId), null); //$NON-NLS-1$ + + IExtensionPoint extensionPoint = registry.getExtensionPoint(pluginId + "." + extensionId); //$NON-NLS-1$ if (extensionPoint != null) { IExtension[] extensions = extensionPoint.getExtensions(); for (IExtension extension : extensions) { @@ -105,6 +110,10 @@ public class ExtensionPointReader<T> { } } + public T getItem() { + return (items.isEmpty()) ? null : items.get(0); + } + public List<T> getItems() { return new ArrayList<T>(items); } diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java index bf417ad8..d2d0477d 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java @@ -14,10 +14,13 @@ package org.eclipse.mylyn.commons.core.net; import java.net.Proxy; import java.net.SocketAddress; +import org.eclipse.core.runtime.Assert; + /** * Abstraction for a proxy that supports user authentication. * * @author Rob Elves + * @author Steffen Pingel * @since 3.7 */ public class AuthenticatedProxy extends Proxy { @@ -26,10 +29,19 @@ public class AuthenticatedProxy extends Proxy { private final String password; - public AuthenticatedProxy(Type type, SocketAddress sa, String userName, String password) { + private final String domain; + + public AuthenticatedProxy(Type type, SocketAddress sa, String userName, String password, String domain) { super(type, sa); + Assert.isNotNull(userName); + Assert.isNotNull(password); this.userName = userName; this.password = password; + this.domain = domain; + } + + public AuthenticatedProxy(Type type, SocketAddress sa, String userName, String password) { + this(type, sa, userName, password, null); } public String getUserName() { @@ -40,4 +52,8 @@ public class AuthenticatedProxy extends Proxy { return password; } + public String getDomain() { + return domain; + } + } diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java index 7e8ff89e..ad65ea8c 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java @@ -98,12 +98,16 @@ public class NetUtil { } } - public static Proxy createProxy(String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) { + public static Proxy createProxy(String proxyHost, int proxyPort) { + return createProxy(proxyHost, proxyPort, null, null, null); + } + + public static Proxy createProxy(String proxyHost, int proxyPort, String username, String password, String domain) { if (proxyHost != null && proxyHost.length() > 0) { InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort); - boolean authenticated = (proxyUsername != null && proxyPassword != null && proxyUsername.length() > 0 && proxyPassword.length() > 0); + boolean authenticated = (username != null && password != null && username.length() > 0 && password.length() > 0); if (authenticated) { - return new AuthenticatedProxy(Type.HTTP, sockAddr, proxyUsername, proxyPassword); + return new AuthenticatedProxy(Type.HTTP, sockAddr, username, password, domain); } else { return new Proxy(Type.HTTP, sockAddr); } @@ -199,7 +203,7 @@ public class NetUtil { if (proxyPort == -1) { proxyPort = 0; } - return createProxy(proxyHost, proxyPort, data.getUserId(), data.getPassword()); + return createProxy(proxyHost, proxyPort, data.getUserId(), data.getPassword(), null); } } else { try { diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java index c9bafb24..6288f6a1 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java @@ -21,6 +21,7 @@ import java.util.concurrent.TimeoutException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.mylyn.commons.core.operations.IOperationMonitor.OperationFlag; import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin; import org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor; import org.eclipse.mylyn.internal.commons.core.operations.OperationMonitor; @@ -51,6 +52,19 @@ public class OperationUtil { return new OperationMonitor(null, monitor, taskName, work); } + public static boolean isBackgroundMonitor(IProgressMonitor monitor) { + if (monitor == null) { + return false; + } + if (monitor instanceof IOperationMonitor) { + return ((IOperationMonitor) monitor).hasFlag(OperationFlag.BACKGROUND); + } + if (monitor.getClass().getSimpleName().equals("BackgroundProgressMonitor")) { //$NON-NLS-1$ + return true; + } + return false; + } + /** * @since 3.7 */ diff --git a/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF index 52f6a933..e86b1d12 100644 --- a/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF @@ -5,8 +5,8 @@ Bundle-SymbolicName: org.eclipse.mylyn.commons.repositories.core;singleton:=true Bundle-Version: 0.9.0.qualifier Bundle-Vendor: %Bundle-Vendor Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.eclipse.mylyn.commons.repositories.core;x-internal:=true, - org.eclipse.mylyn.commons.repositories.core.auth;x-internal:=true, +Export-Package: org.eclipse.mylyn.commons.repositories.core;x-friends:="org.eclipse.mylyn.commons.repositories.ui", + org.eclipse.mylyn.commons.repositories.core.auth;x-friends:="org.eclipse.mylyn.commons.repositories.ui", org.eclipse.mylyn.internal.commons.repositories.core;x-internal:=true Require-Bundle: org.eclipse.core.runtime, org.eclipse.equinox.security, diff --git a/org.eclipse.mylyn.commons.repositories.core/plugin.xml b/org.eclipse.mylyn.commons.repositories.core/plugin.xml new file mode 100644 index 00000000..d163c9b5 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/plugin.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.5"?> +<!-- + Copyright (c) 2012 Tasktop Technologies 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 + http://www.eclipse.org/legal/epl-v10.html + + Contributors: + Tasktop Technologies - initial API and implementation + --> +<plugin> + <extension-point id="locationServices" name="Location Services" schema="schema/locationServices.exsd"/> +</plugin> diff --git a/org.eclipse.mylyn.commons.repositories.core/schema/locationServices.exsd b/org.eclipse.mylyn.commons.repositories.core/schema/locationServices.exsd new file mode 100644 index 00000000..fc00b05d --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/schema/locationServices.exsd @@ -0,0 +1,109 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.mylyn.commons.repositories.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.mylyn.commons.repositories.core" id="locationServices" name="Location Service"/> + </appinfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element internal="true" /> + </appinfo> + </annotation> + <complexType> + <choice> + <element ref="service"/> + </choice> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="service"> + <complexType> + <attribute name="id" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.mylyn.commons.repositories.core.ILocationService"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="implementation"/> + </appinfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/ILocationService.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/ILocationService.java index 4e46163c..a9882123 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/ILocationService.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/ILocationService.java @@ -17,23 +17,26 @@ import javax.net.ssl.X509TrustManager; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; /** + * Provides platform services related that are used by {@link RepositoryLocation} objects. + * * @author Steffen Pingel * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface ILocationService { - // FIXME replace with 3.5 proxy API + // FIXME e3.5 replace with 3.5 proxy API public abstract Proxy getProxyForHost(String host, String proxyType); public abstract X509TrustManager getTrustManager(); - public abstract <T extends AuthenticationCredentials> T requestCredentials(AuthenticationType type, - Class<T> credentialsKind, String message, IProgressMonitor monitor); + public abstract <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> context, IProgressMonitor monitor); public ICredentialsStore getCredentialsStore(String id); diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/IRepositoryLocationChangeListener.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/IRepositoryLocationChangeListener.java new file mode 100644 index 00000000..a89af33b --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/IRepositoryLocationChangeListener.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core; + +/** + * @author Steffen Pingel + */ +public interface IRepositoryLocationChangeListener { + + public abstract void repositoryChanged(RepositoryLocationChangeEvent event); + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java index 89324754..aa8f0466 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java @@ -13,24 +13,37 @@ package org.eclipse.mylyn.commons.repositories.core; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.SocketAddress; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.core.runtime.Status; +import org.eclipse.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.commons.core.net.NetUtil; +import org.eclipse.mylyn.commons.repositories.core.RepositoryLocationChangeEvent.Type; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; import org.eclipse.mylyn.internal.commons.repositories.core.CredentialsFactory; import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore; import org.eclipse.mylyn.internal.commons.repositories.core.LocationService; +import org.eclipse.mylyn.internal.commons.repositories.core.RepositoriesCoreInternal; /** * @author Steffen Pingel @@ -38,48 +51,28 @@ import org.eclipse.mylyn.internal.commons.repositories.core.LocationService; // FIXME add synchronization public class RepositoryLocation extends PlatformObject { - private static final String AUTH_HTTP = "org.eclipse.mylyn.tasklist.repositories.httpauth"; //$NON-NLS-1$ - - private static final String AUTH_PROXY = "org.eclipse.mylyn.tasklist.repositories.proxy"; //$NON-NLS-1$ - - private static final String AUTH_REPOSITORY = "org.eclipse.mylyn.tasklist.repositories"; //$NON-NLS-1$ - - private static final String ENABLED = ".enabled"; //$NON-NLS-1$ - - public static final String PROPERTY_CATEGORY = "category"; //$NON-NLS-1$ - - public static final String PROPERTY_ENCODING = "encoding"; //$NON-NLS-1$ - public static final String PROPERTY_ID = "id"; //$NON-NLS-1$ public static final String PROPERTY_LABEL = "label"; //$NON-NLS-1$ public static final String PROPERTY_OFFLINE = "org.eclipse.mylyn.tasklist.repositories.offline"; //$NON-NLS-1$ - public static final String PROPERTY_TIMEZONE = "timezone"; //$NON-NLS-1$ - - public static final String PROPERTY_URL = "url"; //$NON-NLS-1$ - - public static final String PROPERTY_USERNAME = "org.eclipse.mylyn.repositories.username"; //$NON-NLS-1$ - public static final String PROPERTY_PROXY_HOST = "org.eclipse.mylyn.repositories.proxy.host"; //$NON-NLS-1$ public static final String PROPERTY_PROXY_PORT = "org.eclipse.mylyn.repositories.proxy.port"; //$NON-NLS-1$ public static final String PROPERTY_PROXY_USEDEFAULT = "org.eclipse.mylyn.repositories.proxy.usedefault"; //$NON-NLS-1$ - private static final String SAVE_PASSWORD = ".savePassword"; //$NON-NLS-1$ + public static final String PROPERTY_URL = "url"; //$NON-NLS-1$ - private static String getKeyPrefix(AuthenticationType type) { - switch (type) { - case HTTP: - return AUTH_HTTP; - case PROXY: - return AUTH_PROXY; - case REPOSITORY: - return AUTH_REPOSITORY; - } - throw new IllegalArgumentException("Unknown authentication type: " + type); //$NON-NLS-1$ + public static final String PROPERTY_USERNAME = "org.eclipse.mylyn.repositories.username"; //$NON-NLS-1$ + + private static final String ENABLED = ".enabled"; //$NON-NLS-1$ + + private static Map<String, String> createDefaultProperties() { + Map<String, String> defaultProperties = new HashMap<String, String>(); + defaultProperties.put(PROPERTY_PROXY_USEDEFAULT, Boolean.TRUE.toString()); + return defaultProperties; } private ICredentialsStore credentialsStore; @@ -89,49 +82,104 @@ public class RepositoryLocation extends PlatformObject { private final Map<String, String> properties = new LinkedHashMap<String, String>(); - private final Set<PropertyChangeListener> propertyChangeListeners = new HashSet<PropertyChangeListener>(); + private final List<PropertyChangeListener> propertyChangeListeners = new CopyOnWriteArrayList<PropertyChangeListener>(); + + private final List<IRepositoryLocationChangeListener> repositoryLocationChangeListeners = new CopyOnWriteArrayList<IRepositoryLocationChangeListener>(); private ILocationService service; - private boolean workingCopy; + private final boolean workingCopy; public RepositoryLocation() { - this.properties.put(RepositoryLocation.PROPERTY_ID, UUID.randomUUID().toString()); - this.service = LocationService.getDefault(); + this(createDefaultProperties(), LocationService.getDefault(), false); } public RepositoryLocation(Map<String, String> properties) { + this(properties, LocationService.getDefault(), true); + } + + public RepositoryLocation(Map<String, String> properties, ILocationService service, boolean workingCopy) { this.properties.putAll(properties); - this.workingCopy = true; - this.service = LocationService.getDefault(); + this.service = service; + this.workingCopy = workingCopy; + if (this.properties.get(PROPERTY_ID) == null) { + this.properties.put(RepositoryLocation.PROPERTY_ID, UUID.randomUUID().toString()); + } } public RepositoryLocation(RepositoryLocation source) { - this.properties.putAll(source.properties); - this.workingCopy = true; - this.service = source.getService(); + this(source.getProperties(), source.getService(), true); } - public void addChangeListener(PropertyChangeListener listener) { + public void addPropertyChangeListener(PropertyChangeListener listener) { propertyChangeListeners.add(listener); } + public void apply(RepositoryLocation location) { + String oldId = getProperty(PROPERTY_ID); + ICredentialsStore oldCredentialsStore = null; + if (oldId != null) { + oldCredentialsStore = getCredentialsStore(); + } + + // merge properties + HashSet<String> removed = new HashSet<String>(properties.keySet()); + removed.removeAll(location.properties.keySet()); + for (Map.Entry<String, String> entry : location.properties.entrySet()) { + setProperty(entry.getKey(), entry.getValue()); + } + for (String key : removed) { + setProperty(key, null); + } + + String newId = getProperty(PROPERTY_ID); + if (newId != null) { + // migrate credentials if url has changed + ICredentialsStore newCredentialsStore = getCredentialsStore(); + if (!newId.equals(oldId)) { + if (oldCredentialsStore != null) { + oldCredentialsStore.copyTo(newCredentialsStore); + oldCredentialsStore.clear(); + } + } + + // merge credentials + if (location.getCredentialsStore() instanceof InMemoryCredentialsStore) { + ((InMemoryCredentialsStore) location.getCredentialsStore()).copyTo(newCredentialsStore); + } + + // persist changes + try { + newCredentialsStore.flush(); + } catch (IOException e) { + // ignore + } + } + + fireRepositoryLocationChangeEvent(Type.ALL); + } + public void clearCredentials() { getCredentialsStore().clear(); } - public <T extends AuthenticationCredentials> T getCredentials(AuthenticationType authType, Class<T> credentialsKind) { - String prefix = getKeyPrefix(authType); + public boolean getBooleanPropery(String key) { + String value = getProperty(key); + return value != null && Boolean.parseBoolean(value); + } + + public <T extends AuthenticationCredentials> T getCredentials(AuthenticationType<T> authType) { + return getCredentials(authType, true); + } + + public <T extends AuthenticationCredentials> T getCredentials(AuthenticationType<T> authType, boolean loadSecrets) { + String prefix = authType.getKey(); if (getBooleanPropery(prefix + ENABLED)) { if (getId() == null) { // can't determine location of credentials return null; } - try { - return CredentialsFactory.create(credentialsKind, getCredentialsStore(), prefix); - } catch (StorageException e) { - // FIXME - } + return CredentialsFactory.create(authType.getCredentialsType(), getCredentialsStore(), prefix, loadSecrets); } return null; } @@ -151,14 +199,6 @@ public class RepositoryLocation extends PlatformObject { return id; } - public Map<String, String> getProperties() { - return new LinkedHashMap<String, String>(this.properties); - } - - public String getProperty(String name) { - return this.properties.get(name); - } - /** * @return the URL if the label property is not set */ @@ -171,13 +211,47 @@ public class RepositoryLocation extends PlatformObject { } } - public boolean getSavePassword(AuthenticationType authType) { - return getBooleanPropery(getKeyPrefix(authType) + SAVE_PASSWORD); + public Map<String, String> getProperties() { + return new LinkedHashMap<String, String>(this.properties); } - public boolean getBooleanPropery(String key) { - String value = getProperty(key); - return value != null && Boolean.parseBoolean(value); + public String getProperty(String name) { + return this.properties.get(name); + } + + public Proxy getProxy() { + if (Boolean.parseBoolean(getProperty(PROPERTY_PROXY_USEDEFAULT))) { + return null; + } + + String proxyHost = getProperty(PROPERTY_PROXY_HOST); + String proxyPort = getProperty(PROPERTY_PROXY_PORT); + if (proxyHost != null && proxyHost.length() > 0 && proxyPort != null) { + try { + int proxyPortNum = Integer.parseInt(proxyPort); + UserCredentials credentials = getCredentials(AuthenticationType.PROXY); + if (credentials != null) { + return NetUtil.createProxy(proxyHost, proxyPortNum, credentials.getUserName(), + credentials.getPassword(), credentials.getDomain()); + } else { + return NetUtil.createProxy(proxyHost, proxyPortNum); + } + } catch (NumberFormatException e) { + StatusHandler.log(new Status(IStatus.ERROR, RepositoriesCoreInternal.ID_PLUGIN, 0, + "Error occured while configuring proxy. Invalid port \"" //$NON-NLS-1$ + + proxyPort + "\" specified.", e)); //$NON-NLS-1$ + } + } + return null; + } + + // FIXME e3.5 replace with 3.5 proxy API + public Proxy getProxyForHost(String host, String proxyType) { + Proxy proxy = getProxy(); + if (proxy != null) { + return proxy; + } + return getService().getProxyForHost(host, proxyType); } public ILocationService getService() { @@ -199,30 +273,27 @@ public class RepositoryLocation extends PlatformObject { return getProperty(PROPERTY_USERNAME); } - public void setUserName(String userName) { - setProperty(PROPERTY_USERNAME, userName); + public boolean hasProperty(String name) { + String value = getProperty(name); + return value != null && value.trim().length() > 0; } - private void handlePropertyChange(String key, Object old, Object value) { - if (PROPERTY_ID.equals(key)) { - credentialsStore = null; + /** + * Returns true if a normalized form of <code>url</code> matches the URL of this location. + */ + public boolean hasUrl(String url) { + Assert.isNotNull(url); + String myUrl = getUrl(); + if (myUrl == null) { + return false; } - - PropertyChangeEvent event = new PropertyChangeEvent(this, key, old, value); - for (PropertyChangeListener listener : propertyChangeListeners) { - listener.propertyChange(event); + try { + return new URI(url + "/").normalize().equals(new URI(myUrl + "/").normalize()); //$NON-NLS-1$//$NON-NLS-2$ + } catch (URISyntaxException e) { + return false; } } - private boolean hasChanged(Object oldValue, Object newValue) { - return oldValue != null && !oldValue.equals(newValue) || oldValue == null && newValue != null; - } - - public boolean hasProperty(String name) { - String value = getProperty(name); - return value != null && value.trim().length() > 0; - } - public boolean isOffline() { return Boolean.parseBoolean(getProperty(PROPERTY_OFFLINE)); } @@ -231,33 +302,59 @@ public class RepositoryLocation extends PlatformObject { return workingCopy; } - public void removeChangeListener(PropertyChangeListener listener) { + public void removePropertyChangeListener(PropertyChangeListener listener) { propertyChangeListeners.remove(listener); } + public <T extends AuthenticationCredentials> void removeCredentials(AuthenticationType<T> authType, T credentials) { + String prefix = authType.getKey(); + credentials.clear(getCredentialsStore(), prefix); + } + public void removeProperty(String key) { setProperty(key, null); } - public <T extends AuthenticationCredentials> void setCredentials(AuthenticationType authType, T credentials) { - String prefix = getKeyPrefix(authType); + /** + * Requests credentials. This may block and prompt to enter credentials. + * + * @param request + * the authentication request + * @param monitor + * the progress monitor + * @return the entered credentials + * @see ILocationService#requestCredentials(AuthenticationRequest, IProgressMonitor) + */ + public <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> request, IProgressMonitor monitor) { + return getService().requestCredentials(request, monitor); + } + public <T extends AuthenticationCredentials> void setCredentials(AuthenticationType<T> authType, T credentials) { + String prefix = authType.getKey(); if (credentials == null) { setProperty(prefix + ENABLED, String.valueOf(false)); } else { setProperty(prefix + ENABLED, String.valueOf(true)); - try { - credentials.save(getCredentialsStore(), prefix); - } catch (StorageException e) { - // FIXME - } + credentials.save(getCredentialsStore(), prefix); } + + fireRepositoryLocationChangeEvent(Type.CREDENTIALS); } public void setCredentialsStore(ICredentialsStore credentialsStore) { this.credentialsStore = credentialsStore; } + public void setIdPreservingCredentialsStore(String id) { + Assert.isNotNull(id); + ICredentialsStore store = getCredentialsStore(); + setProperty(RepositoryLocation.PROPERTY_ID, id); + if (this.credentialsStore == null) { + setCredentialsStore(store); + } + } + public void setLabel(String label) { setProperty(PROPERTY_LABEL, label); } @@ -266,12 +363,8 @@ public class RepositoryLocation extends PlatformObject { properties.put(PROPERTY_OFFLINE, String.valueOf(offline)); } - public void setUrl(String url) { - setProperty(PROPERTY_URL, url); - } - public void setProperty(String key, String newValue) { - Assert.isNotNull(key); + validatePropertyChange(key, newValue); String oldValue = this.properties.get(key); if (hasChanged(oldValue, newValue)) { this.properties.put(key.intern(), (newValue != null) ? newValue.intern() : null); @@ -279,6 +372,30 @@ public class RepositoryLocation extends PlatformObject { } } + public void validatePropertyChange(String key, String newValue) { + Assert.isNotNull(key); + if (key.equals(RepositoryLocation.PROPERTY_ID) && newValue == null) { + throw new IllegalArgumentException("The ID property must not be null"); //$NON-NLS-1$ + } + } + + public void setProxy(Proxy proxy) { + if (proxy == null) { + setProperty(PROPERTY_PROXY_USEDEFAULT, Boolean.toString(true)); + } else { + SocketAddress address = proxy.address(); + if (address instanceof InetSocketAddress) { + setProperty(PROPERTY_PROXY_HOST, ((InetSocketAddress) address).getHostName()); + setProperty(PROPERTY_PROXY_PORT, Integer.toString(((InetSocketAddress) address).getPort())); + setProperty(PROPERTY_PROXY_USEDEFAULT, Boolean.toString(false)); + } else { + throw new IllegalArgumentException("Invalid proxy address"); //$NON-NLS-1$ + } + } + + fireRepositoryLocationChangeEvent(Type.PROYX); + } + public void setService(ILocationService service) { this.service = service; } @@ -287,77 +404,43 @@ public class RepositoryLocation extends PlatformObject { this.errorStatus = errorStatus; } + public void setUrl(String url) { + setProperty(PROPERTY_URL, url); + } + + public void setUserName(String userName) { + setProperty(PROPERTY_USERNAME, userName); + } + @Override public String toString() { return getLabel(); } - public void apply(RepositoryLocation location) { - String oldId = getProperty(PROPERTY_ID); - ICredentialsStore oldCredentialsStore = null; - if (oldId != null) { - oldCredentialsStore = getCredentialsStore(); - } - - // merge properties - HashSet<String> removed = new HashSet<String>(properties.keySet()); - removed.removeAll(location.properties.keySet()); - for (Map.Entry<String, String> entry : location.properties.entrySet()) { - setProperty(entry.getKey(), entry.getValue()); - } - for (String key : removed) { - setProperty(key, null); + private void handlePropertyChange(String key, Object old, Object value) { + if (PROPERTY_ID.equals(key)) { + credentialsStore = null; } - String newId = getProperty(PROPERTY_ID); - if (newId != null) { - // migrate credentials if url has changed - ICredentialsStore newCredentialsStore = getCredentialsStore(); - if (!newId.equals(oldId)) { - if (oldCredentialsStore != null) { - try { - oldCredentialsStore.copyTo(newCredentialsStore); - oldCredentialsStore.clear(); - } catch (StorageException e) { - // FIXME - } - } - } + firePropertyChangeEvent(key, old, value); + } - // merge credentials - if (location.getCredentialsStore() instanceof InMemoryCredentialsStore) { - try { - ((InMemoryCredentialsStore) location.getCredentialsStore()).copyTo(newCredentialsStore); - } catch (StorageException e) { - // FIXME - } - } + private void firePropertyChangeEvent(String key, Object old, Object value) { + PropertyChangeEvent event = new PropertyChangeEvent(this, key, old, value); + for (PropertyChangeListener listener : propertyChangeListeners) { + listener.propertyChange(event); } - } - public void setIdPreservingCredentialsStore(String id) { - ICredentialsStore store = getCredentialsStore(); - setProperty(RepositoryLocation.PROPERTY_ID, id); - if (this.credentialsStore == null) { - setCredentialsStore(store); + private void fireRepositoryLocationChangeEvent(RepositoryLocationChangeEvent.Type type) { + RepositoryLocationChangeEvent event = new RepositoryLocationChangeEvent(this, type); + for (IRepositoryLocationChangeListener listener : repositoryLocationChangeListeners) { + listener.repositoryChanged(event); } } - /** - * Returns true if a normalized form of <code>url</code> matches the URL of this location. - */ - public boolean hasUrl(String url) { - Assert.isNotNull(url); - String myUrl = getUrl(); - if (myUrl == null) { - return false; - } - try { - return new URI(url + "/").normalize().equals(new URI(myUrl + "/").normalize()); //$NON-NLS-1$//$NON-NLS-2$ - } catch (URISyntaxException e) { - return false; - } + private boolean hasChanged(Object oldValue, Object newValue) { + return oldValue != null && !oldValue.equals(newValue) || oldValue == null && newValue != null; } } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocationChangeEvent.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocationChangeEvent.java new file mode 100644 index 00000000..d589927f --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocationChangeEvent.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core; + +import java.util.EventObject; + +import org.eclipse.core.runtime.Assert; + +/** + * @author Steffen Pingel + */ +public class RepositoryLocationChangeEvent extends EventObject { + + public enum Type { + ALL, CREDENTIALS, PROYX + }; + + private static final long serialVersionUID = -8177578930986469693L; + + private final Type type; + + public RepositoryLocationChangeEvent(RepositoryLocation source, Type type) { + super(source); + this.type = type; + Assert.isNotNull(source); + } + + @Override + public RepositoryLocation getSource() { + return (RepositoryLocation) super.getSource(); + } + + public Type getType() { + return type; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationCredentials.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationCredentials.java index 0caaf92e..e7f5bf3d 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationCredentials.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationCredentials.java @@ -11,13 +11,13 @@ package org.eclipse.mylyn.commons.repositories.core.auth; -import org.eclipse.equinox.security.storage.StorageException; - /** * @author Steffen Pingel */ public abstract class AuthenticationCredentials { - public abstract void save(ICredentialsStore store, String prefix) throws StorageException; + public abstract void clear(ICredentialsStore store, String prefix); + + public abstract void save(ICredentialsStore store, String prefix); } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java new file mode 100644 index 00000000..01b150e8 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationException.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import java.io.IOException; + +import org.eclipse.core.runtime.Assert; + +/** + * @author Steffen Pingel + */ +public class AuthenticationException extends IOException { + + private static final long serialVersionUID = 1L; + + private final AuthenticationRequest<?> request; + + public AuthenticationException(String message, AuthenticationRequest<?> request) { + super(message); + Assert.isNotNull(request); + this.request = request; + } + + public AuthenticationException(AuthenticationRequest<?> request) { + this(null, request); + } + + public AuthenticationRequest<?> getRequest() { + return request; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java new file mode 100644 index 00000000..f286169b --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationRequest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; + +/** + * @author Steffen Pingel + */ +public class AuthenticationRequest<T extends AuthenticationType<?>> { + + private final T authenticationType; + + private final RepositoryLocation location; + + public AuthenticationRequest(RepositoryLocation location, T authenticationType) { + Assert.isNotNull(location); + Assert.isNotNull(authenticationType); + this.location = location; + this.authenticationType = authenticationType; + } + + public T getAuthenticationType() { + return authenticationType; + } + + public RepositoryLocation getLocation() { + return location; + } + + public String getMessage() { + return null; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationType.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationType.java index f503e79e..f073c87b 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationType.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/AuthenticationType.java @@ -11,19 +11,56 @@ package org.eclipse.mylyn.commons.repositories.core.auth; +import org.eclipse.core.runtime.Assert; + /** * An enum of supported authentication types. * * @author Steffen Pingel */ -public enum AuthenticationType { +public class AuthenticationType<T extends AuthenticationCredentials> { + /** - * HTTP authentication, this is typically basic authentication but other methods such as digest or NTLM are used as + * Certificate authentication. + */ + public static final AuthenticationType<CertificateCredentials> CERTIFICATE = new AuthenticationType<CertificateCredentials>( + CertificateCredentials.class, "org.eclipse.mylyn.commons.repositories.core.auth.certficate"); //$NON-NLS-1$ + + /** + * HTTP authentication, this is often basic authentication but other methods such as digest or NTLM are used as * well. */ - HTTP, + public static final AuthenticationType<UserCredentials> HTTP = new AuthenticationType<UserCredentials>( + UserCredentials.class, "org.eclipse.mylyn.tasklist.repositories.httpauth"); //$NON-NLS-1$ + + public static final AuthenticationType<OpenIdCredentials> OPENID = new AuthenticationType<OpenIdCredentials>( + OpenIdCredentials.class, "org.eclipse.mylyn.commons.repositories.core.auth.openid"); //$NON-NLS-1$ + /** Proxy authentication. */ - PROXY, - /** Task repository authentication. */ - REPOSITORY + public static final AuthenticationType<UserCredentials> PROXY = new AuthenticationType<UserCredentials>( + UserCredentials.class, "org.eclipse.mylyn.tasklist.repositories.proxy"); //$NON-NLS-1$ + + /** Repository authentication. */ + public static final AuthenticationType<UserCredentials> REPOSITORY = new AuthenticationType<UserCredentials>( + UserCredentials.class, "org.eclipse.mylyn.tasklist.repositories"); //$NON-NLS-1$ + + private final Class<T> credentialsType; + + private final String key; + + public AuthenticationType(Class<T> credentialsType, String key) { + Assert.isNotNull(credentialsType); + Assert.isNotNull(key); + this.credentialsType = credentialsType; + this.key = key; + } + + public Class<T> getCredentialsType() { + return credentialsType; + } + + public String getKey() { + return key; + } + }
\ No newline at end of file diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/CertificateCredentials.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/CertificateCredentials.java new file mode 100644 index 00000000..27c78031 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/CertificateCredentials.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.equinox.security.storage.StorageException; + +/** + * @author Steffen Pingel + */ +public class CertificateCredentials extends AuthenticationCredentials { + + private final String keyStoreFileName; + + private final String password; + + public CertificateCredentials(String keyStoreFileName, String password) { + Assert.isNotNull(password); + this.keyStoreFileName = keyStoreFileName; + this.password = password; + } + + protected CertificateCredentials(ICredentialsStore store, String prefix, boolean loadSecrets) + throws StorageException { + this(store.get(prefix + ".keyStoreFileName", null), (loadSecrets) ? store.get(prefix + ".password", "") : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + CertificateCredentials other = (CertificateCredentials) obj; + if (keyStoreFileName == null) { + if (other.keyStoreFileName != null) { + return false; + } + } else if (!keyStoreFileName.equals(other.keyStoreFileName)) { + return false; + } + if (password == null) { + if (other.password != null) { + return false; + } + } else if (!password.equals(other.password)) { + return false; + } + return true; + } + + public String getKeyStoreFileName() { + return keyStoreFileName; + } + + public String getPassword() { + return password; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((keyStoreFileName == null) ? 0 : keyStoreFileName.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + return result; + } + + @Override + public void clear(ICredentialsStore store, String prefix) { + store.remove(prefix + ".keyStoreFileName"); //$NON-NLS-1$ + store.remove(prefix + ".password"); //$NON-NLS-1$ + } + + @Override + public void save(ICredentialsStore store, String prefix) { + store.put(prefix + ".keyStoreFileName", keyStoreFileName, false); //$NON-NLS-1$ + store.put(prefix + ".password", password, true); //$NON-NLS-1$ + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CertificateCredentials [keyStoreFileName="); //$NON-NLS-1$ + builder.append(keyStoreFileName); + builder.append(", password="); //$NON-NLS-1$ + builder.append((password == null) ? password : "********"); //$NON-NLS-1$ + builder.append("]"); //$NON-NLS-1$ + return builder.toString(); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/ICredentialsStore.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/ICredentialsStore.java index 2ec8c9de..fea9f108 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/ICredentialsStore.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/ICredentialsStore.java @@ -13,8 +13,6 @@ package org.eclipse.mylyn.commons.repositories.core.auth; import java.io.IOException; -import org.eclipse.equinox.security.storage.StorageException; - /** * @author Steffen Pingel * @noextend This interface is not intended to be extended by clients. @@ -26,18 +24,24 @@ public interface ICredentialsStore { public void flush() throws IOException; - public String get(String key, String def) throws StorageException; + public String get(String key, String def); + + public boolean getBoolean(String key, boolean def); - public byte[] getByteArray(String key, byte[] def) throws StorageException; + public byte[] getByteArray(String key, byte[] def); public String[] keys(); - public void put(String key, String value, boolean encrypt) throws StorageException; + public void put(String key, String value, boolean encrypt); + + public void put(String key, String value, boolean encrypt, boolean persist); + + public void putBoolean(String key, boolean value, boolean encrypt); - public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException; + public void putByteArray(String key, byte[] value, boolean encrypt); public void remove(String key); - public void copyTo(ICredentialsStore target) throws StorageException; + public void copyTo(ICredentialsStore target); } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdAuthenticationRequest.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdAuthenticationRequest.java new file mode 100644 index 00000000..253547f9 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdAuthenticationRequest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2011 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import java.util.Map; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; + +/** + * @author Steffen Pingel + */ +public class OpenIdAuthenticationRequest extends AuthenticationRequest<AuthenticationType<OpenIdCredentials>> { + + private String alternateUrl; + + private final Map<String, String> providerArgs; + + private final String requestUrl; + + private final String returnUrl; + + private String cookie; + + private String cookieUrl; + + public OpenIdAuthenticationRequest(RepositoryLocation location, + AuthenticationType<OpenIdCredentials> authenticationType, String requestUrl, + Map<String, String> providerArgs, String returnUrl) { + super(location, authenticationType); + Assert.isNotNull(requestUrl); + Assert.isNotNull(providerArgs); + Assert.isNotNull(returnUrl); + this.requestUrl = requestUrl; + this.providerArgs = providerArgs; + this.returnUrl = returnUrl; + } + + public String getAlternateUrl() { + return alternateUrl; + } + + public Map<String, String> getProviderArgs() { + return providerArgs; + } + + public String getRequestUrl() { + return requestUrl; + } + + /** + * Alternate URL in case the browser does not support POST requests. + */ + public void setAlternateUrl(String alternateUrl) { + this.alternateUrl = alternateUrl; + } + + public String getReturnUrl() { + return returnUrl; + } + + public void setCookie(String cookie) { + this.cookie = cookie; + } + + public void setCookieUrl(String cookieUrl) { + this.cookieUrl = cookieUrl; + } + + public String getCookie() { + return cookie; + } + + public String getCookieUrl() { + return cookieUrl; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdCredentials.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdCredentials.java new file mode 100644 index 00000000..15b9d50a --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/OpenIdCredentials.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +/** + * @author Steffen Pingel + */ +public class OpenIdCredentials extends AuthenticationCredentials { + + private final String responseUrl; + + private final String token; + + public OpenIdCredentials(String responseUrl, String token) { + this.responseUrl = responseUrl; + this.token = token; + } + + protected OpenIdCredentials(ICredentialsStore store, String prefix, boolean loadSecrets) { + this(store.get(prefix + ".responseUrl", null), store.get(prefix + ".token", null)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + OpenIdCredentials other = (OpenIdCredentials) obj; + if (responseUrl == null) { + if (other.responseUrl != null) { + return false; + } + } else if (!responseUrl.equals(other.responseUrl)) { + return false; + } + if (token == null) { + if (other.token != null) { + return false; + } + } else if (!token.equals(other.token)) { + return false; + } + return true; + } + + public String getResponseUrl() { + return responseUrl; + } + + public String getToken() { + return token; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((responseUrl == null) ? 0 : responseUrl.hashCode()); + result = prime * result + ((token == null) ? 0 : token.hashCode()); + return result; + } + + @Override + public void clear(ICredentialsStore store, String prefix) { + store.remove(prefix + ".responseUrl"); //$NON-NLS-1$ + store.remove(prefix + ".token"); //$NON-NLS-1$ + } + + @Override + public void save(ICredentialsStore store, String prefix) { + store.put(prefix + ".responseUrl", responseUrl, true); //$NON-NLS-1$ + store.put(prefix + ".token", token, true); //$NON-NLS-1$ + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("OpenIdCredentials [responseUrl="); //$NON-NLS-1$ + builder.append(responseUrl); + builder.append(", token="); //$NON-NLS-1$ + builder.append(token); + builder.append("]"); //$NON-NLS-1$ + return builder.toString(); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserAuthenticationRequest.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserAuthenticationRequest.java new file mode 100644 index 00000000..dba047e6 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserAuthenticationRequest.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; + +/** + * @author Steffen Pingel + */ +public class UserAuthenticationRequest extends AuthenticationRequest<AuthenticationType<UserCredentials>> { + + private final boolean needsDomain; + + public UserAuthenticationRequest(RepositoryLocation location, + AuthenticationType<UserCredentials> authenticationType, boolean needsDomain) { + super(location, authenticationType); + this.needsDomain = needsDomain; + } + + public boolean needsDomain() { + return needsDomain; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserCredentials.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserCredentials.java new file mode 100644 index 00000000..2810eebd --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UserCredentials.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2011 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.core.auth; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.equinox.security.storage.StorageException; + +/** + * Provides a user name and password. + * + * @author Steffen Pingel + */ +public class UserCredentials extends AuthenticationCredentials { + + private final String domain; + + private final String password; + + private final String userName; + + private final boolean savePassword; + + private final boolean hasSecrets; + + /** + * @param userName + * the user name, must not be null + * @param password + * the password, must not be null + */ + public UserCredentials(String userName, String password) { + this(userName, password, null, true, true); + } + + /** + * @param userName + * the user name, must not be null + * @param password + * the password, must not be null + */ + public UserCredentials(String userName, String password, boolean savePassword) { + this(userName, password, null, savePassword, true); + } + + public UserCredentials(String userName, String password, String domain, boolean savePassword) { + this(userName, password, domain, savePassword, true); + } + + public UserCredentials(String userName, String password, String domain, boolean savePassword, boolean hasSecrets) { + Assert.isNotNull(userName); + Assert.isNotNull(password); + this.userName = userName; + this.password = password; + this.domain = domain; + this.savePassword = savePassword; + this.hasSecrets = hasSecrets; + } + + protected UserCredentials(ICredentialsStore store, String prefix, boolean loadSecrets) throws StorageException { + this( + store.get(prefix + ".user", ""), (loadSecrets) ? store.get(prefix + ".password", "") : "", store.get(prefix + ".domain", null), //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + store.getBoolean(prefix + ".savePassword", false), loadSecrets); //$NON-NLS-1$ + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + UserCredentials other = (UserCredentials) obj; + if (domain == null) { + if (other.domain != null) { + return false; + } + } else if (!domain.equals(other.domain)) { + return false; + } + if (password == null) { + if (other.password != null) { + return false; + } + } else if (!password.equals(other.password)) { + return false; + } + if (userName == null) { + if (other.userName != null) { + return false; + } + } else if (!userName.equals(other.userName)) { + return false; + } + return true; + } + + public String getDomain() { + return domain; + } + + public String getPassword() { + return password; + } + + public String getUserName() { + return userName; + } + + public boolean getSavePassword() { + return savePassword; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((domain == null) ? 0 : domain.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((userName == null) ? 0 : userName.hashCode()); + return result; + } + + @Override + public void clear(ICredentialsStore store, String prefix) { + store.remove(prefix + ".user"); //$NON-NLS-1$ + store.remove(prefix + ".password"); //$NON-NLS-1$ + store.remove(prefix + ".domain"); //$NON-NLS-1$ + store.remove(prefix + ".savePassword"); //$NON-NLS-1$ + } + + @Override + public void save(ICredentialsStore store, String prefix) { + store.put(prefix + ".user", userName, false); //$NON-NLS-1$ + if (hasSecrets) { + store.put(prefix + ".password", password, true, savePassword); //$NON-NLS-1$ + } + store.put(prefix + ".domain", domain, false); //$NON-NLS-1$ + store.putBoolean(prefix + ".savePassword", savePassword, false); //$NON-NLS-1$ + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UserCredentials [domain="); //$NON-NLS-1$ + builder.append(domain); + builder.append(", password="); //$NON-NLS-1$ + builder.append((password == null) ? password : "********"); //$NON-NLS-1$ + builder.append(", userName="); //$NON-NLS-1$ + builder.append(userName); + builder.append(", savePassword="); //$NON-NLS-1$ + builder.append(savePassword); + builder.append(", hasSecrets="); //$NON-NLS-1$ + builder.append(hasSecrets); + builder.append("]"); //$NON-NLS-1$ + return builder.toString(); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UsernamePasswordCredentials.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UsernamePasswordCredentials.java deleted file mode 100644 index 46bd75bb..00000000 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/auth/UsernamePasswordCredentials.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 Tasktop Technologies 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.commons.repositories.core.auth; - -import org.eclipse.equinox.security.storage.StorageException; - -/** - * Provides a user name and password. - * - * @author Steffen Pingel - * @noextend This class is not intended to be subclassed by clients. - */ -public class UsernamePasswordCredentials extends AuthenticationCredentials { - - private final String userName; - - private final String password; - - /** - * @param userName - * the user name, must not be null - * @param password - * the password, must not be null - */ - public UsernamePasswordCredentials(String userName, String password) { - if (userName == null) { - throw new IllegalArgumentException(); - } - if (password == null) { - throw new IllegalArgumentException(); - } - - this.userName = userName; - this.password = password; - } - - public String getUserName() { - return userName; - } - - public String getPassword() { - return password; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((password == null) ? 0 : password.hashCode()); - result = prime * result + ((userName == null) ? 0 : userName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final UsernamePasswordCredentials other = (UsernamePasswordCredentials) obj; - if (password == null) { - if (other.password != null) { - return false; - } - } else if (!password.equals(other.password)) { - return false; - } - if (userName == null) { - if (other.userName != null) { - return false; - } - } else if (!userName.equals(other.userName)) { - return false; - } - return true; - } - - public static UsernamePasswordCredentials create(ICredentialsStore store, String prefix) throws StorageException { - String userName = store.get(prefix + ".user", ""); //$NON-NLS-1$ //$NON-NLS-2$ - String password = store.get(prefix + ".password", ""); //$NON-NLS-1$ //$NON-NLS-2$ - return new UsernamePasswordCredentials(userName, password); - } - - @Override - public void save(ICredentialsStore store, String prefix) throws StorageException { - store.put(prefix + ".user", userName, false); //$NON-NLS-1$ - store.put(prefix + ".password", password, true); //$NON-NLS-1$ - } - -} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/CredentialsFactory.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/CredentialsFactory.java index 9850a745..77dc223b 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/CredentialsFactory.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/CredentialsFactory.java @@ -11,10 +11,10 @@ package org.eclipse.mylyn.internal.commons.repositories.core; -import org.eclipse.equinox.security.storage.StorageException; +import java.lang.reflect.Constructor; + import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; -import org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials; /** * Simple factory that creates {@link AuthenticationCredentials} objects. @@ -23,13 +23,16 @@ import org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredenti */ public class CredentialsFactory { - @SuppressWarnings("unchecked") - public static <T extends AuthenticationCredentials> T create(Class<T> credentialsKind, - ICredentialsStore credentialsStore, String key) throws StorageException { - if (credentialsKind == UsernamePasswordCredentials.class) { - return (T) UsernamePasswordCredentials.create(credentialsStore, key); + public static <T extends AuthenticationCredentials> T create(Class<T> credentialsType, + ICredentialsStore credentialsStore, String key, boolean loadSecrets) { + try { + Constructor<T> constructor = credentialsType.getDeclaredConstructor(ICredentialsStore.class, String.class, + boolean.class); + constructor.setAccessible(true); + return constructor.newInstance(credentialsStore, key, loadSecrets); + } catch (Exception e) { + throw new RuntimeException("Unexpected error while creating credentials", e); } - throw new IllegalArgumentException("Unknown credentials type: " + credentialsKind); //$NON-NLS-1$ } } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/InMemoryCredentialsStore.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/InMemoryCredentialsStore.java index 69b53478..6a23b776 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/InMemoryCredentialsStore.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/InMemoryCredentialsStore.java @@ -12,10 +12,14 @@ package org.eclipse.mylyn.internal.commons.repositories.core; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Map.Entry; -import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.core.runtime.Assert; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; /** @@ -23,63 +27,172 @@ import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; */ public class InMemoryCredentialsStore implements ICredentialsStore { - private final ConcurrentHashMap<String, Object> store; + private static class Item { + + boolean encrypted; + + boolean persisted; + + Object value; + + } + + static Map<String, InMemoryCredentialsStore> storeById = new HashMap<String, InMemoryCredentialsStore>(); + + public synchronized static InMemoryCredentialsStore getStore(String id) { + Assert.isNotNull(id); + InMemoryCredentialsStore store = storeById.get(id); + if (store == null) { + store = new InMemoryCredentialsStore(id); + storeById.put(id, store); + } + return store; + } + + private final String id; private final ICredentialsStore parent; + /** + * Protected by <code>this</code>. + */ + private final Map<String, Item> store; + + /** + * Flag that controls if removed values are set to null or if the key is removed. This affects the behavior of + * {@link #copyTo(ICredentialsStore)}. If the flag is set to <code>true</code> removed keys will also be removed in + * target store. + */ + private final boolean keepRemovedKeys; + + public InMemoryCredentialsStore() { + this(null, null, true); + } + public InMemoryCredentialsStore(ICredentialsStore parent) { + this(parent, null, true); + } + + InMemoryCredentialsStore(ICredentialsStore parent, String id, boolean keepRemovedKeys) { this.parent = parent; - store = new ConcurrentHashMap<String, Object>(); + this.id = id; + this.keepRemovedKeys = keepRemovedKeys; + this.store = new HashMap<String, Item>(); + } + + InMemoryCredentialsStore(String id) { + this(null, id, false); } - public void clear() { + public synchronized void clear() { store.clear(); } - public void flush() throws IOException { - // does nothing + public void copyTo(ICredentialsStore target) { + synchronized (target) { + synchronized (this) { + for (Map.Entry<String, Item> entry : store.entrySet()) { + Item item = entry.getValue(); + if (item != null) { + if (item.value instanceof String) { + target.put(entry.getKey(), (String) item.value, item.encrypted, item.persisted); + } else if (item.value instanceof byte[]) { + target.putByteArray(entry.getKey(), (byte[]) item.value, item.encrypted); + } else if (item.value instanceof Boolean) { + target.putBoolean(entry.getKey(), (Boolean) item.value, item.encrypted); + } + } else { + target.remove(entry.getKey()); + } + } + } + } + } + + /** + * Clears removed items. + */ + public synchronized void flush() throws IOException { + for (Iterator<Map.Entry<String, Item>> it = store.entrySet().iterator(); it.hasNext();) { + if (it.next().getValue() == null) { + it.remove(); + } + } } - public String get(String key, String def) throws StorageException { - String value = (String) store.get(key); - if (value == null && parent != null) { + public synchronized String get(String key, String def) { + Item item = store.get(key); + if (item == null && parent != null) { return parent.get(key, def); } - return (value != null) ? value : def; + return (item != null && item.value instanceof String) ? (String) item.value : def; } - public byte[] getByteArray(String key, byte[] def) throws StorageException { - byte[] value = (byte[]) store.get(key); - if (value == null && parent != null) { + public synchronized boolean getBoolean(String key, boolean def) { + Item item = store.get(key); + if (item == null && parent != null) { + return parent.getBoolean(key, def); + } + return (item != null && item.value instanceof Boolean) ? (Boolean) item.value : def; + } + + public synchronized byte[] getByteArray(String key, byte[] def) { + Item item = store.get(key); + if (item == null && parent != null) { return parent.getByteArray(key, def); } - return (value != null) ? value : def; + return (item != null && item.value instanceof byte[]) ? (byte[]) item.value : def; } - public String[] keys() { - return store.keySet().toArray(new String[0]); + public String getId() { + return id; } - public void put(String key, String value, boolean encrypt) throws StorageException { - store.put(key, value); + public synchronized boolean hasKey(String key) { + // store.containsKey(key) would return true for removed items that were set to null + return store.get(key) != null; } - public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException { - store.put(key, value); + public synchronized String[] keys() { + List<String> keys = new ArrayList<String>(store.keySet().size()); + for (Entry<String, Item> entry : store.entrySet()) { + if (entry.getValue() != null) { + keys.add(entry.getKey()); + } + } + return keys.toArray(new String[0]); } - public void remove(String key) { - store.remove(key); + public synchronized void put(String key, String value, boolean encrypt) { + put(key, value, encrypt, true); } - public void copyTo(ICredentialsStore target) throws StorageException { - for (Map.Entry<String, Object> entry : store.entrySet()) { - if (entry.getValue() instanceof String) { - target.put(entry.getKey(), (String) entry.getValue(), true); - } else if (entry.getValue() instanceof byte[]) { - target.putByteArray(entry.getKey(), (byte[]) entry.getValue(), true); - } + public synchronized void put(String key, String value, boolean encrypt, boolean persist) { + store.put(key, createItem(value, encrypt, persist)); + } + + public synchronized void putBoolean(String key, boolean value, boolean encrypt) { + store.put(key, createItem(value, encrypt, true)); + } + + public synchronized void putByteArray(String key, byte[] value, boolean encrypt) { + store.put(key, createItem(value, encrypt, encrypt)); + } + + public synchronized void remove(String key) { + if (keepRemovedKeys) { + store.put(key, null); + } else { + store.remove(key); } } + private Item createItem(Object value, boolean encrypt, boolean persist) { + Item item = new Item(); + item.value = value; + item.encrypted = encrypt; + item.persisted = persist; + return item; + } + } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java index e424be02..844c5ba8 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java @@ -12,29 +12,43 @@ package org.eclipse.mylyn.internal.commons.repositories.core; import java.net.Proxy; -import java.util.HashMap; -import java.util.Map; import javax.net.ssl.X509TrustManager; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.mylyn.commons.core.ExtensionPointReader; +import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.commons.core.net.NetUtil; import org.eclipse.mylyn.commons.core.net.ProxyProvider; import org.eclipse.mylyn.commons.repositories.core.ILocationService; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; -import org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials; /** * @author Steffen Pingel */ public class LocationService implements ILocationService { - private static LocationService instance = new LocationService(); - - public static LocationService getDefault() { - return instance; + private static class LocationServiceInitializer { + private static ILocationService service; + static { + ExtensionPointReader<ILocationService> reader = new ExtensionPointReader<ILocationService>( + RepositoriesCoreInternal.ID_PLUGIN, "locationServices", "service", ILocationService.class); //$NON-NLS-1$ //$NON-NLS-2$ + + IStatus status = reader.read(); + if (!status.isOK()) { + StatusHandler.log(status); + } + + if (reader.getItem() != null) { + service = reader.getItem(); + } else { + service = new LocationService(); + } + } } private static class PlatformProxyProvider extends ProxyProvider { @@ -48,37 +62,22 @@ public class LocationService implements ILocationService { } - private final Map<AuthenticationType, UsernamePasswordCredentials> credentialsByType; + public static ILocationService getDefault() { + return LocationServiceInitializer.service; + } private final ProxyProvider proxyProvider; public LocationService() { - this(null, null, PlatformProxyProvider.INSTANCE); + this(PlatformProxyProvider.INSTANCE); } public LocationService(ProxyProvider proxyProvider) { - this(null, null, proxyProvider); - } - - public LocationService(String username, String password, ProxyProvider proxyProvider) { - this.credentialsByType = new HashMap<AuthenticationType, UsernamePasswordCredentials>(); this.proxyProvider = proxyProvider; - - if (username != null && password != null) { - setCredentials(AuthenticationType.REPOSITORY, username, password); - } } -// public LocationService(String url, String username, String password) { -// this(url, username, password, new PlatformProxyProvider()); -// } -// -// public LocationService(String url) { -// this(url, null, null, new PlatformProxyProvider()); -// } - - public UsernamePasswordCredentials getCredentials(AuthenticationType authType) { - return credentialsByType.get(authType); + public ICredentialsStore getCredentialsStore(String id) { + return InMemoryCredentialsStore.getStore(id); } public Proxy getProxyForHost(String host, String proxyType) { @@ -88,22 +87,13 @@ public class LocationService implements ILocationService { return null; } - public void setCredentials(AuthenticationType authType, String username, String password) { - credentialsByType.put(authType, new UsernamePasswordCredentials(username, password)); - } - public X509TrustManager getTrustManager() { - // ignore - return null; - } - - public <T extends AuthenticationCredentials> T requestCredentials(AuthenticationType type, - Class<T> credentialsKind, String message, IProgressMonitor monitor) { throw new UnsupportedOperationException(); } - public ICredentialsStore getCredentialsStore(String id) { - return new SecureCredentialsStore(id); + public <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> context, IProgressMonitor monitor) { + throw new UnsupportedOperationException(); } } diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/RepositoriesCoreInternal.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/RepositoriesCoreInternal.java new file mode 100644 index 00000000..eed082d5 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/RepositoriesCoreInternal.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.core; + +/** + * @author Steffen Pingel + */ +public class RepositoriesCoreInternal { + + public static final String ID_PLUGIN = "org.eclipse.mylyn.commons.repositories.core"; //$NON-NLS-1$ + +} diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/SecureCredentialsStore.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/SecureCredentialsStore.java index 3efdf0aa..fd18a022 100644 --- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/SecureCredentialsStore.java +++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/SecureCredentialsStore.java @@ -13,10 +13,14 @@ package org.eclipse.mylyn.internal.commons.repositories.core; import java.io.IOException; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.equinox.security.storage.EncodingUtils; import org.eclipse.equinox.security.storage.ISecurePreferences; import org.eclipse.equinox.security.storage.SecurePreferencesFactory; import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; /** @@ -26,59 +30,165 @@ public class SecureCredentialsStore implements ICredentialsStore { private static final String ID_NODE = "org.eclipse.mylyn.commons.repository"; //$NON-NLS-1$ - private final String url; + private final String id; - public SecureCredentialsStore(String url) { - this.url = url; + private InMemoryCredentialsStore inMemoryStore; + + private boolean loggedStorageException; + + public SecureCredentialsStore(String id) { + this.id = id; } public void clear() { //getSecurePreferences().clear(); getSecurePreferences().removeNode(); + getInMemoryStore().clear(); + } + + public synchronized void copyTo(ICredentialsStore target) { + Assert.isNotNull(target); + if (!(target instanceof SecureCredentialsStore)) { + throw new IllegalArgumentException( + "SecureCredentialsStore may only by copied to stores of the same type: " + target.getClass()); //$NON-NLS-1$ + } + + ISecurePreferences preferences = getSecurePreferences(); + for (String key : preferences.keys()) { + try { + String value = preferences.get(key, null); + boolean encrypted = preferences.isEncrypted(key); + target.put(key, value, encrypted); + } catch (StorageException e) { + handle(e); + } + } + if (inMemoryStore != null) { + inMemoryStore.copyTo(target); + } } public void flush() throws IOException { getSecurePreferences().flush(); } - public String get(String key, String def) throws StorageException { - return getSecurePreferences().get(key, def); + public String get(final String key, final String def) { + InMemoryCredentialsStore memoryStore = getInMemoryStore(); + synchronized (memoryStore) { + if (memoryStore.hasKey(key)) { + return memoryStore.get(key, def); + } + } + try { + return getSecurePreferences().get(key, def); + } catch (StorageException e) { + handle(e); + return memoryStore.get(key, def); + } } - public byte[] getByteArray(String key, byte[] def) throws StorageException { - return getSecurePreferences().getByteArray(key, def); + public boolean getBoolean(String key, boolean def) { + InMemoryCredentialsStore memoryStore = getInMemoryStore(); + synchronized (memoryStore) { + if (memoryStore.hasKey(key)) { + return memoryStore.getBoolean(key, def); + } + } + try { + return getSecurePreferences().getBoolean(key, def); + } catch (StorageException e) { + handle(e); + return memoryStore.getBoolean(key, def); + } } - private ISecurePreferences getSecurePreferences() { - ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault().node(ID_NODE); - securePreferences = securePreferences.node(EncodingUtils.encodeSlashes(getUrl())); - return securePreferences; + public byte[] getByteArray(String key, byte[] def) { + InMemoryCredentialsStore memoryStore = getInMemoryStore(); + synchronized (memoryStore) { + if (memoryStore.hasKey(key)) { + return memoryStore.getByteArray(key, def); + } + } + try { + return getSecurePreferences().getByteArray(key, def); + } catch (StorageException e) { + handle(e); + return memoryStore.getByteArray(key, def); + } } - public String getUrl() { - return url; + public String getId() { + return id; } public String[] keys() { return getSecurePreferences().keys(); } - public void put(String key, String value, boolean encrypt) throws StorageException { - getSecurePreferences().put(key, value, encrypt); + public void put(String key, String value, boolean encrypt) { + put(key, value, encrypt, true); } - public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException { - getSecurePreferences().putByteArray(key, value, encrypt); + public void put(String key, String value, boolean encrypt, boolean persist) { + if (persist) { + try { + getSecurePreferences().put(key, value, encrypt); + getInMemoryStore().remove(key); + } catch (StorageException e) { + handle(e); + getInMemoryStore().put(key, value, encrypt, true); + } + } else { + getInMemoryStore().put(key, value, encrypt, false); + getSecurePreferences().remove(key); + } + } + + public void putBoolean(String key, boolean value, boolean encrypt) { + try { + getSecurePreferences().putBoolean(key, value, encrypt); + getInMemoryStore().remove(key); + } catch (StorageException e) { + handle(e); + getInMemoryStore().putBoolean(key, value, encrypt); + } + } + + public void putByteArray(String key, byte[] value, boolean encrypt) { + try { + getSecurePreferences().putByteArray(key, value, encrypt); + getInMemoryStore().remove(key); + } catch (StorageException e) { + handle(e); + getInMemoryStore().putByteArray(key, value, encrypt); + } } public void remove(String key) { getSecurePreferences().remove(key); } - public void copyTo(ICredentialsStore target) throws StorageException { - ISecurePreferences preferences = getSecurePreferences(); - for (String key : preferences.keys()) { - target.put(key, preferences.get(key, null), preferences.isEncrypted(key)); + protected synchronized InMemoryCredentialsStore getInMemoryStore() { + if (inMemoryStore == null) { + inMemoryStore = InMemoryCredentialsStore.getStore(id); + } + return inMemoryStore; + } + + protected ISecurePreferences getSecurePreferences() { + ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault().node(ID_NODE); + securePreferences = securePreferences.node(EncodingUtils.encodeSlashes(getId())); + return securePreferences; + } + + private void handle(StorageException e) { + if (!loggedStorageException) { + loggedStorageException = true; + StatusHandler.log(new Status( + IStatus.ERROR, + RepositoriesCoreInternal.ID_PLUGIN, + "Unexpected error accessing secure storage, falling back to in memory store for credentials. Some credentials may not be saved.", + e)); } } diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java index 47725dfe..e2a82ba5 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java @@ -24,7 +24,11 @@ import org.apache.http.protocol.SyncBasicHttpContext; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationException; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; /** * Provides an abstraction for connecting to a {@link RepositoryLocation} through HTTP. @@ -70,6 +74,10 @@ public class CommonHttpClient { return authenticated; } + public boolean needsAuthentication() { + return !isAuthenticated() && getLocation().getCredentials(AuthenticationType.REPOSITORY, false) != null; + } + public void setAuthenticated(boolean authenticated) { this.authenticated = authenticated; } @@ -100,29 +108,22 @@ public class CommonHttpClient { return HttpUtil.getConnectionManager(); } - protected boolean needsReauthentication(HttpResponse response, IProgressMonitor monitor) throws IOException { + protected <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> request, IProgressMonitor monitor) { + return location.requestCredentials(request, monitor); + } + + protected void validate(HttpResponse response, IProgressMonitor monitor) throws AuthenticationException { int statusCode = response.getStatusLine().getStatusCode(); - final AuthenticationType authenticationType; - if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) { - authenticationType = AuthenticationType.HTTP; + if (statusCode == HttpStatus.SC_UNAUTHORIZED) { + AuthenticationRequest<AuthenticationType<UserCredentials>> request = new AuthenticationRequest<AuthenticationType<UserCredentials>>( + getLocation(), AuthenticationType.HTTP); + throw new AuthenticationException(HttpUtil.getStatusText(statusCode), request); } else if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { - authenticationType = AuthenticationType.PROXY; - } else { - return false; + AuthenticationRequest<AuthenticationType<UserCredentials>> request = new AuthenticationRequest<AuthenticationType<UserCredentials>>( + getLocation(), AuthenticationType.PROXY); + throw new AuthenticationException(HttpUtil.getStatusText(statusCode), request); } - - try { - org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials authCreds = location.getService() - .requestCredentials(AuthenticationType.HTTP, - org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials.class, null, - monitor); - } catch (UnsupportedOperationException e) { - IOException ioe = new IOException(HttpUtil.getStatusText(statusCode)); - ioe.initCause(e); - throw ioe; - } - - return true; } } diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java index 775a6e93..89fe3d8b 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java @@ -20,6 +20,10 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; import org.eclipse.mylyn.commons.core.operations.OperationUtil; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationException; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; /** * @author Steffen Pingel @@ -51,6 +55,22 @@ public abstract class CommonHttpOperation<T> { protected CommonHttpResponse execute(HttpRequestBase request, IOperationMonitor monitor) throws IOException { monitor = OperationUtil.convert(monitor); + try { + // first attempt + return executeOnce(request, monitor); + } catch (AuthenticationException e) { + try { + requestCredentials((AuthenticationRequest) e.getRequest(), monitor); + } catch (UnsupportedOperationException e2) { + throw e; + } + } + + // second attempt + return executeOnce(request, monitor); + } + + protected CommonHttpResponse executeOnce(HttpRequestBase request, IOperationMonitor monitor) throws IOException { // force authentication if (needsAuthentication()) { authenticate(monitor); @@ -58,12 +78,10 @@ public abstract class CommonHttpOperation<T> { // first attempt HttpResponse response = client.execute(request, monitor); - boolean repeat = false; try { - if (needsReauthentication(response, monitor)) { - HttpUtil.release(request, response, monitor); - repeat = true; - } + validate(response, monitor); + // success + return new CommonHttpResponse(request, response); } catch (IOException e) { HttpUtil.release(request, response, monitor); throw e; @@ -71,14 +89,6 @@ public abstract class CommonHttpOperation<T> { HttpUtil.release(request, response, monitor); throw e; } - - if (repeat) { - // second attempt - authenticate(monitor); - response = client.execute(request, monitor); - } - - return new CommonHttpResponse(request, response); } protected final CommonHttpClient getClient() { @@ -86,11 +96,16 @@ public abstract class CommonHttpOperation<T> { } protected boolean needsAuthentication() { - return false; + return client.needsAuthentication(); + } + + protected <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> request, IOperationMonitor monitor) { + return client.requestCredentials(request, monitor); } - protected boolean needsReauthentication(HttpResponse response, IOperationMonitor monitor) throws IOException { - return client.needsReauthentication(response, monitor); + protected void validate(HttpResponse response, IOperationMonitor monitor) throws AuthenticationException { + client.validate(response, monitor); } } diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java index 2dd31c96..528cdf12 100644 --- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java +++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java @@ -18,8 +18,6 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URI; import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; import org.apache.http.HttpEntity; @@ -30,10 +28,10 @@ import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.NTCredentials; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.auth.params.AuthPNames; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.AuthPolicy; +import org.apache.http.client.params.ClientPNames; import org.apache.http.client.params.CookiePolicy; import org.apache.http.client.params.HttpClientParams; import org.apache.http.conn.params.ConnRoutePNames; @@ -63,6 +61,7 @@ import org.eclipse.mylyn.commons.core.operations.Operation; import org.eclipse.mylyn.commons.core.operations.OperationUtil; import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; /** * @author Steffen Pingel @@ -111,10 +110,11 @@ public class HttpUtil { } public static void configureClient(AbstractHttpClient client, String userAgent) { - HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.RFC_2109); + HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.BEST_MATCH); HttpProtocolParams.setUserAgent(client.getParams(), userAgent); HttpProtocolParams.setUseExpectContinue(client.getParams(), true); + client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT); @@ -130,9 +130,7 @@ public class HttpUtil { configureProxy(client, location, url); - org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials authCreds = location.getCredentials( - AuthenticationType.HTTP, - org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials.class); + UserCredentials authCreds = location.getCredentials(AuthenticationType.HTTP); if (authCreds != null) { String host = NetUtil.getHost(url); int port = NetUtil.getPort(url); @@ -185,7 +183,7 @@ public class HttpUtil { } public static Credentials getHttpClientCredentials( - org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials credentials, String host, + org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials credentials, String host, boolean forceUserNamePassword) { String username = credentials.getUserName(); String password = credentials.getPassword(); @@ -228,9 +226,9 @@ public class HttpUtil { Proxy proxy; if (NetUtil.isUrlHttps(location.getUrl())) { - proxy = location.getService().getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE); + proxy = location.getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE); } else { - proxy = location.getService().getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE); + proxy = location.getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE); } if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { @@ -244,11 +242,6 @@ public class HttpUtil { Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(), address.getAddress(), false); if (credentials instanceof NTCredentials) { - List<String> authpref = new ArrayList<String>(); - authpref.add(AuthPolicy.NTLM); - authpref.add(AuthPolicy.BASIC); - authpref.add(AuthPolicy.DIGEST); - client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); AuthScope proxyAuthScopeNTLM = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM, AuthPolicy.NTLM); client.getCredentialsProvider().setCredentials(proxyAuthScopeNTLM, credentials); @@ -260,11 +253,6 @@ public class HttpUtil { client.getCredentialsProvider().setCredentials(proxyAuthScopeAny, usernamePasswordCredentials); } else { - List<String> authpref = new ArrayList<String>(); - authpref.add(AuthPolicy.BASIC); - authpref.add(AuthPolicy.DIGEST); - authpref.add(AuthPolicy.NTLM); - client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM); client.getCredentialsProvider().setCredentials(proxyAuthScope, credentials); diff --git a/org.eclipse.mylyn.commons.repositories.tests/.classpath b/org.eclipse.mylyn.commons.repositories.tests/.classpath new file mode 100644 index 00000000..8d4bac77 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.classpath @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> + <accessrules> + <accessrule kind="accessible" pattern="org/eclipse/mylyn/internal/**"/> + <accessrule kind="accessible" pattern="org/eclipse/core/internal/net/**"/> + </accessrules> + </classpathentry> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.eclipse.mylyn.commons.repositories.tests/.cvsignore b/org.eclipse.mylyn.commons.repositories.tests/.cvsignore new file mode 100644 index 00000000..d567ba01 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.cvsignore @@ -0,0 +1,2 @@ +bin +target diff --git a/org.eclipse.mylyn.commons.repositories.tests/.project b/org.eclipse.mylyn.commons.repositories.tests/.project new file mode 100644 index 00000000..6537ad27 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.mylyn.commons.repositories.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/.api_filters b/org.eclipse.mylyn.commons.repositories.tests/.settings/.api_filters new file mode 100644 index 00000000..e0014b33 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/.api_filters @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<component id="org.eclipse.mylyn.commons.repositories.tests" version="2"> + <resource path="src/org/eclipse/mylyn/commons/repositories/tests/support/DelegatingSecurePreferences.java" type="org.eclipse.mylyn.commons.repositories.tests.support.DelegatingSecurePreferences"> + <filter id="574619656"> + <message_arguments> + <message_argument value="ISecurePreferences"/> + <message_argument value="DelegatingSecurePreferences"/> + </message_arguments> + </filter> + </resource> +</component> diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 00000000..5a0ad22d --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..74bc9856 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,359 @@ +#Wed Mar 02 16:00:04 PST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=error +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled +org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL +org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=48 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=true +org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=false +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=120 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=120 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=true +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000..2843a88a --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,63 @@ +#Wed Mar 02 16:00:08 PST 2011 +cleanup_settings_version=2 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_Mylyn based on Eclipse +formatter_settings_version=12 +internal.default.compliance=default +org.eclipse.jdt.ui.exception.name=e +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.javadoc=false +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*******************************************************************************\n * Copyright (c) ${year} Tasktop Technologies and others.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * Tasktop Technologies - initial API and implementation\n *******************************************************************************/\n\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ignore\n${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ignore</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created JavaScript files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for vars" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Jsdoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created function stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated function stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=true +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=true +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=true +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.ltk.core.refactoring.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 00000000..5e7f2bd4 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,3 @@ +#Tue Aug 18 22:42:26 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs new file mode 100644 index 00000000..d8c6d26a --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs @@ -0,0 +1,4 @@ +#Mon Jun 25 03:02:37 GMT 2007 +eclipse.preferences.version=1 +project.repository.kind=bugzilla +project.repository.url=https\://bugs.eclipse.org/bugs diff --git a/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.pde.prefs b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.pde.prefs new file mode 100644 index 00000000..e8f2d562 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/.settings/org.eclipse.pde.prefs @@ -0,0 +1,18 @@ +#Tue Apr 15 11:07:59 PDT 2008 +compilers.incompatible-environment=1 +compilers.p.build=1 +compilers.p.deprecated=1 +compilers.p.discouraged-class=2 +compilers.p.missing-bundle-classpath-entries=1 +compilers.p.missing-packages=1 +compilers.p.no-required-att=0 +compilers.p.not-externalized-att=2 +compilers.p.unknown-attribute=0 +compilers.p.unknown-class=0 +compilers.p.unknown-element=0 +compilers.p.unknown-identifier=1 +compilers.p.unknown-resource=0 +compilers.p.unresolved-ex-points=0 +compilers.p.unresolved-import=0 +compilers.use-project=true +eclipse.preferences.version=1 diff --git a/org.eclipse.mylyn.commons.repositories.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..dee2a63e --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Mylyn Commons Tests +Bundle-SymbolicName: org.eclipse.mylyn.commons.repositories.tests;singleton:=true +Bundle-Version: 0.9.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.net, + org.eclipse.equinox.security, + org.junit4;bundle-version="4.5.0", + org.eclipse.mylyn.commons.core, + org.eclipse.mylyn.commons.repositories.core, + org.eclipse.mylyn.commons.repositories.ui, + org.eclipse.mylyn.commons.sdk.util +Export-Package: org.eclipse.mylyn.commons.repositories.tests.core;x-internal:=true +Bundle-Vendor: Eclipse Mylyn diff --git a/org.eclipse.mylyn.commons.repositories.tests/about.html b/org.eclipse.mylyn.commons.repositories.tests/about.html new file mode 100644 index 00000000..d774b07c --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/about.html @@ -0,0 +1,27 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<html> +<head> +<title>About</title> +<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 25, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/org.eclipse.mylyn.commons.repositories.tests/build.properties b/org.eclipse.mylyn.commons.repositories.tests/build.properties new file mode 100644 index 00000000..4002fdba --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/build.properties @@ -0,0 +1,17 @@ +############################################################################### +# Copyright (c) 2009 Tasktop Technologies 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 +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Tasktop Technologies - initial API and implementation +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = .,\ + META-INF/,\ + about.html +src.includes = about.html +jre.compilation.profile = J2SE-1.5 diff --git a/org.eclipse.mylyn.commons.repositories.tests/pom.xml b/org.eclipse.mylyn.commons.repositories.tests/pom.xml new file mode 100644 index 00000000..544df8a0 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/pom.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.mylyn.commons-parent</artifactId> + <groupId>org.eclipse.mylyn.commons</groupId> + <version>3.7.0-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.mylyn.commons.repositories.tests</artifactId> + <version>0.9.0-SNAPSHOT</version> + <packaging>eclipse-test-plugin</packaging> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/AbstractCredentialsStoreTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/AbstractCredentialsStoreTest.java new file mode 100644 index 00000000..c807137d --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/AbstractCredentialsStoreTest.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public abstract class AbstractCredentialsStoreTest { + + @Test + public void testGetBooleanDefault() { + ICredentialsStore store = createCredentialsStore(); + assertEquals(true, store.getBoolean("key2", true)); + assertEquals(false, store.getBoolean("key2", false)); + } + + @Test + public void testGetStringDefault() { + ICredentialsStore store = createCredentialsStore(); + assertEquals("default", store.get("key2", "default")); + assertEquals("otherValue", store.get("key2", "otherValue")); + assertEquals(null, store.get("key2", null)); + } + + @Test + public void testKeys() { + ICredentialsStore store = createCredentialsStore(); + store.put("a", "value", false); + store.put("b", "value", true); + String[] keys = store.keys(); + Arrays.sort(keys); + assertEquals("[a, b]", Arrays.toString(keys)); + } + + @Test + public void testPutGetBooleanEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.putBoolean("key", true, true); + assertEquals(true, store.getBoolean("key", false)); + } + + @Test + public void testPutGetBooleanNotEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.putBoolean("key", true, false); + assertEquals(true, store.getBoolean("key", false)); + } + + @Test + public void testPutGetByteArrayDefault() { + ICredentialsStore store = createCredentialsStore(); + assertEquals(null, store.getByteArray("key2", null)); + assertEquals(Arrays.toString(new byte[] { 0x00, 0x32 }), + Arrays.toString(store.getByteArray("key2", new byte[] { 0x00, 0x32 }))); + } + + @Test + public void testPutGetByteArrayEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.putByteArray("key", new byte[] { 0x00, 0x32 }, true); + assertEquals(Arrays.toString(new byte[] { 0x00, 0x32 }), + Arrays.toString(store.getByteArray("key", new byte[] { 0x00, 0x32 }))); + } + + @Test + public void testPutGetByteArrayNotEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.putByteArray("key", new byte[] { 0x00, 0x32 }, false); + assertEquals(Arrays.toString(new byte[] { 0x00, 0x32 }), + Arrays.toString(store.getByteArray("key", new byte[] { 0x00, 0x32 }))); + } + + @Test + public void testPutGetStringEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "valueGet", true); + assertEquals("valueGet", store.get("key", "default")); + } + + @Test + public void testPutGetStringEncryptedNotPersisted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "valueGet", true, false); + assertEquals("valueGet", store.get("key", "default")); + store.put("key", "newValue", true, false); + assertEquals("newValue", store.get("key", "default")); + } + + @Test + public void testPutGetStringNotEncryptedNotPersisted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "valueGet", false, false); + assertEquals("valueGet", store.get("key", "default")); + store.put("key", "newValue", false, false); + assertEquals("newValue", store.get("key", "default")); + } + + @Test + public void testPutGetStringNotEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "valueGet", false); + assertEquals("valueGet", store.get("key", "default")); + } + + @Test + public void testRemoveEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "value", true); + store.remove("key"); + assertEquals("default", store.get("key", "default")); + } + + @Test + public void testRemoveNonExistantEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.remove("key2"); + assertEquals("default", store.get("key2", "default")); + } + + @Test + public void testRemoveNotEncrypted() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "value", false); + store.remove("key"); + assertEquals("default", store.get("key", "default")); + } + + @Test + public void testRemoveKeys() { + ICredentialsStore store = createCredentialsStore(); + store.put("key", "value", false); + store.remove("key"); + assertEquals("[]", Arrays.toString(store.keys())); + } + + protected abstract ICredentialsStore createCredentialsStore(); + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsFactoryTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsFactoryTest.java new file mode 100644 index 00000000..f8509c25 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsFactoryTest.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.CertificateCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; +import org.eclipse.mylyn.commons.repositories.core.auth.OpenIdCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; +import org.eclipse.mylyn.internal.commons.repositories.core.CredentialsFactory; +import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class CredentialsFactoryTest { + + @Test(expected = RuntimeException.class) + public void testCreateInvalidCredentials() { + ICredentialsStore store = new InMemoryCredentialsStore(); + AuthenticationCredentials credentials = new AuthenticationCredentials() { + @Override + public void save(ICredentialsStore store, String prefix) { + // ignore + } + + @Override + public void clear(ICredentialsStore store, String prefix) { + // ignore + } + }; + CredentialsFactory.create(credentials.getClass(), store, "key", false); + } + + @Test + public void testCreateUserCredentials() { + ICredentialsStore store = new InMemoryCredentialsStore(); + UserCredentials credentials = CredentialsFactory.create(UserCredentials.class, store, "key", false); + assertEquals("", credentials.getUserName()); + assertEquals("", credentials.getPassword()); + assertEquals(null, credentials.getDomain()); + assertEquals(false, credentials.getSavePassword()); + } + + @Test + public void testSaveUserCredentials() throws StorageException { + ICredentialsStore store = new InMemoryCredentialsStore(); + UserCredentials oldCredentials = new UserCredentials("user", "password", "domain", false); + oldCredentials.save(store, "key"); + UserCredentials newCredentials = CredentialsFactory.create(UserCredentials.class, store, "key", true); + assertNotSame(oldCredentials, newCredentials); + assertEquals(oldCredentials, newCredentials); + } + + @Test + public void testCreateCertificateCredentials() { + ICredentialsStore store = new InMemoryCredentialsStore(); + CertificateCredentials credentials = CredentialsFactory.create(CertificateCredentials.class, store, "key", + false); + assertEquals(null, credentials.getKeyStoreFileName()); + assertEquals("", credentials.getPassword()); + } + + @Test + public void testSaveCertificateCredentials() throws StorageException { + ICredentialsStore store = new InMemoryCredentialsStore(); + CertificateCredentials oldCredentials = new CertificateCredentials("keyStore", "password"); + oldCredentials.save(store, "key"); + CertificateCredentials newCredentials = CredentialsFactory.create(CertificateCredentials.class, store, "key", + true); + assertNotSame(oldCredentials, newCredentials); + assertEquals(oldCredentials, newCredentials); + } + + @Test + public void testCreateOpenIdCredentials() { + ICredentialsStore store = new InMemoryCredentialsStore(); + OpenIdCredentials credentials = CredentialsFactory.create(OpenIdCredentials.class, store, "key", false); + assertEquals(null, credentials.getResponseUrl()); + assertEquals(null, credentials.getToken()); + } + + @Test + public void testSaveOpenIdCredentials() throws StorageException { + ICredentialsStore store = new InMemoryCredentialsStore(); + OpenIdCredentials oldCredentials = new OpenIdCredentials("responseUrl", "token"); + oldCredentials.save(store, "key"); + OpenIdCredentials newCredentials = CredentialsFactory.create(OpenIdCredentials.class, store, "key", true); + assertNotSame(oldCredentials, newCredentials); + assertEquals(oldCredentials, newCredentials); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsStoreTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsStoreTest.java new file mode 100644 index 00000000..ce93c95f --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/CredentialsStoreTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; +import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore; +import org.eclipse.mylyn.internal.commons.repositories.core.SecureCredentialsStore; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class CredentialsStoreTest { + + @Test + public void testCopyInMemoryToSecure() { + InMemoryCredentialsStore source = new InMemoryCredentialsStore(); + SecureCredentialsStore target = new SecureCredentialsStore(CredentialsStoreTest.class.getName()); + target.clear(); + + putValues(source); + source.copyTo(target); + assertValues(target); + } + + @Test + public void testCopyInMemoryToInMemory() { + InMemoryCredentialsStore source = new InMemoryCredentialsStore(); + InMemoryCredentialsStore target = new InMemoryCredentialsStore(); + + putValues(source); + source.copyTo(target); + assertValues(target); + } + + @Test(expected = IllegalArgumentException.class) + public void testCopySecureToInMemory() { + SecureCredentialsStore source = new SecureCredentialsStore(CredentialsStoreTest.class.getName()); + source.clear(); + InMemoryCredentialsStore target = new InMemoryCredentialsStore(); + source.copyTo(target); + } + + @Test + public void testCopySecureToSecure() { + SecureCredentialsStore source = new SecureCredentialsStore(CredentialsStoreTest.class.getName()); + source.clear(); + SecureCredentialsStore target = new SecureCredentialsStore(CredentialsStoreTest.class.getName() + "2"); + target.clear(); + + putValues(source); + source.copyTo(target); + assertValues(target); + } + + private void assertValues(ICredentialsStore target) { + assertEquals("value", target.get("key1", null)); + assertEquals(true, target.getBoolean("key2", false)); + assertEquals(Arrays.toString(new byte[] { 0x00, 0x05 }), Arrays.toString(target.getByteArray("key3", null))); + assertEquals("value2", target.get("keyNotEncrypted", null)); + } + + private void putValues(ICredentialsStore source) { + source.put("key1", "value", true); + source.putBoolean("key2", true, true); + source.putByteArray("key3", new byte[] { 0x00, 0x05 }, true); + source.put("keyNotEncrypted", "value2", false); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/InMemoryCredentialsStoreTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/InMemoryCredentialsStoreTest.java new file mode 100644 index 00000000..4477b60b --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/InMemoryCredentialsStoreTest.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; + +import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class InMemoryCredentialsStoreTest extends AbstractCredentialsStoreTest { + + @Test + public void testCopyTo() { + InMemoryCredentialsStore source = new InMemoryCredentialsStore(); + InMemoryCredentialsStore target = new InMemoryCredentialsStore(); + source.put("key1", "value", true); + source.copyTo(target); + assertEquals("value", target.get("key1", null)); + } + + @Test + public void testCopyToRemove() { + InMemoryCredentialsStore source = new InMemoryCredentialsStore(); + InMemoryCredentialsStore target = new InMemoryCredentialsStore(); + target.put("key", "value", true); + source.remove("key"); + source.copyTo(target); + assertEquals(null, target.get("key", null)); + } + + @Test + public void testGetStore() { + InMemoryCredentialsStore store = InMemoryCredentialsStore.getStore("test-store"); + assertNotNull(store); + assertSame(store, InMemoryCredentialsStore.getStore("test-store")); + assertNotSame(store, InMemoryCredentialsStore.getStore("test-store2")); + } + + @Test + public void testParentPutGetString() { + InMemoryCredentialsStore parent = new InMemoryCredentialsStore(); + InMemoryCredentialsStore store = new InMemoryCredentialsStore(parent); + parent.put("key", "parentValue", false); + assertEquals("parentValue", store.get("key", null)); + store.put("key", "value", false); + assertEquals("value", store.get("key", null)); + } + + @Test + public void testParentCopyToRemove() { + InMemoryCredentialsStore parent = new InMemoryCredentialsStore(); + InMemoryCredentialsStore store = new InMemoryCredentialsStore(parent); + parent.put("key", "parentValue", false); + store.remove("key"); + assertEquals("parentValue", store.get("key", null)); + parent.remove("key"); + assertEquals(null, store.get("key", null)); + } + + public void testGetId() { + assertEquals("id", InMemoryCredentialsStore.getStore("id").getId()); + } + + @Override + protected InMemoryCredentialsStore createCredentialsStore() { + return new InMemoryCredentialsStore(); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/RepositoryLocationTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/RepositoryLocationTest.java new file mode 100644 index 00000000..3f407e82 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/RepositoryLocationTest.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class RepositoryLocationTest { + + @Test + public void testGetId() { + assertNotNull(new RepositoryLocation().getId()); + } + + @Test + public void testSetCredentialsRepositoryCredentials() { + RepositoryLocation location = new RepositoryLocation(); + UserCredentials credentials = new UserCredentials("user", "password", "domain", true); + location.setCredentials(AuthenticationType.REPOSITORY, credentials); + UserCredentials newCredentials = location.getCredentials(AuthenticationType.REPOSITORY); + assertEquals(credentials, newCredentials); + } + + @Test + public void testSetCredentialsRepositoryHttpCredentials() { + RepositoryLocation location = new RepositoryLocation(); + UserCredentials credentials = new UserCredentials("httpuser", "httppassword", "httpdomain", true); + location.setCredentials(AuthenticationType.HTTP, credentials); + UserCredentials newCredentials = location.getCredentials(AuthenticationType.HTTP); + assertEquals(credentials, newCredentials); + } + + @Test + public void testSetCredentialsRepositoryNull() { + RepositoryLocation location = new RepositoryLocation(); + UserCredentials credentials = new UserCredentials("httpuser", "httppassword", "httpdomain", true); + location.setCredentials(AuthenticationType.HTTP, credentials); + location.setCredentials(AuthenticationType.HTTP, null); + assertNull(location.getCredentials(AuthenticationType.HTTP)); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/SecureCredentialsStoreTest.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/SecureCredentialsStoreTest.java new file mode 100644 index 00000000..aae921bc --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/core/SecureCredentialsStoreTest.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.core; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.mylyn.commons.repositories.tests.support.DelegatingSecurePreferences; +import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore; +import org.eclipse.mylyn.internal.commons.repositories.core.SecureCredentialsStore; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class SecureCredentialsStoreTest extends AbstractCredentialsStoreTest { + + private class StubSecureCredentialsStore extends SecureCredentialsStore { + + DelegatingSecurePreferences delegate; + + public StubSecureCredentialsStore() { + super(SecureCredentialsStore.class.getName()); + } + + @Override + protected DelegatingSecurePreferences getSecurePreferences() { + if (delegate == null) { + delegate = new DelegatingSecurePreferences(getSecurePreferencesSuper()) { + @Override + public void removeNode() { + super.removeNode(); + // re-initialize + setDelegate(getSecurePreferencesSuper()); + } + }; + } + return delegate; + } + + ISecurePreferences getSecurePreferencesSuper() { + return super.getSecurePreferences(); + } + + @Override + protected synchronized InMemoryCredentialsStore getInMemoryStore() { + return super.getInMemoryStore(); + } + + } + + @Test + public void testClear() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.put("key", "value", false); + assertEquals("[key]", Arrays.toString(store.getSecurePreferences().keys())); + store.clear(); + assertEquals("[]", Arrays.toString(store.getSecurePreferences().keys())); + } + + @Test + public void testGetId() { + SecureCredentialsStore store = createCredentialsStore(); + assertEquals(SecureCredentialsStoreTest.class.getName(), store.getId()); + } + + @Override + protected SecureCredentialsStore createCredentialsStore() { + SecureCredentialsStore store = new SecureCredentialsStore(SecureCredentialsStoreTest.class.getName()); + store.clear(); + return store; + } + + @Test + public void testKeysInSecurePreferences() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.put("key", "value", false); + assertEquals("[key]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals("[]", Arrays.toString(store.getInMemoryStore().keys())); + } + + @Test + public void testKeysInSecurePreferencesNoPersist() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.put("key", "value", false, false); + assertEquals("[]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals("[key]", Arrays.toString(store.getInMemoryStore().keys())); + } + + @Test + public void testKeysInSecurePreferencesEncryptNoPersist() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.put("key", "value", true, false); + assertEquals("[]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals("[key]", Arrays.toString(store.getInMemoryStore().keys())); + } + + @Test + public void testKeysInSecurePreferencesNoPersistClear() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.put("key", "value", false, false); + store.clear(); + assertEquals("[]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals("[]", Arrays.toString(store.getInMemoryStore().keys())); + } + + @Test + public void testPutException() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.getSecurePreferences().setException(new StorageException(0, "")); + store.put("key", "value", true); + assertEquals("[]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals("value", store.getInMemoryStore().get("key", null)); + assertEquals("value", store.get("key", null)); + } + + @Test + public void testPutExceptionNoException() { + StubSecureCredentialsStore store = new StubSecureCredentialsStore(); + store.getSecurePreferences().setException(new StorageException(0, "")); + store.put("key", "value", true); + store.getSecurePreferences().setException(null); + store.put("key", "value", true); + assertEquals("[key]", Arrays.toString(store.getSecurePreferences().keys())); + assertEquals(null, store.getInMemoryStore().get("key", null)); + assertEquals("value", store.get("key", null)); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/support/DelegatingSecurePreferences.java b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/support/DelegatingSecurePreferences.java new file mode 100644 index 00000000..fb810250 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.tests/src/org/eclipse/mylyn/commons/repositories/tests/support/DelegatingSecurePreferences.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.repositories.tests.support; + +import java.io.IOException; + +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; + +/** + * @author Steffen Pingel + */ +public class DelegatingSecurePreferences implements ISecurePreferences { + + ISecurePreferences delegate; + + StorageException exception; + + public DelegatingSecurePreferences(ISecurePreferences delegate) { + this.delegate = delegate; + } + + public String absolutePath() { + return delegate.absolutePath(); + } + + public String[] childrenNames() { + return delegate.childrenNames(); + } + + public void clear() { + delegate.clear(); + } + + public void flush() throws IOException { + delegate.flush(); + } + + public String get(String key, String def) throws StorageException { + checkException(); + return delegate.get(key, def); + } + + public boolean getBoolean(String key, boolean def) throws StorageException { + checkException(); + return delegate.getBoolean(key, def); + } + + public byte[] getByteArray(String key, byte[] def) throws StorageException { + checkException(); + return delegate.getByteArray(key, def); + } + + public ISecurePreferences getDelegate() { + return delegate; + } + + public double getDouble(String key, double def) throws StorageException { + checkException(); + return delegate.getDouble(key, def); + } + + public StorageException getException() { + return exception; + } + + public float getFloat(String key, float def) throws StorageException { + checkException(); + return delegate.getFloat(key, def); + } + + public int getInt(String key, int def) throws StorageException { + checkException(); + return delegate.getInt(key, def); + } + + public long getLong(String key, long def) throws StorageException { + checkException(); + return delegate.getLong(key, def); + } + + public boolean isEncrypted(String key) throws StorageException { + checkException(); + return delegate.isEncrypted(key); + } + + public String[] keys() { + return delegate.keys(); + } + + public String name() { + return delegate.name(); + } + + public ISecurePreferences node(String pathName) { + return delegate.node(pathName); + } + + public boolean nodeExists(String pathName) { + return delegate.nodeExists(pathName); + } + + public ISecurePreferences parent() { + return delegate.parent(); + } + + public void put(String key, String value, boolean encrypt) throws StorageException { + checkException(); + delegate.put(key, value, encrypt); + } + + public void putBoolean(String key, boolean value, boolean encrypt) throws StorageException { + checkException(); + delegate.putBoolean(key, value, encrypt); + } + + public void putByteArray(String key, byte[] value, boolean encrypt) throws StorageException { + checkException(); + delegate.putByteArray(key, value, encrypt); + } + + public void putDouble(String key, double value, boolean encrypt) throws StorageException { + checkException(); + delegate.putDouble(key, value, encrypt); + } + + public void putFloat(String key, float value, boolean encrypt) throws StorageException { + checkException(); + delegate.putFloat(key, value, encrypt); + } + + public void putInt(String key, int value, boolean encrypt) throws StorageException { + checkException(); + delegate.putInt(key, value, encrypt); + } + + public void putLong(String key, long value, boolean encrypt) throws StorageException { + checkException(); + delegate.putLong(key, value, encrypt); + } + + public void remove(String key) { + delegate.remove(key); + } + + public void removeNode() { + delegate.removeNode(); + } + + public void setDelegate(ISecurePreferences delegate) { + this.delegate = delegate; + } + + public void setException(StorageException exception) { + this.exception = exception; + } + + private void checkException() throws StorageException { + if (exception != null) { + throw exception; + } + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.ui/META-INF/MANIFEST.MF index e58c868c..42e9abc3 100644 --- a/org.eclipse.mylyn.commons.repositories.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.commons.repositories.ui/META-INF/MANIFEST.MF @@ -14,11 +14,13 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.databinding.beans, org.eclipse.core.databinding.property;resolution:=optional, org.eclipse.jface.databinding, - org.eclipse.mylyn.commons.repositories.core;bundle-version="0.1.0", - org.eclipse.mylyn.commons.ui;bundle-version="3.5.0", - org.eclipse.mylyn.commons.workbench;bundle-version="3.5.0" + org.eclipse.mylyn.commons.core;bundle-version="3.7.0", + org.eclipse.mylyn.commons.repositories.core;bundle-version="0.9.0", + org.eclipse.mylyn.commons.ui;bundle-version="3.7.0", + org.eclipse.mylyn.commons.workbench;bundle-version="3.7.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.mylyn.commons.repositories.ui;x-internal:=true, org.eclipse.mylyn.internal.commons.repositories.ui;x-internal:=true, + org.eclipse.mylyn.internal.commons.repositories.ui.auth;x-internal:=true, org.eclipse.mylyn.internal.commons.repositories.ui.wizards;x-internal:=true diff --git a/org.eclipse.mylyn.commons.repositories.ui/plugin.xml b/org.eclipse.mylyn.commons.repositories.ui/plugin.xml index 21761a41..07767b51 100644 --- a/org.eclipse.mylyn.commons.repositories.ui/plugin.xml +++ b/org.eclipse.mylyn.commons.repositories.ui/plugin.xml @@ -161,5 +161,12 @@ </command> </menuContribution> </extension> + <extension + point="org.eclipse.mylyn.commons.repositories.core.locationServices"> + <service + class="org.eclipse.mylyn.internal.commons.repositories.ui.UiLocationService" + id="org.eclipse.mylyn.commons.repositories.ui.LocationService"> + </service> + </extension> </plugin> diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryLocationPart.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryLocationPart.java index 6ddf30fd..38a956cb 100644 --- a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryLocationPart.java +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryLocationPart.java @@ -20,6 +20,7 @@ import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.UpdateValueStrategy; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -40,7 +41,7 @@ import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation; import org.eclipse.mylyn.commons.repositories.core.RepositoryValidator; import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; -import org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; import org.eclipse.mylyn.commons.workbench.forms.SectionComposite; import org.eclipse.mylyn.internal.commons.repositories.ui.RepositoriesUiPlugin; import org.eclipse.mylyn.internal.commons.repositories.ui.RepositoryLocationValueProperty; @@ -80,7 +81,7 @@ public class RepositoryLocationPart { private class UsernamePasswordListener implements ModifyListener, SelectionListener { - private final AuthenticationType authenticationType; + private final AuthenticationType<UserCredentials> authenticationType; private final Button enabledButton; @@ -94,12 +95,19 @@ public class RepositoryLocationPart { private final Text userText; - public UsernamePasswordListener(AuthenticationType authenticationType, Button enabledButton, Text userText, - Text passwordText, Button savePasswordButton) { + private final Text domainText; + + public UsernamePasswordListener(AuthenticationType<UserCredentials> authenticationType, Button enabledButton, + Text userText, Text passwordText, Text domainText, Button savePasswordButton) { + Assert.isNotNull(authenticationType); + Assert.isNotNull(enabledButton); + Assert.isNotNull(userText); + Assert.isNotNull(passwordText); this.authenticationType = authenticationType; this.enabledButton = enabledButton; this.userText = userText; this.passwordText = passwordText; + this.domainText = domainText; this.savePasswordButton = savePasswordButton; init(); } @@ -108,9 +116,10 @@ public class RepositoryLocationPart { if (updating) { return; } - if (isEnabled()) { - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userText.getText(), - passwordText.getText()); + if (getEnabledButtonSelection()) { + String domain = (domainText != null) ? domainText.getText() : null; + UserCredentials credentials = new UserCredentials(userText.getText(), passwordText.getText(), domain, + savePasswordButton.getSelection()); getWorkingCopy().setCredentials(authenticationType, credentials); } else { getWorkingCopy().setCredentials(authenticationType, null); @@ -121,10 +130,13 @@ public class RepositoryLocationPart { enabledButton.addSelectionListener(this); userText.addModifyListener(this); passwordText.addModifyListener(this); + if (domainText != null) { + domainText.addModifyListener(this); + } savePasswordButton.addSelectionListener(this); } - protected boolean isEnabled() { + protected boolean getEnabledButtonSelection() { return enabledButton.getSelection() != isEnablementReversed(); } @@ -139,17 +151,22 @@ public class RepositoryLocationPart { private void restore() { try { updating = true; - UsernamePasswordCredentials credentials = getWorkingCopy().getCredentials(authenticationType, - UsernamePasswordCredentials.class); + UserCredentials credentials = getWorkingCopy().getCredentials(authenticationType); if (credentials != null) { enabledButton.setSelection(!isEnablementReversed()); userText.setText(credentials.getUserName()); passwordText.setText(credentials.getPassword()); - savePasswordButton.setSelection(true); + if (domainText != null) { + domainText.setText((credentials.getDomain() != null) ? credentials.getDomain() : ""); //$NON-NLS-1$ + } + savePasswordButton.setSelection(credentials.getSavePassword()); } else { enabledButton.setSelection(isEnablementReversed()); userText.setText(""); //$NON-NLS-1$ passwordText.setText(""); //$NON-NLS-1$ + if (domainText != null) { + domainText.setText(""); //$NON-NLS-1$ + } savePasswordButton.setSelection(true); } } finally { @@ -163,15 +180,11 @@ public class RepositoryLocationPart { } private void updateWidgetEnablement() { - boolean enabled = isEnabled(); - userText.setEnabled(enabled); - passwordText.setEnabled(enabled); - savePasswordButton.setEnabled(enabled); + setInputFieldsEnabled(getEnabledButtonSelection()); } public void widgetDefaultSelected(SelectionEvent event) { apply(); - } public void widgetSelected(SelectionEvent event) { @@ -181,6 +194,25 @@ public class RepositoryLocationPart { } } + public void setEnabled(boolean enabled) { + if (!enabled) { + enabledButton.setEnabled(false); + setInputFieldsEnabled(false); + } else { + enabledButton.setEnabled(true); + updateWidgetEnablement(); + } + } + + private void setInputFieldsEnabled(boolean enabled) { + userText.setEnabled(enabled); + passwordText.setEnabled(enabled); + if (domainText != null) { + domainText.setEnabled(enabled); + } + savePasswordButton.setEnabled(enabled); + } + } protected static final String PREFS_PAGE_ID_NET_PROXY = "org.eclipse.ui.net.NetPreferences"; //$NON-NLS-1$ @@ -237,12 +269,13 @@ public class RepositoryLocationPart { } } - private void bind(AuthenticationType authType, Button anonymousButton, Text userText, Text passwordText, - Button savePasswordButton, boolean reverseEnablement) { + private UsernamePasswordListener bind(AuthenticationType<UserCredentials> authType, Button anonymousButton, + Text userText, Text passwordText, Text domainText, Button savePasswordButton, boolean reverseEnablement) { UsernamePasswordListener listener = new UsernamePasswordListener(authType, anonymousButton, userText, - passwordText, savePasswordButton); + passwordText, domainText, savePasswordButton); listener.setEnablementReversed(reverseEnablement); listener.restore(); + return listener; } protected void bind(Button button, String property) { @@ -333,7 +366,7 @@ public class RepositoryLocationPart { private void createHttpAuthSection(SectionComposite parent) { int style = SWT.NONE; - if (getWorkingCopy().getCredentials(AuthenticationType.HTTP, UsernamePasswordCredentials.class) != null) { + if (getWorkingCopy().getCredentials(AuthenticationType.HTTP, false) != null) { style |= ExpandableComposite.EXPANDED; } ExpandableComposite section = parent.createSection(Messages.RepositoryLocationPart_HTTP_Authentication, style); @@ -364,11 +397,16 @@ public class RepositoryLocationPart { Button savePasswordButton = new Button(composite, SWT.CHECK); savePasswordButton.setText(Messages.RepositoryLocationPart_Save_Password); - bind(AuthenticationType.HTTP, enableButton, userText, passwordText, savePasswordButton, false); + bind(AuthenticationType.HTTP, enableButton, userText, passwordText, null, savePasswordButton, false); } private void createProxySection(final SectionComposite parent) { - ExpandableComposite section = parent.createSection(Messages.RepositoryLocationPart_Proxy_Server_Configuration); + int style = SWT.NONE; + if (!Boolean.parseBoolean(getWorkingCopy().getProperty(RepositoryLocation.PROPERTY_PROXY_USEDEFAULT))) { + style |= ExpandableComposite.EXPANDED; + } + ExpandableComposite section = parent.createSection(Messages.RepositoryLocationPart_Proxy_Server_Configuration, + style); Composite composite = new Composite(section, SWT.NONE); section.setClient(composite); @@ -376,15 +414,9 @@ public class RepositoryLocationPart { Label label; - Button systemProxyButton = new Button(composite, SWT.CHECK); + final Button systemProxyButton = new Button(composite, SWT.CHECK); GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(systemProxyButton); systemProxyButton.setText(Messages.RepositoryLocationPart_Use_global_Network_Connections_preferences); -// systemProxyButton.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent e) { -// updateProxyEnablement(systemProxyButton.getSelection()); -// } -// }); bind(systemProxyButton, RepositoryLocation.PROPERTY_PROXY_USEDEFAULT); Link changeProxySettingsLink = new Link(composite, SWT.NONE); @@ -401,14 +433,14 @@ public class RepositoryLocationPart { label = new Label(composite, SWT.NONE); label.setText(Messages.RepositoryLocationPart_Proxy_Host); - Text proxyHostText = new Text(composite, SWT.BORDER); + final Text proxyHostText = new Text(composite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(proxyHostText); bind(proxyHostText, RepositoryLocation.PROPERTY_PROXY_HOST); label = new Label(composite, SWT.NONE); label.setText(Messages.RepositoryLocationPart_Proxy_Port); - Text proxyPortText = new Text(composite, SWT.BORDER | SWT.PASSWORD); + final Text proxyPortText = new Text(composite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(proxyPortText); bind(proxyPortText, RepositoryLocation.PROPERTY_PROXY_PORT); @@ -433,7 +465,22 @@ public class RepositoryLocationPart { Button savePasswordButton = new Button(composite, SWT.CHECK); savePasswordButton.setText(Messages.RepositoryLocationPart_Save_Password); - bind(AuthenticationType.PROXY, enableButton, userText, passwordText, savePasswordButton, false); + final UsernamePasswordListener listener = bind(AuthenticationType.PROXY, enableButton, userText, passwordText, + null, savePasswordButton, false); + systemProxyButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateProxyEnablement(listener, proxyPortText, proxyHostText, !systemProxyButton.getSelection()); + } + }); + updateProxyEnablement(listener, proxyPortText, proxyHostText, !systemProxyButton.getSelection()); + } + + protected void updateProxyEnablement(UsernamePasswordListener listener, Text hostText, Text portText, + boolean selected) { + hostText.setEnabled(selected); + portText.setEnabled(selected); + listener.setEnabled(selected); } protected void createSections(SectionComposite sectionComposite) { @@ -487,7 +534,7 @@ public class RepositoryLocationPart { Button savePasswordButton = new Button(parent, SWT.CHECK); savePasswordButton.setText(Messages.RepositoryLocationPart_Save_Password); - bind(AuthenticationType.REPOSITORY, anonymousButton, userText, passwordText, savePasswordButton, true); + bind(AuthenticationType.REPOSITORY, anonymousButton, userText, passwordText, null, savePasswordButton, true); } public <T> T getContainer(Class<T> clazz) { diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryPropertyPage.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryPropertyPage.java index 41f57f87..e2bc31bc 100644 --- a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryPropertyPage.java +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryPropertyPage.java @@ -11,8 +11,6 @@ package org.eclipse.mylyn.commons.repositories.ui; -import java.util.UUID; - import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.DialogPage; @@ -49,9 +47,7 @@ public class RepositoryPropertyPage extends PropertyPage implements IAdaptable { if (workingCopy == null) { RepositoryLocation element = (RepositoryLocation) getElement().getAdapter(RepositoryLocation.class); workingCopy = new RepositoryLocation(element); - if (workingCopy.getId() == null) { - workingCopy.setProperty(RepositoryLocation.PROPERTY_ID, UUID.randomUUID().toString()); - } + // use an in memory credentials store that is backed by the actual credentials store workingCopy.setCredentialsStore(new InMemoryCredentialsStore(workingCopy.getCredentialsStore())); } return workingCopy; diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryLocationValueProperty.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryLocationValueProperty.java index 5c4efb45..ca295ec7 100644 --- a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryLocationValueProperty.java +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryLocationValueProperty.java @@ -36,12 +36,12 @@ public class RepositoryLocationValueProperty extends SimpleValueProperty { @Override protected void doAddTo(Object source) { - ((RepositoryLocation) source).addChangeListener(this); + ((RepositoryLocation) source).addPropertyChangeListener(this); } @Override protected void doRemoveFrom(Object source) { - ((RepositoryLocation) source).removeChangeListener(this); + ((RepositoryLocation) source).removePropertyChangeListener(this); } public void propertyChange(PropertyChangeEvent evt) { diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/UiLocationService.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/UiLocationService.java new file mode 100644 index 00000000..578a5073 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/UiLocationService.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui; + +import java.net.Proxy; + +import javax.net.ssl.X509TrustManager; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.mylyn.commons.core.CoreUtil; +import org.eclipse.mylyn.commons.core.net.NetUtil; +import org.eclipse.mylyn.commons.core.operations.OperationUtil; +import org.eclipse.mylyn.commons.repositories.core.ILocationService; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore; +import org.eclipse.mylyn.internal.commons.repositories.core.SecureCredentialsStore; +import org.eclipse.mylyn.internal.commons.repositories.ui.auth.RepositoryAuthenticator; + +/** + * @author Steffen Pingel + */ +public class UiLocationService implements ILocationService { + + public UiLocationService() { + } + + public ICredentialsStore getCredentialsStore(String id) { + return new SecureCredentialsStore(id); + } + + public Proxy getProxyForHost(String host, String proxyType) { + return NetUtil.getProxy(host, proxyType); + } + + public X509TrustManager getTrustManager() { + throw new UnsupportedOperationException(); + } + + public <T extends AuthenticationCredentials> T requestCredentials( + AuthenticationRequest<AuthenticationType<T>> request, IProgressMonitor monitor) { + if (CoreUtil.TEST_MODE) { + throw new UnsupportedOperationException(); + } + + if (OperationUtil.isBackgroundMonitor(monitor)) { + throw new UnsupportedOperationException(); + } + + RepositoryAuthenticator<T> requester = new RepositoryAuthenticator<T>(request); + return requester.open(monitor); + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/AbstractCredentialsProviderUi.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/AbstractCredentialsProviderUi.java new file mode 100644 index 00000000..fb6e01a4 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/AbstractCredentialsProviderUi.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui.auth; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Steffen Pingel + */ +public abstract class AbstractCredentialsProviderUi<T extends AuthenticationCredentials> { + + /** + * Opens the credentials UI. Invoked from the UI thread. + * + * @param parentShell + * the parent shell + * @param request + * the authentication request + * @return {@link IStatus#OK} on success; {@link IStatus#CANCEL} on cancellation; an error status otherwise + */ + public abstract IStatus open(Shell parentShell, AuthenticationRequest<AuthenticationType<T>> request); + + /** + * Returns the provided credentials. + */ + public abstract T getCredentials(); + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/CertificateCredentialsProviderUi.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/CertificateCredentialsProviderUi.java new file mode 100644 index 00000000..20ad5d98 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/CertificateCredentialsProviderUi.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui.auth; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.window.Window; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.CertificateCredentials; +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog; +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog.Mode; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Steffen Pingel + */ +public class CertificateCredentialsProviderUi extends AbstractCredentialsProviderUi<CertificateCredentials> { + + private CertificateCredentials credentials; + + @Override + public CertificateCredentials getCredentials() { + return credentials; + } + + @Override + public IStatus open(Shell shell, AuthenticationRequest<AuthenticationType<CertificateCredentials>> request) { + CredentialsDialog dialog = new CredentialsDialog(shell, Mode.USER); + + CertificateCredentials oldCredentials = request.getLocation().getCredentials(request.getAuthenticationType()); + if (oldCredentials != null) { + dialog.setKeyStoreFileName(oldCredentials.getKeyStoreFileName()); + dialog.setPassword(oldCredentials.getPassword()); + } + + // caller provided message takes precedence + if (request.getMessage() != null) { + dialog.setMessage(request.getMessage()); + } else { + dialog.setMessage(getDefaultMessage(request)); + } + + int resultCode = dialog.open(); + if (resultCode == Window.OK) { + credentials = new CertificateCredentials(dialog.getKeyStoreFileName(), dialog.getPassword()); + request.getLocation().setCredentials(request.getAuthenticationType(), oldCredentials); + return Status.OK_STATUS; + } else { + return Status.CANCEL_STATUS; + } + } + + private String getDefaultMessage(AuthenticationRequest<AuthenticationType<CertificateCredentials>> request) { + AuthenticationType<CertificateCredentials> authType = request.getAuthenticationType(); + if (AuthenticationType.CERTIFICATE == authType) { + return "Enter key store password"; + } + return null; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/OpenIdCredentialsProviderUi.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/OpenIdCredentialsProviderUi.java new file mode 100644 index 00000000..297e6ae5 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/OpenIdCredentialsProviderUi.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui.auth; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.OpenIdAuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.OpenIdCredentials; +import org.eclipse.mylyn.commons.workbench.WorkbenchUtil; +import org.eclipse.mylyn.commons.workbench.browser.WebBrowserDialog; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.LocationAdapter; +import org.eclipse.swt.browser.LocationEvent; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Steffen Pingel + */ +public class OpenIdCredentialsProviderUi extends AbstractCredentialsProviderUi<OpenIdCredentials> { + + protected OpenIdCredentials credentials; + + @Override + public IStatus open(Shell parentShell, AuthenticationRequest<AuthenticationType<OpenIdCredentials>> authRequest) { + if (!(authRequest instanceof OpenIdAuthenticationRequest)) { + throw new IllegalArgumentException( + "Extected instanceof OpenIdAuthenticationRequest, got " + authRequest.getClass()); //$NON-NLS-1$ + } + final OpenIdAuthenticationRequest request = (OpenIdAuthenticationRequest) authRequest; + + final WebBrowserDialog dialog = new WebBrowserDialog(WorkbenchUtil.getShell(), "Login", null, + "Login to OpenID Provider", MessageDialog.NONE, new String[] { IDialogConstants.CANCEL_LABEL }, 0); + dialog.create(); + + dialog.getBrowser().addLocationListener(new LocationAdapter() { + @Override + public void changing(LocationEvent event) { + if (event.location != null && event.location.startsWith(request.getReturnUrl())) { + credentials = new OpenIdCredentials(event.location, null); + } + // alternatively check cookies since IE does not notify listeners of redirects + String value = Browser.getCookie(request.getCookie(), request.getCookieUrl()); + if (value != null) { + credentials = new OpenIdCredentials(event.location, value); + } + if (credentials != null) { + event.doit = false; + // delay execution to avoid IE crash + dialog.getBrowser().getDisplay().asyncExec(new Runnable() { + public void run() { + if (dialog.getShell() != null && !dialog.getShell().isDisposed()) { + dialog.close(); + } + } + }); + } + } + }); + + // navigate to login page + dialog.getBrowser().setUrl(request.getRequestUrl() + "?" + getRequestParameters(request)); //$NON-NLS-1$ + + if (dialog.open() == Window.OK) { + return Status.OK_STATUS; + } else { + return Status.CANCEL_STATUS; + } + } + + private String getRequestParameters(final OpenIdAuthenticationRequest request) { + final StringBuilder sb = new StringBuilder(); + try { + for (Map.Entry<String, String> entry : request.getProviderArgs().entrySet()) { + if (sb.length() > 0) { + sb.append("&"); //$NON-NLS-1$ + } + sb.append(URLEncoder.encode(entry.getKey(), "UTF-8")); //$NON-NLS-1$ + sb.append("="); //$NON-NLS-1$ + sb.append(URLEncoder.encode(entry.getValue(), "UTF-8")); //$NON-NLS-1$ + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + return sb.toString(); + } + + @Override + public OpenIdCredentials getCredentials() { + return credentials; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/RepositoryAuthenticator.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/RepositoryAuthenticator.java new file mode 100644 index 00000000..3daad162 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/RepositoryAuthenticator.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui.auth; + +import java.util.concurrent.atomic.AtomicReference; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.mylyn.commons.core.CoreUtil; +import org.eclipse.mylyn.commons.core.StatusHandler; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.CertificateCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.OpenIdCredentials; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; +import org.eclipse.mylyn.commons.workbench.WorkbenchUtil; +import org.eclipse.ui.PlatformUI; + +/** + * @author Steffen Pingel + */ +public class RepositoryAuthenticator<T extends AuthenticationCredentials> { + + private final static Object lock = new Object(); + + private final AuthenticationRequest<AuthenticationType<T>> request; + + public RepositoryAuthenticator(AuthenticationRequest<AuthenticationType<T>> request) { + this.request = request; + } + + public T open(IProgressMonitor monitor) { + AuthenticationCredentials oldCredentials = request.getLocation() + .getCredentials(request.getAuthenticationType()); + // synchronize on a static lock to ensure that only one password dialog is displayed at a time + synchronized (lock) { + // check if the credentials changed while the thread was waiting for the lock + T newCredentials = request.getLocation().getCredentials(request.getAuthenticationType()); + if (!CoreUtil.areEqual(oldCredentials, newCredentials)) { + return newCredentials; + } + + // check if the workbench was closed meanwhile + if (PlatformUI.getWorkbench().getDisplay().isDisposed()) { + throw new UnsupportedOperationException(); + } + + final AtomicReference<IStatus> status = new AtomicReference<IStatus>(); + final AtomicReference<T> requestedCredentials = new AtomicReference<T>(); + + // show dialog + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + AbstractCredentialsProviderUi<T> provider = getCredentialsProviderUi(); + + // open prompt + IStatus result = provider.open(WorkbenchUtil.getShell(), request); + status.set(result); + + requestedCredentials.set(provider.getCredentials()); + } + }); + + if (status.get() == null) { + throw new IllegalStateException(); + } + if (status.get().getSeverity() == IStatus.CANCEL) { + throw new OperationCanceledException(); + } + if (!status.get().isOK()) { + StatusHandler.log(status.get()); + throw new UnsupportedOperationException(); + } + + return requestedCredentials.get(); + } + } + + protected AbstractCredentialsProviderUi<T> getCredentialsProviderUi() { + Class<T> credentialsType = request.getAuthenticationType().getCredentialsType(); + if (credentialsType == UserCredentials.class) { + return (AbstractCredentialsProviderUi<T>) new UserCredentialsProviderUi(); + } else if (credentialsType == CertificateCredentials.class) { + return (AbstractCredentialsProviderUi<T>) new CertificateCredentialsProviderUi(); + } else if (credentialsType == OpenIdCredentials.class) { + return (AbstractCredentialsProviderUi<T>) new OpenIdCredentialsProviderUi(); + } + return null; + } + +} diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/UserCredentialsProviderUi.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/UserCredentialsProviderUi.java new file mode 100644 index 00000000..3b759f91 --- /dev/null +++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/auth/UserCredentialsProviderUi.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.commons.repositories.ui.auth; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.window.Window; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType; +import org.eclipse.mylyn.commons.repositories.core.auth.UserAuthenticationRequest; +import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials; +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog; +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog.Mode; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Steffen Pingel + */ +public class UserCredentialsProviderUi extends AbstractCredentialsProviderUi<UserCredentials> { + + private UserCredentials credentials; + + @Override + public UserCredentials getCredentials() { + return credentials; + } + + @Override + public IStatus open(Shell shell, AuthenticationRequest<AuthenticationType<UserCredentials>> request) { + CredentialsDialog dialog = new CredentialsDialog(shell, Mode.USER); + + UserCredentials oldCredentials = request.getLocation().getCredentials(request.getAuthenticationType()); + if (oldCredentials != null) { + dialog.setUsername(oldCredentials.getUserName()); + dialog.setDomain((oldCredentials.getDomain() != null) ? oldCredentials.getDomain() : ""); //$NON-NLS-1$ + dialog.setPassword(oldCredentials.getPassword()); + dialog.setSavePassword(oldCredentials.getSavePassword()); + } + + if (request instanceof UserAuthenticationRequest) { + dialog.setNeedsDomain(((UserAuthenticationRequest) request).needsDomain()); + } + + dialog.create(); + + dialog.setTitle(NLS.bind("Credentials for {0}", request.getLocation().getLabel())); + // caller provided message takes precedence + if (request.getMessage() != null) { + dialog.setMessage(request.getMessage()); + } else { + dialog.setMessage(getDefaultMessage(request)); + } + + int resultCode = dialog.open(); + if (resultCode == Window.OK) { + credentials = new UserCredentials(dialog.getUserName(), dialog.getPassword(), dialog.getDomain(), + dialog.getSavePassword()); + request.getLocation().setCredentials(request.getAuthenticationType(), credentials); + if (request.getAuthenticationType() == AuthenticationType.REPOSITORY) { + request.getLocation().setUserName(dialog.getUserName()); + } + return Status.OK_STATUS; + } else { + return Status.CANCEL_STATUS; + } + } + + private String getDefaultMessage(AuthenticationRequest<AuthenticationType<UserCredentials>> request) { + AuthenticationType<UserCredentials> authType = request.getAuthenticationType(); + if (AuthenticationType.REPOSITORY == authType) { + return "Enter repository credentials"; + } else if (AuthenticationType.HTTP == authType) { + return "Enter HTTP credentials"; + } else if (AuthenticationType.PROXY == authType) { + return "Enter proxy credentials"; + } + return null; + } + +} diff --git a/org.eclipse.mylyn.commons.sdk-feature/feature.xml b/org.eclipse.mylyn.commons.sdk-feature/feature.xml index 3181072b..ef235659 100644 --- a/org.eclipse.mylyn.commons.sdk-feature/feature.xml +++ b/org.eclipse.mylyn.commons.sdk-feature/feature.xml @@ -375,4 +375,18 @@ version="0.0.0" unpack="false"/> + <plugin + id="org.apache.httpcomponents.httpcore" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.apache.httpcomponents.httpclient" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature> diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java index 5a77c60e..931e4aaa 100644 --- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java @@ -14,11 +14,13 @@ package org.eclipse.mylyn.commons.tests; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.mylyn.commons.tests.core.AuthenticatedProxyTest; import org.eclipse.mylyn.commons.tests.core.CoreUtilTest; import org.eclipse.mylyn.commons.tests.net.NetUtilTest; import org.eclipse.mylyn.commons.tests.net.SslProtocolSocketFactoryTest; import org.eclipse.mylyn.commons.tests.net.TimeoutInputStreamTest; import org.eclipse.mylyn.commons.tests.net.WebUtilTest; +import org.eclipse.mylyn.commons.tests.operations.OperationUtilTest; /** * @author Mik Kersten @@ -28,6 +30,8 @@ public class AllCommonsTests { public static Test suite() { TestSuite suite = new TestSuite(AllCommonsTests.class.getName()); suite.addTestSuite(CoreUtilTest.class); + suite.addTestSuite(AuthenticatedProxyTest.class); + suite.addTestSuite(OperationUtilTest.class); suite.addTestSuite(NetUtilTest.class); suite.addTestSuite(SslProtocolSocketFactoryTest.class); suite.addTestSuite(WebUtilTest.class); diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/AuthenticatedProxyTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/AuthenticatedProxyTest.java new file mode 100644 index 00000000..db945651 --- /dev/null +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/AuthenticatedProxyTest.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.tests.core; + +import java.net.InetSocketAddress; +import java.net.Proxy; + +import junit.framework.TestCase; + +import org.eclipse.mylyn.commons.core.net.AuthenticatedProxy; + +/** + * @author Steffen Pingel + */ +public class AuthenticatedProxyTest extends TestCase { + + public void testConstructor() { + AuthenticatedProxy proxy = new AuthenticatedProxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080), + "user", "pass", "domain"); + assertEquals("user", proxy.getUserName()); + assertEquals("pass", proxy.getPassword()); + assertEquals("domain", proxy.getDomain()); + } + +} diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java index e0531885..f0109151 100644 --- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java @@ -76,4 +76,33 @@ public class CoreUtilTest extends TestCase { assertFalse(CoreUtil.propertyEquals(true, "true")); } + public void testAreEqualEqualStrings() { + assertTrue(CoreUtil.areEqual("a", "a")); + } + + public void testAreEqualSameObject() { + Object o = new Object(); + assertTrue(CoreUtil.areEqual(o, o)); + } + + public void testAreEqualNull() { + assertTrue(CoreUtil.areEqual(null, null)); + } + + public void testAreEqualRightNotNull() { + assertFalse(CoreUtil.areEqual(null, new Object())); + } + + public void testAreEqualLeftNotNull() { + assertFalse(CoreUtil.areEqual(new Object(), null)); + } + + public void testAreEqualUnequalObject() { + assertFalse(CoreUtil.areEqual(1, "a")); + } + + public void testAreEqualUnequalStrings() { + assertFalse(CoreUtil.areEqual("a", "b")); + } + } diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/NoticicationPopupMain.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/NoticicationPopupMain.java index b425d29e..6c7d0d8c 100644 --- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/NoticicationPopupMain.java +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/NoticicationPopupMain.java @@ -49,4 +49,5 @@ public class NoticicationPopupMain { } } } + } diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/TestCredentialsDialog.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/TestCredentialsDialog.java new file mode 100644 index 00000000..7a825fe5 --- /dev/null +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/manual/TestCredentialsDialog.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.tests.manual; + +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog; +import org.eclipse.mylyn.commons.ui.dialogs.CredentialsDialog.Mode; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Steffen Pingel + */ +public class TestCredentialsDialog { + + public static void main(String[] args) { + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setText("Test Credentials Dialog"); + shell.setLayout(new RowLayout()); + + Button userButton = new Button(shell, SWT.PUSH); + userButton.setText("Username/Password"); + userButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + CredentialsDialog dialog = new CredentialsDialog(shell, Mode.USER); + dialog.create(); + dialog.setMessage("Enter password"); + dialog.open(); + System.err.println("User name: " + dialog.getUserName()); + System.err.println("Password: " + dialog.getPassword()); + System.err.println("Save password: " + dialog.getSavePassword()); + } + }); + + Button domainButton = new Button(shell, SWT.PUSH); + domainButton.setText("Domain"); + domainButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + CredentialsDialog dialog = new CredentialsDialog(shell, Mode.USER); + dialog.setNeedsDomain(true); + dialog.create(); + dialog.setMessage("Enter password"); + dialog.open(); + System.err.println("User name: " + dialog.getUserName()); + System.err.println("Password: " + dialog.getPassword()); + System.err.println("Domain: " + dialog.getDomain()); + System.err.println("Save password: " + dialog.getSavePassword()); + } + }); + + Button keyStoreButton = new Button(shell, SWT.PUSH); + keyStoreButton.setText("Key Store"); + keyStoreButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + CredentialsDialog dialog = new CredentialsDialog(shell, Mode.KEY_STORE); + dialog.create(); + dialog.setMessage("Enter keystore location"); + dialog.open(); + System.err.println("Key store filename: " + dialog.getKeyStoreFileName()); + System.err.println("Password: " + dialog.getPassword()); + System.err.println("Save password: " + dialog.getSavePassword()); + } + }); + + shell.pack(); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } +} diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/operations/OperationUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/operations/OperationUtilTest.java new file mode 100644 index 00000000..420bcbdd --- /dev/null +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/operations/OperationUtilTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.tests.operations; + +import junit.framework.TestCase; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; +import org.eclipse.mylyn.commons.core.operations.IOperationMonitor.OperationFlag; +import org.eclipse.mylyn.commons.core.operations.OperationUtil; +import org.eclipse.mylyn.commons.net.Policy; + +/** + * @author Steffen Pingel + */ +public class OperationUtilTest extends TestCase { + + public void testIsBackgroundMonitorNull() { + assertFalse(OperationUtil.isBackgroundMonitor(null)); + } + + public void testIsBackgroundMonitorProgressMonitor() { + assertFalse(OperationUtil.isBackgroundMonitor(new NullProgressMonitor())); + } + + public void testIsBackgroundMonitorBackgroundMonitor() { + assertTrue(OperationUtil.isBackgroundMonitor(Policy.backgroundMonitorFor(new NullProgressMonitor()))); + } + + public void testIsBackgroundMonitorOperationMonitorNull() { + assertFalse(OperationUtil.isBackgroundMonitor(OperationUtil.convert(null))); + } + + public void testIsBackgroundMonitorOperationMonitorProgressMonitor() { + assertFalse(OperationUtil.isBackgroundMonitor(OperationUtil.convert(new NullProgressMonitor()))); + } + + public void testIsBackgroundMonitorOperationMonitorBackground() { + IOperationMonitor monitor = OperationUtil.convert(new NullProgressMonitor()); + monitor.addFlag(OperationFlag.BACKGROUND); + assertTrue(OperationUtil.isBackgroundMonitor(monitor)); + monitor.removeFlag(OperationFlag.BACKGROUND); + assertFalse(OperationUtil.isBackgroundMonitor(monitor)); + } + + public void testIsBackgroundMonitorOperationMonitorChild() { + IOperationMonitor monitor = OperationUtil.convert(new NullProgressMonitor()); + monitor.addFlag(OperationFlag.BACKGROUND); + assertTrue(OperationUtil.isBackgroundMonitor(monitor)); + + IOperationMonitor child = monitor.newChild(1); + assertTrue(OperationUtil.isBackgroundMonitor(child)); + monitor.removeFlag(OperationFlag.BACKGROUND); + assertFalse(OperationUtil.isBackgroundMonitor(child)); + } + + public void testConvert() { + assertNotNull(OperationUtil.convert(null)); + } + +} diff --git a/org.eclipse.mylyn.commons.ui/icons/wizban/secur_role_wiz.gif b/org.eclipse.mylyn.commons.ui/icons/wizban/secur_role_wiz.gif Binary files differnew file mode 100644 index 00000000..e05db64d --- /dev/null +++ b/org.eclipse.mylyn.commons.ui/icons/wizban/secur_role_wiz.gif diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/CommonImages.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/CommonImages.java index e46190ee..66ffa2db 100644 --- a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/CommonImages.java +++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/CommonImages.java @@ -23,6 +23,7 @@ import org.eclipse.mylyn.internal.commons.ui.CompositeElementImageDescriptor; import org.eclipse.mylyn.internal.commons.ui.CompositeSyncImageDescriptor; import org.eclipse.mylyn.internal.commons.ui.TaskListImageDescriptor; import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Bundle; /** * @author Mik Kersten @@ -30,7 +31,23 @@ import org.eclipse.swt.graphics.Image; */ public class CommonImages { - private static final URL baseURL = Platform.getBundle(CommonsUiConstants.ID_PLUGIN).getEntry("/icons/"); //$NON-NLS-1$ + private static final URL baseUrl; + + static { + Bundle bundle = Platform.getBundle(CommonsUiConstants.ID_PLUGIN); + if (bundle != null) { + baseUrl = bundle.getEntry("/icons/"); //$NON-NLS-1$ + } else { + URL iconsUrl = null; + try { + // lookup location of CommonImages class on disk + iconsUrl = new URL(CommonImages.class.getResource("CommonImages.class"), "../../../../../../icons/"); //$NON-NLS-1$ //$NON-NLS-2$ + } catch (MalformedURLException e) { + // ignore + } + baseUrl = iconsUrl; + } + } private static ImageRegistry imageRegistry; @@ -151,6 +168,8 @@ public class CommonImages { public static final ImageDescriptor BANNER_EXPORT = create(T_WIZBAN, "banner-export.gif"); //$NON-NLS-1$ + public static final ImageDescriptor BANNER_SECURE_ROLE = create(T_WIZBAN, "secur_role_wiz.gif"); //$NON-NLS-1$ + // Discovery public static final ImageDescriptor DISCOVERY = create(T_TOOL, "discovery.png"); //$NON-NLS-1$ @@ -401,14 +420,14 @@ public class CommonImages { } private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { - if (baseURL == null) { + if (baseUrl == null) { throw new MalformedURLException(); } StringBuffer buffer = new StringBuffer(prefix); buffer.append('/'); buffer.append(name); - return new URL(baseURL, buffer.toString()); + return new URL(baseUrl, buffer.toString()); } private static Image[] progressImages; diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/dialogs/CredentialsDialog.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/dialogs/CredentialsDialog.java new file mode 100644 index 00000000..2e5d0912 --- /dev/null +++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/dialogs/CredentialsDialog.java @@ -0,0 +1,295 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Frank Becker 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + * Tasktop Technologies - improvements + * BREDEX GmbH - fix for bug 295050 + *******************************************************************************/ + +package org.eclipse.mylyn.commons.ui.dialogs; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.mylyn.commons.ui.CommonImages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * A dialog that prompts for credentials. The dialog support two modes: + * <ul> + * <li>Username/password authentication</li> + * <li>Key store authentication</li> + * </ul> + * + * @author Frank Becker + * @author Steffen Pingel + * @author Torsten Kalix + * @since 3.7 + */ +public class CredentialsDialog extends TitleAreaDialog { + + public enum Mode { + KEY_STORE, USER, + }; + + private String domain; + + private Image keyLockImage; + + private String keyStoreFileName; + + private final Mode mode; + + private boolean needsDomain; + + private String password; + + private boolean savePassword; + + private String username; + + public CredentialsDialog(Shell parentShell, Mode mode) { + super(parentShell); + this.mode = mode; + this.domain = ""; //$NON-NLS-1$ + this.username = ""; //$NON-NLS-1$ + this.password = ""; //$NON-NLS-1$ + this.keyStoreFileName = ""; //$NON-NLS-1$ + } + + @Override + public boolean close() { + if (keyLockImage != null) { + keyLockImage.dispose(); + } + return super.close(); + } + + public String getDomain() { + return domain; + } + + public String getKeyStoreFileName() { + return keyStoreFileName; + } + + public Mode getMode() { + return mode; + } + + public String getPassword() { + return password; + } + + public boolean getSavePassword() { + return savePassword; + } + + public String getUserName() { + return username; + } + + public boolean needsDomain() { + return needsDomain; + } + + public void setDomain(String domain) { + Assert.isNotNull(domain); + this.domain = domain; + } + + public void setKeyStoreFileName(String keyStoreFileName) { + Assert.isNotNull(this.keyStoreFileName); + this.keyStoreFileName = keyStoreFileName; + } + + public void setNeedsDomain(boolean needsDomain) { + this.needsDomain = needsDomain; + } + + public void setPassword(String password) { + Assert.isNotNull(password); + this.password = password; + } + + public void setSavePassword(boolean savePassword) { + this.savePassword = savePassword; + } + + public void setUsername(String username) { + Assert.isNotNull(username); + this.username = username; + } + + private void createCenterArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(3, false)); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + if (mode == Mode.USER) { + createUserControls(composite); + } else if (mode == Mode.KEY_STORE) { + createKeyStoreControls(composite); + } + + createPasswordControls(composite); + } + + private void createKeyStoreControls(Composite composite) { + new Label(composite, SWT.NONE).setText("Key Store:"); + + final Text keyStoreField = new Text(composite, SWT.BORDER); + keyStoreField.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + keyStoreFileName = keyStoreField.getText(); + } + }); + keyStoreField.setText(keyStoreFileName); + if (keyStoreFileName.length() == 0) { + keyStoreField.setFocus(); + } + GridDataFactory.fillDefaults() + .align(SWT.FILL, SWT.CENTER) + .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) + .grab(true, false) + .applyTo(keyStoreField); + + Button browseButton = new Button(composite, SWT.PUSH); + browseButton.setText("Browse..."); + browseButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); + if (keyStoreFileName != null) { + fileDialog.setFilterPath(System.getProperty("user.home", ".")); //$NON-NLS-1$ //$NON-NLS-2$ + } + String returnFile = fileDialog.open(); + if (returnFile != null) { + username = returnFile; + keyStoreField.setText(returnFile); + } + } + }); + } + + private void createPasswordControls(Composite composite) { + new Label(composite, SWT.NONE).setText("Password:"); + + final Text passwordField = new Text(composite, SWT.BORDER | SWT.PASSWORD); + passwordField.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + password = passwordField.getText(); + } + }); + passwordField.setText(password); + if (username.length() > 0) { + passwordField.setFocus(); + } + GridDataFactory.fillDefaults() + .align(SWT.FILL, SWT.CENTER) + .span(2, 1) + .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) + .grab(true, false) + .applyTo(passwordField); + + final Button savePasswordButton = new Button(composite, SWT.CHECK); + savePasswordButton.setText("Save Password"); + savePasswordButton.setSelection(savePassword); + savePasswordButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + savePassword = savePasswordButton.getSelection(); + } + }); + GridDataFactory.fillDefaults().span(3, 1).applyTo(savePasswordButton); + } + + private void createUserControls(Composite composite) { + new Label(composite, SWT.NONE).setText("Username:"); + + final Text usernameText = new Text(composite, SWT.BORDER); + usernameText.setText(username); + usernameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + username = usernameText.getText(); + } + }); + if (username.length() == 0) { + usernameText.setFocus(); + } + GridDataFactory.fillDefaults() + .align(SWT.FILL, SWT.CENTER) + .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) + .span(2, 1) + .grab(true, false) + .applyTo(usernameText); + + if (needsDomain()) { + new Label(composite, SWT.NONE).setText("Domain:"); + + final Text domainText = new Text(composite, SWT.BORDER); + domainText.setText(domain); + domainText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + domain = domainText.getText(); + } + }); + GridDataFactory.fillDefaults() + .align(SWT.FILL, SWT.CENTER) + .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT) + .span(2, 1) + .grab(true, false) + .applyTo(domainText); + } + } + + @Override + protected Control createContents(Composite parent) { + getShell().setText("Enter credentials"); + setTitle("Authentication"); + setMessage(getMessage()); + + Control control = super.createContents(parent); + + keyLockImage = CommonImages.BANNER_SECURE_ROLE.createImage(); + setTitleImage(keyLockImage); + + applyDialogFont(control); + return control; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite parent2 = (Composite) super.createDialogArea(parent); + + Composite composite = new Composite(parent2, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(composite); + + createCenterArea(composite); + + composite.pack(); + return parent; + } + +} diff --git a/org.eclipse.mylyn.commons.workbench/src/org/eclipse/mylyn/commons/workbench/forms/SectionComposite.java b/org.eclipse.mylyn.commons.workbench/src/org/eclipse/mylyn/commons/workbench/forms/SectionComposite.java index 30a39ff4..c45819b7 100644 --- a/org.eclipse.mylyn.commons.workbench/src/org/eclipse/mylyn/commons/workbench/forms/SectionComposite.java +++ b/org.eclipse.mylyn.commons.workbench/src/org/eclipse/mylyn/commons/workbench/forms/SectionComposite.java @@ -69,7 +69,7 @@ public class SectionComposite extends SharedScrolledComposite { } public ExpandableComposite createSection(String title, int expansionStyle) { - return createSection(title, SWT.NONE, false); + return createSection(title, expansionStyle, false); } public ExpandableComposite createSection(String title, int expansionStyle, final boolean grabExcessVerticalSpace) { @@ -65,6 +65,7 @@ <module>org.eclipse.mylyn.commons.notifications.ui</module> <module>org.eclipse.mylyn.commons.repositories-feature</module> <module>org.eclipse.mylyn.commons.repositories.core</module> + <module>org.eclipse.mylyn.commons.repositories.tests</module> <module>org.eclipse.mylyn.commons.repositories.ui</module> <module>org.eclipse.mylyn.commons.repositories.http-feature</module> <module>org.eclipse.mylyn.commons.repositories.http.core</module> |