diff options
author | Siva Velusamy <vsiva@google.com> | 2011-11-12 15:00:59 -0800 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2011-11-12 15:15:56 -0800 |
commit | cefde2307aa8737fccc756c3b69c3d7ca3e53e8b (patch) | |
tree | 5e991158c7253e4a6768ea17ac28d819ef6c6a8a /sdkmanager/libs/sdkuilib | |
parent | 0ff515a76142ce48794bdfb098df37f899886535 (diff) | |
download | sdk-cefde2307aa8737fccc756c3b69c3d7ca3e53e8b.zip sdk-cefde2307aa8737fccc756c3b69c3d7ca3e53e8b.tar.gz sdk-cefde2307aa8737fccc756c3b69c3d7ca3e53e8b.tar.bz2 |
Add support for NTLM proxy authentication.
Change-Id: Ia8375444bf99b33396616a57e781adb22d82175d
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
6 files changed, 138 insertions, 62 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java index bd4bb01..3fe5bff 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java @@ -22,6 +22,7 @@ import com.android.sdklib.internal.repository.ITask; import com.android.sdklib.internal.repository.ITaskFactory; import com.android.sdklib.internal.repository.ITaskMonitor; import com.android.sdklib.internal.repository.NullTaskMonitor; +import com.android.sdklib.internal.repository.UserCredentials; import com.android.sdklib.repository.SdkRepoConstants; import com.android.util.Pair; @@ -360,11 +361,14 @@ public class SdkUpdaterNoWindow { * <b>second element</b> is always the <b>Password</b>. This * method will never return null, in case of error the pair will * be filled with empty strings. - * @see ITaskMonitor#displayLoginPasswordPrompt(String, String) + * @see ITaskMonitor#displayLoginCredentialsPrompt(String, String) */ - public Pair<String, String> displayLoginPasswordPrompt(String title, String message) { + public UserCredentials displayLoginCredentialsPrompt(String title, String message) { String login = ""; //$NON-NLS-1$ String password = ""; //$NON-NLS-1$ + String workstation = ""; //$NON-NLS-1$ + String domain = ""; //$NON-NLS-1$ + mSdkLog.printf("\n%1$s\n%2$s", title, message); byte[] readBuffer = new byte[2048]; try { @@ -372,6 +376,12 @@ public class SdkUpdaterNoWindow { login = readLine(readBuffer); mSdkLog.printf("\nPassword: "); password = readLine(readBuffer); + mSdkLog.printf("\nIf your proxy uses NTLM authentication, provide the following information. Leave blank otherwise."); + mSdkLog.printf("\nWorkstation: "); + workstation = readLine(readBuffer); + mSdkLog.printf("\nDomain: "); + domain = readLine(readBuffer); + /* * TODO: Implement a way to don't echo the typed password On * Java 5 there's no simple way to do this. There's just a @@ -382,11 +392,13 @@ public class SdkUpdaterNoWindow { // Reset login/pass to empty Strings. login = ""; //$NON-NLS-1$ password = ""; //$NON-NLS-1$ + workstation = ""; //$NON-NLS-1$ + domain = ""; //$NON-NLS-1$ //Just print the error to console. mSdkLog.printf("\nError occurred during login/pass query: %s\n", e.getMessage()); } - return Pair.of(login, password); + return new UserCredentials(login, password, workstation, domain); } private String readLine(byte[] buffer) throws IOException { @@ -504,8 +516,8 @@ public class SdkUpdaterNoWindow { return mRoot.displayPrompt(title, message); } - public Pair<String, String> displayLoginPasswordPrompt(String title, String message) { - return mRoot.displayLoginPasswordPrompt(title, message); + public UserCredentials displayLoginCredentialsPrompt(String title, String message) { + return mRoot.displayLoginCredentialsPrompt(title, message); } public ITaskMonitor createSubMonitor(int tickCount) { diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java index 1eca704..dc4f3ba 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java @@ -17,7 +17,7 @@ package com.android.sdkuilib.internal.tasks; import com.android.sdklib.internal.repository.ITaskMonitor; -import com.android.util.Pair; +import com.android.sdklib.internal.repository.UserCredentials; import org.eclipse.swt.widgets.ProgressBar; @@ -73,19 +73,14 @@ interface IProgressUiProvider extends ILogUiProvider { public abstract boolean displayPrompt(String title, String message); /** - * Launch an interface which asks for login and password. Implementations + * Launch an interface which asks for login credentials. Implementations * MUST allow this to be called from any thread, e.g. by making sure the * dialog is opened synchronously in the UI thread. * * @param title The title of the dialog box. * @param message The message to be displayed as an instruction. - * @return Returns a {@link Pair} holding the entered login and password. - * The information must always be in the following order: - * Login,Password. So in order to retrieve the <b>login</b> callers - * should retrieve the first element, and the second value for the - * <b>password</b>. This method should never return a null pair. - * It's elements however can be empty Strings + * @return Returns user provided credentials */ - public abstract Pair<String, String> displayLoginPasswordPrompt(String title, String message); + public UserCredentials displayLoginCredentialsPrompt(String title, String message); } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTaskDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTaskDialog.java index dbc871f..d01466b 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTaskDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressTaskDialog.java @@ -18,6 +18,7 @@ package com.android.sdkuilib.internal.tasks; import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.repository.ITaskMonitor;
+import com.android.sdklib.internal.repository.UserCredentials;
import com.android.sdkuilib.ui.AuthenticationDialog;
import com.android.sdkuilib.ui.GridDialog;
import com.android.util.Pair;
@@ -408,31 +409,46 @@ final class ProgressTaskDialog extends Dialog implements IProgressUiProvider { * should retrieve the first element, and the second value for the
* <b>password</b>.
* If operation is <b>canceled</b> by user the return value must be <b>null</b>.
- * @see ITaskMonitor#displayLoginPasswordPrompt(String, String)
+ * @see ITaskMonitor#displayLoginCredentialsPrompt(String, String)
*/
- public Pair<String, String> displayLoginPasswordPrompt(
+ public UserCredentials displayLoginCredentialsPrompt(
final String title, final String message) {
- final String[] resultArray = new String[2];
Display display = mDialogShell.getDisplay();
// open dialog and request login and password
- display.syncExec(new Runnable() {
- public void run() {
- AuthenticationDialog authenticationDialog = new AuthenticationDialog(mDialogShell,
- title,
- message);
- int dlgResult= authenticationDialog.open();
- if(dlgResult == GridDialog.OK) {
- resultArray[0] = authenticationDialog.getLogin();
- resultArray[1] = authenticationDialog.getPassword();
- } else {
- resultArray[0] = null;
- resultArray[1] = null;
- }
- }
- });
+ GetUserCredentialsTask task = new GetUserCredentialsTask(mDialogShell, title, message);
+ display.syncExec(task);
+
+ return new UserCredentials(task.userName, task.password, task.workstation, task.domain);
+ }
- return resultArray[0] == null ? null : Pair.of(resultArray[0], resultArray[1]);
+ private static class GetUserCredentialsTask implements Runnable {
+ public String userName = null;
+ public String password = null;
+ public String workstation = null;
+ public String domain = null;
+
+ private Shell mShell;
+ private String mTitle;
+ private String mMessage;
+
+ public GetUserCredentialsTask(Shell shell, String title, String message) {
+ mShell = shell;
+ mTitle = title;
+ mMessage = message;
+ }
+
+ public void run() {
+ AuthenticationDialog authenticationDialog = new AuthenticationDialog(mShell,
+ mTitle, mMessage);
+ int dlgResult= authenticationDialog.open();
+ if(dlgResult == GridDialog.OK) {
+ userName = authenticationDialog.getLogin();
+ password = authenticationDialog.getPassword();
+ workstation = authenticationDialog.getWorkstation();
+ domain = authenticationDialog.getDomain();
+ }
+ }
}
/**
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java index d4eb362..3361a58 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java @@ -18,9 +18,9 @@ package com.android.sdkuilib.internal.tasks; import com.android.sdklib.internal.repository.ITask;
import com.android.sdklib.internal.repository.ITaskMonitor;
+import com.android.sdklib.internal.repository.UserCredentials;
import com.android.sdkuilib.ui.AuthenticationDialog;
import com.android.sdkuilib.ui.GridDialog;
-import com.android.util.Pair;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
@@ -309,22 +309,17 @@ public final class ProgressView implements IProgressUiProvider { } /**
- * This method opens a pop-up window which requests for User Login and
- * password.
+ * This method opens a pop-up window which requests for User Credentials.
*
* @param title The title of the window.
* @param message The message to displayed in the login/password window.
- * @return Returns a {@link Pair} holding the entered login and password.
- * The information must always be in the following order:
- * Login,Password. So in order to retrieve the <b>login</b> callers
- * should retrieve the first element, and the second value for the
- * <b>password</b>.
+ * @return Returns user provided credentials.
* If operation is <b>canceled</b> by user the return value must be <b>null</b>.
- * @see ITaskMonitor#displayLoginPasswordPrompt(String, String)
+ * @see ITaskMonitor#displayLoginCredentialsPrompt(String, String)
*/
- public Pair<String, String>
- displayLoginPasswordPrompt(final String title, final String message) {
- final String[] resultArray = new String[] {"", ""};
+ public UserCredentials
+ displayLoginCredentialsPrompt(final String title, final String message) {
+ final String[] resultArray = new String[] {"", "", "", ""};
// open dialog and request login and password
syncExec(mProgressBar, new Runnable() {
public void run() {
@@ -336,13 +331,16 @@ public final class ProgressView implements IProgressUiProvider { if (dlgResult == GridDialog.OK) {
resultArray[0] = authenticationDialog.getLogin();
resultArray[1] = authenticationDialog.getPassword();
- } else {
- resultArray[0] = null;
- resultArray[1] = null;
+ resultArray[2] = authenticationDialog.getWorkstation();
+ resultArray[3] = authenticationDialog.getDomain();
}
}
});
- return resultArray[0] == null ? null : Pair.of(resultArray[0], resultArray[1]);
- }
+ return new UserCredentials(resultArray[0],
+ resultArray[1],
+ resultArray[2],
+ resultArray[3]);
+ }
}
+
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/TaskMonitorImpl.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/TaskMonitorImpl.java index bb2991c..ff207c5 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/TaskMonitorImpl.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/TaskMonitorImpl.java @@ -17,7 +17,7 @@ package com.android.sdkuilib.internal.tasks;
import com.android.sdklib.internal.repository.ITaskMonitor;
-import com.android.util.Pair;
+import com.android.sdklib.internal.repository.UserCredentials;
/**
* Internal class that implements the logic of an {@link ITaskMonitor}.
@@ -177,8 +177,8 @@ class TaskMonitorImpl implements ITaskMonitor { * element and Password is always the second. If any error occurs a
* pair with empty strings is returned.
*/
- public Pair<String, String> displayLoginPasswordPrompt(String title, String message) {
- return mUi.displayLoginPasswordPrompt(title, message);
+ public UserCredentials displayLoginCredentialsPrompt(String title, String message) {
+ return mUi.displayLoginCredentialsPrompt(title, message);
}
/**
@@ -297,8 +297,8 @@ class TaskMonitorImpl implements ITaskMonitor { return mRoot.displayPrompt(title, message);
}
- public Pair<String, String> displayLoginPasswordPrompt(String title, String message) {
- return mRoot.displayLoginPasswordPrompt(title, message);
+ public UserCredentials displayLoginCredentialsPrompt(String title, String message) {
+ return mRoot.displayLoginCredentialsPrompt(title, message);
}
public ITaskMonitor createSubMonitor(int tickCount) {
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/AuthenticationDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/AuthenticationDialog.java index 497c752..10e2e6e 100644 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/AuthenticationDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/AuthenticationDialog.java @@ -30,18 +30,18 @@ import org.eclipse.swt.widgets.Text; * Dialog which collects from the user his/her login and password. */ public class AuthenticationDialog extends GridDialog { - private Text mTxtLogin; - private Text mTxtPassword; + private Text mTxtWorkstation; + private Text mTxtDomain; private String mTitle; - private String mMessage; - protected String mLogin; - - protected String mPassword; + private String mLogin; + private String mPassword; + private String mWorkstation; + private String mDomain; /** * Constructor which retrieves the parent {@link Shell} and the message to @@ -92,7 +92,7 @@ public class AuthenticationDialog extends GridDialog { mTxtLogin.setFocus(); mTxtLogin.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent arg0) { - mLogin = mTxtLogin.getText(); + mLogin = mTxtLogin.getText().trim(); } }); @@ -110,6 +110,43 @@ public class AuthenticationDialog extends GridDialog { mPassword = mTxtPassword.getText(); } }); + + // add a label indicating that the following two fields are optional + Label lblInfo = new Label(upperComposite, SWT.NONE); + lblInfo.setText("Provide the following info if your proxy uses NTLM authentication. Leave blank otherwise."); + data = new GridData(); + data.horizontalSpan = 2; + lblInfo.setLayoutData(data); + + // add workstation label and text field + Label lblWorkstation = new Label(upperComposite, SWT.NONE); + lblWorkstation.setText("Workstation:"); + data = new GridData(SWT.LEFT, SWT.CENTER, false, false); + lblWorkstation.setLayoutData(data); + + mTxtWorkstation = new Text(upperComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.CENTER, true, false); + mTxtWorkstation.setLayoutData(data); + mTxtWorkstation.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + mWorkstation = mTxtWorkstation.getText().trim(); + } + }); + + // add domain label and text field + Label lblDomain = new Label(upperComposite, SWT.NONE); + lblDomain.setText("Domain:"); + data = new GridData(SWT.LEFT, SWT.CENTER, false, false); + lblDomain.setLayoutData(data); + + mTxtDomain = new Text(upperComposite, SWT.SINGLE | SWT.BORDER); + data = new GridData(SWT.FILL, SWT.CENTER, true, false); + mTxtDomain.setLayoutData(data); + mTxtDomain.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + mDomain = mTxtDomain.getText().trim(); + } + }); } /** @@ -129,4 +166,22 @@ public class AuthenticationDialog extends GridDialog { public String getPassword() { return mPassword != null ? mPassword : ""; //$NON-NLS-1$ } + + /** + * Retrieves the workstation field information + * + * @return Workstation field value or empty String. Return value is never null + */ + public String getWorkstation() { + return mWorkstation != null ? mWorkstation : ""; + } + + /** + * Retrieves the domain field information + * + * @return Domain field value or empty String. Return value is never null + */ + public String getDomain() { + return mDomain != null ? mDomain : ""; + } } |