Author: rob.stryker(a)jboss.com
Date: 2012-02-17 04:32:10 -0500 (Fri, 17 Feb 2012)
New Revision: 38862
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegator.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/RequiredCredentialsDialog.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/UserPassCredentialProvider.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IUserModelListener.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
Log:
JBIDE-10908 - any user with an empty password should prompt for password before doing any
operations.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/RequiredCredentialsDialog.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/RequiredCredentialsDialog.java 2012-02-17
07:55:47 UTC (rev 38861)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/dialogs/RequiredCredentialsDialog.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -25,7 +25,6 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
import org.jboss.ide.eclipse.as.ui.Messages;
import org.jboss.ide.eclipse.as.ui.UIUtil;
@@ -37,18 +36,28 @@
public static final int IGNORE_ID = IDialogConstants.CLIENT_ID | 3;
private String user, pass;
private boolean save;
- private JBossServer jbs;
-
- public RequiredCredentialsDialog(Shell parentShell, JBossServer jbs) {
+ private boolean canModifyUser = true;
+ private String description;
+ public RequiredCredentialsDialog(Shell parentShell, String initialUser, String
initialPass) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
- this.jbs = jbs;
+ this.user = initialUser;
+ this.pass = initialPass;
+ this.description = Messages.credentials_warning;
}
+ public void setCanModifyUser(boolean val) {
+ canModifyUser = val;
+ }
+
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(Messages.RequiredCredentialsDialog_ShellText);
}
+
+ public void setDescription(String desc) {
+ this.description = desc;
+ }
protected Control createDialogArea(Composite parent) {
Composite c = (Composite) super.createDialogArea(parent);
@@ -74,7 +83,7 @@
passText.setLayoutData(u.createFormData(passLabel, 5, null, 0, 0,5, 100, -5));
saveCredentials.setLayoutData(u.createFormData(passText, 10, null, 0, 0,5, 100, -5));
- top.setText(Messages.credentials_warning);
+ top.setText(description);
userLabel.setText(Messages.swf_Username);
passLabel.setText(Messages.swf_Password);
saveCredentials.setText(Messages.credentials_save);
@@ -101,11 +110,13 @@
saveCredentials.addSelectionListener(listener2);
// defaults
- userText.setText(jbs.getUsername());
- userText.setSelection(0, jbs.getUsername() == null ? 0 : jbs.getUsername().length());
- passText.setText(jbs.getPassword());
+ userText.setText(user);
+ userText.setSelection(0, user == null ? 0 : user.length());
+ passText.setText(pass);
// save by default
saveCredentials.setSelection(true);
+
+ userText.setEnabled(canModifyUser);
return c;
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/UserPassCredentialProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/UserPassCredentialProvider.java 2012-02-17
07:55:47 UTC (rev 38861)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/launch/UserPassCredentialProvider.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -56,7 +56,10 @@
IServer server = inNeed.getServer();
IServerWorkingCopy copy = server.createWorkingCopy();
JBossServer jbs = ServerConverter.getJBossServer(copy);
- RequiredCredentialsDialog d = new RequiredCredentialsDialog(new Shell(), jbs);
+ String initialUser = jbs.getUsername();
+ String initialPass = jbs.getPassword();
+ RequiredCredentialsDialog d = new RequiredCredentialsDialog(
+ new Shell(), initialUser, initialPass);
if( d.open() == Window.OK) {
if( d.getSave() ) {
jbs.setPassword(d.getPass());
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IPasswordPrompter.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.core.console;
+
+import com.openshift.express.client.IUser;
+
+public interface IPasswordPrompter {
+ public String getPasswordFor(IUser user);
+}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IUserModelListener.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IUserModelListener.java 2012-02-17
07:55:47 UTC (rev 38861)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/IUserModelListener.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.openshift.express.internal.core.console;
import com.openshift.express.client.IUser;
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegator.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegator.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserDelegator.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.core.console;
+
+import java.util.List;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.ICartridge;
+import com.openshift.express.client.IDomain;
+import com.openshift.express.client.IEmbeddableCartridge;
+import com.openshift.express.client.ISSHPublicKey;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+public class UserDelegator implements IUser {
+ private IUser delegate;
+ public UserDelegator(IUser user) {
+ this.delegate = user;
+ }
+
+ public String getRhlogin() {
+ return delegate.getRhlogin();
+ }
+ public String getPassword() {
+ return delegate.getPassword();
+ }
+ protected void checkForPassword() {
+ if( delegate.getPassword() == null || "".equals(delegate.getPassword())) {
+ try {
+ String newPw = UserModel.promptForPassword(this);
+ delegate = UserModel.getDefault().createUser(delegate.getRhlogin(), newPw);
+ } catch( Exception e ) {
+ // TODO log handle everything
+ }
+ }
+ }
+
+ public IApplication createApplication(String arg0, ICartridge arg1)
+ throws OpenShiftException {
+ checkForPassword();
+ return delegate.createApplication(arg0, arg1);
+ }
+
+ public IDomain createDomain(String arg0, ISSHPublicKey arg1)
+ throws OpenShiftException {
+ checkForPassword();
+ return delegate.createDomain(arg0, arg1);
+ }
+ public IApplication getApplicationByName(String arg0)
+ throws OpenShiftException {
+ checkForPassword();
+ return delegate.getApplicationByName(arg0);
+ }
+ public List<IApplication> getApplications() throws OpenShiftException {
+ checkForPassword();
+ return delegate.getApplications();
+ }
+ public List<IApplication> getApplicationsByCartridge(ICartridge arg0)
+ throws OpenShiftException {
+ checkForPassword();
+ return delegate.getApplicationsByCartridge(arg0);
+ }
+ public String getAuthIV() {
+ checkForPassword();
+ return delegate.getAuthIV();
+ }
+ public String getAuthKey() {
+ checkForPassword();
+ return delegate.getAuthKey();
+ }
+ public ICartridge getCartridgeByName(String arg0) throws OpenShiftException {
+ checkForPassword();
+ return delegate.getCartridgeByName(arg0);
+ }
+ public List<ICartridge> getCartridges() throws OpenShiftException {
+ checkForPassword();
+ return delegate.getCartridges();
+ }
+ public IDomain getDomain() throws OpenShiftException {
+ checkForPassword();
+ return delegate.getDomain();
+ }
+ public List<IEmbeddableCartridge> getEmbeddableCartridges()
+ throws OpenShiftException {
+ checkForPassword();
+ return delegate.getEmbeddableCartridges();
+ }
+ public ISSHPublicKey getSshKey() throws OpenShiftException {
+ checkForPassword();
+ return delegate.getSshKey();
+ }
+ public String getUUID() throws OpenShiftException {
+ checkForPassword();
+ return delegate.getUUID();
+ }
+ public boolean hasApplication(String arg0) throws OpenShiftException {
+ checkForPassword();
+ return delegate.hasApplication(arg0);
+ }
+ public boolean hasApplication(ICartridge arg0) throws OpenShiftException {
+ checkForPassword();
+ return delegate.hasApplication(arg0);
+ }
+ public boolean hasDomain() throws OpenShiftException {
+ checkForPassword();
+ return delegate.hasDomain();
+ }
+ public boolean isValid() throws OpenShiftException {
+ checkForPassword();
+ return delegate.isValid();
+ }
+ public void refresh() throws OpenShiftException {
+ checkForPassword();
+ delegate.refresh();
+ }
+}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java 2012-02-17
07:55:47 UTC (rev 38861)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/console/UserModel.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -41,6 +41,14 @@
return model;
}
+ private static IPasswordPrompter prompter;
+ public static void setPasswordPrompt(IPasswordPrompter prompt) {
+ prompter =prompt;
+ }
+ public static String promptForPassword(IUser user) {
+ return prompter == null ? null : prompter.getPasswordFor(user);
+ }
+
/** The most recent user connected on OpenShift. */
private IUser recentUser = null;
private HashMap<String, IUser> allUsers = new HashMap<String, IUser>();
@@ -139,7 +147,7 @@
try {
String password = getPasswordFromSecureStorage(users[i]);
IUser u = createUser(users[i], password);
- addUser(u);
+ addUser(new UserDelegator(u));
} catch (OpenShiftException ose) {
// TODO
} catch (IOException ioe) {
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2012-02-17
07:55:47 UTC (rev 38861)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2012-02-17
09:32:10 UTC (rev 38862)
@@ -8,16 +8,23 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.ide.eclipse.as.ui.dialogs.RequiredCredentialsDialog;
+import org.jboss.tools.openshift.express.internal.core.console.IPasswordPrompter;
import org.jboss.tools.openshift.express.internal.core.console.UserModel;
import org.osgi.framework.BundleContext;
+import com.openshift.express.client.IUser;
+
/**
* The activator class controls the plug-in life cycle
*/
-public class OpenShiftUIActivator extends AbstractUIPlugin {
+public class OpenShiftUIActivator extends AbstractUIPlugin implements IPasswordPrompter
{
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.openshift.express.ui";
//$NON-NLS-1$
@@ -41,6 +48,7 @@
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ UserModel.setPasswordPrompt(this);
}
/*
@@ -117,4 +125,21 @@
URL imageFileUrl = FileLocator.find(this.getBundle(), imageFilePath, null);
return ImageDescriptor.createFromURL(imageFileUrl);
}
+
+ public String getPasswordFor(final IUser user) {
+ final String[] val =new String[1];
+ val[0] = null;
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ Shell shell = Display.getDefault().getActiveShell();
+ RequiredCredentialsDialog d = new RequiredCredentialsDialog(shell, user.getRhlogin(),
user.getPassword());
+ d.setCanModifyUser(false);
+ d.setDescription("Provide enter the password for your express server");
+ if( d.open() == Window.OK) {
+ val[0] = d.getPass();
+ }
+ }
+ });
+ return val[0];
+ }
}