Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2002-01-08 16:40:37 +0000
committerMichael Valenta2002-01-08 16:40:37 +0000
commit1592826e89e518ecb20175bee7d0253a251b846e (patch)
tree7177fb74aae6471aa00eebd23b2cc43c8a626bb3 /bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java
parent4aff5b7f8ccdac6eb39b8396342d25adb477a21e (diff)
downloadeclipse.platform.team-1592826e89e518ecb20175bee7d0253a251b846e.tar.gz
eclipse.platform.team-1592826e89e518ecb20175bee7d0253a251b846e.tar.xz
eclipse.platform.team-1592826e89e518ecb20175bee7d0253a251b846e.zip
Made validateConnection part of ICVSRepositoryLocation API
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java')
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java327
1 files changed, 164 insertions, 163 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java
index 70cae403c..5ed6d2b4c 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java
@@ -1,163 +1,164 @@
-package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
-import org.eclipse.team.ccvs.core.IUserAuthenticator;
-import org.eclipse.team.ccvs.core.IUserInfo;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-
-/**
- * An authenticator that prompts the user for authentication info,
- * and stores the results in the Platform's authentication keyring.
- */
-public class WorkbenchUserAuthenticator implements IUserAuthenticator {
-
- public static final String INFO_PASSWORD = "org.eclipse.team.ccvs.ui.password";
- public static final String INFO_USERNAME = "org.eclipse.team.ccvs.ui.username";
- public static final String AUTH_SCHEME = "";
- public static final URL FAKE_URL;
-
- static {
- URL temp = null;
- try {
- temp = new URL("http://org.eclipse.team.ccvs.ui");
- } catch (MalformedURLException e) {
- }
- FAKE_URL = temp;
- }
- /**
- * WorkbenchUserAuthenticator constructor.
- */
- public WorkbenchUserAuthenticator() {
- super();
- }
- /**
- * @see IUserAuthenticator#authenticateUser
- */
- public boolean authenticateUser(final ICVSRepositoryLocation location, final IUserInfo userinfo, final boolean retry, final String message) throws CVSException {
-
- // first check to see if there is a cached username and password
- if ((!retry) && (retrievePassword(location, userinfo))) {
- return true;
- }
-
- // ask the user for a password
- final String[] result = new String[2];
- Display display = Display.getCurrent();
- if (display != null) {
- promptForPassword(location, userinfo.getUsername(), message, userinfo.isUsernameMutable(), result);
- } else {
- // sync exec in default thread
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- promptForPassword(location, userinfo.getUsername(), message, userinfo.isUsernameMutable(), result);
- }
- });
- }
-
- if (result[0] == null) {
- throw new CVSOperationCancelledException(Policy.bind("WorkbenchUserAuthenticator.cancelled"));
- }
-
- updateAndCache(location, userinfo, result[0], result[1]);
- return true;
- }
- /**
- * Asks the user to enter a password. Places the
- * results in the supplied string[]. result[0] must
- * contain the username, result[1] must contain the password.
- * If the user canceled, both values must be zero.
- *
- * @param location the location to obtain the password for
- * @param username the username
- * @param message a message to display to the user
- * @param userMutable whether the user can be changed in the dialog
- * @param result a String array of length two in which to put the result
- */
- private void promptForPassword(ICVSRepositoryLocation location, String username, String message, boolean userMutable, String[] result) {
- Shell shell = new Shell();
- UserValidationDialog dialog = new UserValidationDialog(shell, location.getLocation(), (username==null)?"":username, message);
- dialog.setUsernameMutable(userMutable);
- dialog.open();
-
- shell.dispose();
- result[0] = dialog.getUsername();
- result[1] = dialog.getPassword();
- }
- /**
- * @see IUserAuthenticator#cachePassword
- */
- public void cachePassword(ICVSRepositoryLocation location, IUserInfo userinfo, String password) throws CVSException {
- updateAndCache(location, userinfo, userinfo.getUsername(), password);
- }
- /**
- * @see IUserAuthenticator#retrievePassword
- */
- public boolean retrievePassword(ICVSRepositoryLocation location, IUserInfo userinfo) throws CVSException {
- Map map = Platform.getAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
- if (map != null) {
- String username = (String) map.get(INFO_USERNAME);
- String password = (String) map.get(INFO_PASSWORD);
- if (password != null) {
- if (userinfo.isUsernameMutable())
- userinfo.setUsername(username);
- userinfo.setPassword(password);
- return true;
- }
- }
- return false;
- }
- /**
- * @see IUserAuthenticator#dispose(IRepositoryLocation)
- */
- public void dispose(ICVSRepositoryLocation location) throws CVSException {
- try {
- Platform.flushAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
- } catch (CoreException e) {
- // We should probably wrap the CoreException here!
- CVSUIPlugin.log(e.getStatus());
- throw new CVSException(e.getStatus());
- }
- }
- /**
- * Updates the pasword in the platform keyring.
- *
- * @param location the repository location
- * @param userinfo the user information
- * @param username the name of the user
- * @param password the password
- * @throws CVSException if a CVS error occurs
- */
- public void updateAndCache(ICVSRepositoryLocation location, IUserInfo userinfo, String username, String password) throws CVSException {
- // put the password into the Platform map
- Map map = Platform.getAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
- if (map == null) {
- map = new java.util.HashMap(10);
- }
- map.put(INFO_USERNAME, username);
- map.put(INFO_PASSWORD, password);
- try {
- Platform.addAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME, map);
- } catch (CoreException e) {
- // We should probably wrap the CoreException here!
- CVSUIPlugin.log(e.getStatus());
- throw new CVSException(e.getStatus());
- }
- if (userinfo.isUsernameMutable()) {
- userinfo.setUsername(username);
- }
- userinfo.setPassword(password);;
- }
-}
+package org.eclipse.team.internal.ccvs.ui;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.ccvs.core.IUserAuthenticator;
+import org.eclipse.team.ccvs.core.IUserInfo;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * An authenticator that prompts the user for authentication info,
+ * and stores the results in the Platform's authentication keyring.
+ */
+public class WorkbenchUserAuthenticator implements IUserAuthenticator {
+
+ public static final String INFO_PASSWORD = "org.eclipse.team.ccvs.ui.password";
+ public static final String INFO_USERNAME = "org.eclipse.team.ccvs.ui.username";
+ public static final String AUTH_SCHEME = "";
+ public static final URL FAKE_URL;
+
+ static {
+ URL temp = null;
+ try {
+ temp = new URL("http://org.eclipse.team.ccvs.ui");
+ } catch (MalformedURLException e) {
+ }
+ FAKE_URL = temp;
+ }
+ /**
+ * WorkbenchUserAuthenticator constructor.
+ */
+ public WorkbenchUserAuthenticator() {
+ super();
+ }
+ /**
+ * @see IUserAuthenticator#authenticateUser
+ */
+ public boolean authenticateUser(final ICVSRepositoryLocation location, final IUserInfo userinfo, final boolean retry, final String message) throws CVSException {
+
+ // first check to see if there is a cached username and password
+ if ((!retry) && (retrievePassword(location, userinfo))) {
+ return true;
+ }
+
+ // ask the user for a password
+ final String[] result = new String[2];
+ Display display = Display.getCurrent();
+ if (display != null) {
+ promptForPassword(location, userinfo.getUsername(), message, userinfo.isUsernameMutable(), result);
+ } else {
+ // sync exec in default thread
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ promptForPassword(location, userinfo.getUsername(), message, userinfo.isUsernameMutable(), result);
+ }
+ });
+ }
+
+ if (result[0] == null) {
+ throw new OperationCanceledException(Policy.bind("WorkbenchUserAuthenticator.cancelled"));
+ }
+
+ updateAndCache(location, userinfo, result[0], result[1]);
+ return true;
+ }
+ /**
+ * Asks the user to enter a password. Places the
+ * results in the supplied string[]. result[0] must
+ * contain the username, result[1] must contain the password.
+ * If the user canceled, both values must be zero.
+ *
+ * @param location the location to obtain the password for
+ * @param username the username
+ * @param message a message to display to the user
+ * @param userMutable whether the user can be changed in the dialog
+ * @param result a String array of length two in which to put the result
+ */
+ private void promptForPassword(ICVSRepositoryLocation location, String username, String message, boolean userMutable, String[] result) {
+ Shell shell = new Shell();
+ UserValidationDialog dialog = new UserValidationDialog(shell, location.getLocation(), (username==null)?"":username, message);
+ dialog.setUsernameMutable(userMutable);
+ dialog.open();
+
+ shell.dispose();
+ result[0] = dialog.getUsername();
+ result[1] = dialog.getPassword();
+ }
+ /**
+ * @see IUserAuthenticator#cachePassword
+ */
+ public void cachePassword(ICVSRepositoryLocation location, IUserInfo userinfo, String password) throws CVSException {
+ updateAndCache(location, userinfo, userinfo.getUsername(), password);
+ }
+ /**
+ * @see IUserAuthenticator#retrievePassword
+ */
+ public boolean retrievePassword(ICVSRepositoryLocation location, IUserInfo userinfo) throws CVSException {
+ Map map = Platform.getAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
+ if (map != null) {
+ String username = (String) map.get(INFO_USERNAME);
+ String password = (String) map.get(INFO_PASSWORD);
+ if (password != null) {
+ if (userinfo.isUsernameMutable())
+ userinfo.setUsername(username);
+ userinfo.setPassword(password);
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * @see IUserAuthenticator#dispose(IRepositoryLocation)
+ */
+ public void dispose(ICVSRepositoryLocation location) throws CVSException {
+ try {
+ Platform.flushAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
+ } catch (CoreException e) {
+ // We should probably wrap the CoreException here!
+ CVSUIPlugin.log(e.getStatus());
+ throw new CVSException(e.getStatus());
+ }
+ }
+ /**
+ * Updates the pasword in the platform keyring.
+ *
+ * @param location the repository location
+ * @param userinfo the user information
+ * @param username the name of the user
+ * @param password the password
+ * @throws CVSException if a CVS error occurs
+ */
+ public void updateAndCache(ICVSRepositoryLocation location, IUserInfo userinfo, String username, String password) throws CVSException {
+ // put the password into the Platform map
+ Map map = Platform.getAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME);
+ if (map == null) {
+ map = new java.util.HashMap(10);
+ }
+ map.put(INFO_USERNAME, username);
+ map.put(INFO_PASSWORD, password);
+ try {
+ Platform.addAuthorizationInfo(FAKE_URL, location.getLocation(), AUTH_SCHEME, map);
+ } catch (CoreException e) {
+ // We should probably wrap the CoreException here!
+ CVSUIPlugin.log(e.getStatus());
+ throw new CVSException(e.getStatus());
+ }
+ if (userinfo.isUsernameMutable()) {
+ userinfo.setUsername(username);
+ }
+ userinfo.setPassword(password);;
+ }
+}

Back to the top