Author: adietish
Date: 2012-02-16 12:11:50 -0500 (Thu, 16 Feb 2012)
New Revision: 38836
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftPasswordStorageKey.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SecurePasswordStore.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
Log:
[JBIDE-10936]
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftPasswordStorageKey.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftPasswordStorageKey.java 2012-02-16
16:58:10 UTC (rev 38835)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/OpenShiftPasswordStorageKey.java 2012-02-16
17:11:50 UTC (rev 38836)
@@ -29,7 +29,7 @@
private String userName;
public OpenShiftPasswordStorageKey(String platform, String userName) {
- this.userName = userName;
+ this.userName = platform;
this.platform = userName;
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SecurePasswordStore.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SecurePasswordStore.java 2012-02-16
16:58:10 UTC (rev 38835)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/SecurePasswordStore.java 2012-02-16
17:11:50 UTC (rev 38836)
@@ -52,7 +52,7 @@
update(storageKey, password);
}
- private void update(IStorageKey key, String password) throws
SecurePasswordStoreException {
+ public void update(IStorageKey key, String password) throws SecurePasswordStoreException
{
if (!storageKey.equals(key) || isPasswordChanged(password)) {
storeInPreferences(this.password = password, this.storageKey = key);
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2012-02-16
16:58:10 UTC (rev 38835)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2012-02-16
17:11:50 UTC (rev 38836)
@@ -30,13 +30,11 @@
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Text;
@@ -49,9 +47,6 @@
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;
-import com.openshift.express.client.IUser;
-import com.openshift.express.client.OpenShiftException;
-
/**
* @author Andre Dietisheim
* @author Xavier Coulon
@@ -61,16 +56,14 @@
protected static final String OPENSHIFT_EXPRESS_SIGNUP_URL =
"https://openshift.redhat.com/app/user/new/express"; //$NON-NLS-1$
private final CredentialsWizardPageModel pageModel;
-
- private final IUserAwareModel wizardModel;
private Text rhLoginText = null;
private Text passwordText = null;
public CredentialsWizardPage(IWizard wizard, IUserAwareModel wizardModel) {
- super("OpenShift Connection", "Please provide your OpenShift Express
credentials.", "Server Connection", wizard);
+ super("Server connection", "Please provide your OpenShift Express
credentials.", "Server Connection",
+ wizard);
this.pageModel = new CredentialsWizardPageModel(wizardModel);
- this.wizardModel = wizardModel;
}
protected void doCreateControls(Composite container, DataBindingContext dbc) {
@@ -78,38 +71,45 @@
Link signupLink = new Link(container, SWT.WRAP);
signupLink.setText("If you do not have an account on OpenShift Express, please
sign up <a>here</a>.");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2,
1).applyTo(signupLink);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(signupLink);
signupLink.addSelectionListener(onSignupLinkClicked());
Label fillerLabel = new Label(container, SWT.NONE);
- GridDataFactory.fillDefaults().span(2, 1).hint(SWT.DEFAULT, 6).applyTo(fillerLabel);
+ GridDataFactory.fillDefaults()
+ .span(2, 1).hint(SWT.DEFAULT, 6).applyTo(fillerLabel);
Label rhLoginLabel = new Label(container, SWT.NONE);
rhLoginLabel.setText("&Username");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(rhLoginLabel);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(rhLoginLabel);
rhLoginText = new Text(container, SWT.BORDER);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1,
1).applyTo(rhLoginText);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(rhLoginText);
UIUtils.selectAllOnFocus(rhLoginText);
- final IObservableValue rhLoginObservable =
BeanProperties.value(CredentialsWizardPageModel.PROPERTY_RHLOGIN)
- .observe(pageModel);
+ final IObservableValue rhLoginObservable =
+ BeanProperties.value(CredentialsWizardPageModel.PROPERTY_RHLOGIN).observe(pageModel);
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(rhLoginText),
rhLoginObservable);
Label passwordLabel = new Label(container, SWT.NONE);
passwordLabel.setText("&Password");
- GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);
+ GridDataFactory.fillDefaults()
+ .align(SWT.LEFT, SWT.CENTER).applyTo(passwordLabel);
passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1,
1).applyTo(passwordText);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(passwordText);
UIUtils.selectAllOnFocus(passwordText);
- final IObservableValue passwordModelObservable = BeanProperties.value(
- CredentialsWizardPageModel.PROPERTY_PASSWORD).observe(pageModel);
+ final IObservableValue passwordModelObservable =
+ BeanProperties.value(CredentialsWizardPageModel.PROPERTY_PASSWORD).observe(pageModel);
final ISWTObservableValue passwordTextObservable =
WidgetProperties.text(SWT.Modify).observe(passwordText);
dbc.bindValue(passwordTextObservable, passwordModelObservable);
- IObservableValue credentialsStatusObservable = BeanProperties.value(
- CredentialsWizardPageModel.PROPERTY_CREDENTIALS_STATUS).observe(pageModel);
- dbc.addValidationStatusProvider(new CredentialsInputValidator(rhLoginObservable,
passwordModelObservable));
- final CredentialsStatusValidator credentialsStatusValidator = new
CredentialsStatusValidator(
- credentialsStatusObservable, passwordTextObservable);
+ IObservableValue credentialsStatusObservable =
+ BeanProperties.value(CredentialsWizardPageModel.PROPERTY_CREDENTIALS_STATUS).observe(pageModel);
+ dbc.addValidationStatusProvider(
+ new CredentialsInputValidator(rhLoginObservable, passwordModelObservable));
+ final CredentialsStatusValidator credentialsStatusValidator =
+ new CredentialsStatusValidator(credentialsStatusObservable, passwordTextObservable);
dbc.addValidationStatusProvider(credentialsStatusValidator);
ControlDecorationSupport.create(credentialsStatusValidator, SWT.LEFT | SWT.TOP);
@@ -117,11 +117,12 @@
// the text fields
Button rememberPasswordCheckBox = new Button(container, SWT.CHECK);
rememberPasswordCheckBox.setText("Save password (could trigger secure storage
login)");
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(rememberPasswordCheckBox);
- final IObservableValue rememberPasswordModelObservable = BeanProperties.value(
- CredentialsWizardPageModel.PROPERTY_REMEMBER_PASSWORD).observe(pageModel);
- final ISWTObservableValue rememberPasswordCheckBoxObservable =
WidgetProperties.selection().observe(
- rememberPasswordCheckBox);
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(rememberPasswordCheckBox);
+ final IObservableValue rememberPasswordModelObservable =
+ BeanProperties.value(CredentialsWizardPageModel.PROPERTY_REMEMBER_PASSWORD).observe(pageModel);
+ final ISWTObservableValue rememberPasswordCheckBoxObservable =
+ WidgetProperties.selection().observe(rememberPasswordCheckBox);
dbc.bindValue(rememberPasswordCheckBoxObservable, rememberPasswordModelObservable);
}
@@ -145,7 +146,8 @@
@Override
protected void onPageActivated(DataBindingContext dbc) {
super.onPageActivated(dbc);
- if (pageModel.getRhLogin() == null || pageModel.getRhLogin().isEmpty() &&
rhLoginText != null) {
+ if (StringUtils.isEmpty(pageModel.getRhLogin())
+ && rhLoginText != null) {
rhLoginText.setFocus();
} else if (passwordText != null) {
passwordText.setFocus();
@@ -191,7 +193,8 @@
private final IObservableValue passwordObservable;
- public CredentialsInputValidator(IObservableValue rhLoginObservable, IObservableValue
passwordObservable) {
+ public CredentialsInputValidator(IObservableValue rhLoginObservable,
+ IObservableValue passwordObservable) {
this.rhLoginObservable = rhLoginObservable;
this.passwordObservable = passwordObservable;
}
@@ -202,7 +205,8 @@
// something..
final String rhLoginValue = (String) rhLoginObservable.getValue();
final String passwordValue = (String) passwordObservable.getValue();
- if (!StringUtils.isEmpty(rhLoginValue) && !StringUtils.isEmpty(passwordValue))
{
+ if (!StringUtils.isEmpty(rhLoginValue)
+ && !StringUtils.isEmpty(passwordValue)) {
return ValidationStatus.ok();
}
return ValidationStatus.cancel("Please provide your OpenShift Express user
credentials");
@@ -226,8 +230,7 @@
final IStatus credentialsValidityStatus = (IStatus)
credentialsStatusObservable.getValue();
if (credentialsValidityStatus != null) {
- final IStatus credentialsValidity = pageModel.getCredentialsStatus();
- return credentialsValidity;
+ return pageModel.getCredentialsStatus();
}
return ValidationStatus.ok();
}
@@ -238,7 +241,5 @@
targets.add(passwordTextObservable);
return targets;
}
-
}
-
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2012-02-16
16:58:10 UTC (rev 38835)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2012-02-16
17:11:50 UTC (rev 38836)
@@ -50,13 +50,15 @@
private SecurePasswordStore store;
private IUserAwareModel wizardModel;
+
+ private OpenShiftPasswordStorageKey key;
public CredentialsWizardPageModel(IUserAwareModel wizardModel) {
this.wizardModel = wizardModel;
this.rhLoginPreferenceValue = new StringPreferenceValue(RHLOGIN_PREFS_KEY,
OpenShiftUIActivator.PLUGIN_ID);
this.libraServer = initLibraServer();
this.rhLogin = initRhLogin();
- this.store = initSecureStore(libraServer, rhLogin);
+ initSecureStore(libraServer, rhLogin);
this.password = initPassword();
resetCredentialsStatus();
}
@@ -70,33 +72,36 @@
return null;
}
- private SecurePasswordStore initSecureStore(final String platform, final String rhLogin)
{
- SecurePasswordStore store = null;
- final OpenShiftPasswordStorageKey key = new OpenShiftPasswordStorageKey(platform,
rhLogin);
- if (key != null) {
- store = new SecurePasswordStore(key);
- }
- return store;
+ private void initSecureStore(final String platform, final String rhLogin) {
+ this.key = new OpenShiftPasswordStorageKey(platform, rhLogin);
+ this.store = new SecurePasswordStore(key);
}
protected String initRhLogin() {
String rhLogin = null;
+
IUser user = wizardModel.getUser();
+ if (user == null) {
+ user = UserModel.getDefault().getRecentUser();
+ }
if (user != null) {
rhLogin = user.getRhlogin();
} else {
rhLogin = rhLoginPreferenceValue.get();
- if (rhLogin == null || rhLogin.length() == 0) {
+ if (rhLogin == null
+ || rhLogin.length() == 0) {
rhLogin = getConfiguredUserName();
}
}
+
return rhLogin;
}
-
+
protected String initPassword() {
String password = null;
if (!StringUtils.isEmpty(libraServer)
- && !StringUtils.isEmpty(rhLogin) && store != null) {
+ && !StringUtils.isEmpty(rhLogin)
+ && store != null) {
try {
password = store.getPassword();
setRememberPassword(!StringUtils.isEmpty(password));
@@ -107,10 +112,11 @@
return password;
}
- private void storePassword(String password) {
+ private void storePassword(IUser user) {
try {
if (store != null) {
- store.setPassword(password);
+ OpenShiftPasswordStorageKey key = new OpenShiftPasswordStorageKey(libraServer,
user.getRhlogin());
+ store.update(key, password);
}
} catch (SecurePasswordStoreException e) {
Logger.error(e.getMessage(), e);
@@ -226,7 +232,7 @@
private void storeUser(IUser user) {
wizardModel.setUser(user);
if (rememberPassword) {
- storePassword(password);
+ storePassword(user);
} else {
erasePasswordStore();
}