Author: xcoulon
Date: 2012-02-09 06:54:01 -0500 (Thu, 09 Feb 2012)
New Revision: 38543
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/CredentialsWizardPageModel.java
Log:
FIXED - openshift should provide a "remember password" option
https://issues.jboss.org/browse/JBIDE-10693
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-09
11:11:41 UTC (rev 38542)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2012-02-09
11:54:01 UTC (rev 38543)
@@ -100,10 +100,16 @@
ControlDecorationSupport.create(credentialsStatusValidator, SWT.LEFT | SWT.TOP);
new Label(container, SWT.NONE); // filler to align the checkbox under the text fields
- Button rememberMeCheckBox = new Button(container, SWT.CHECK);
- rememberMeCheckBox.setText("Save password (could trigger secure storage
login)");
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true,
false).applyTo(rememberMeCheckBox);
+ 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);
+ dbc.bindValue(rememberPasswordCheckBoxObservable, rememberPasswordModelObservable);
+
+
Link signupLink = new Link(container, SWT.WRAP);
signupLink.setText("If you don't have an account on OpenShift, please sign up
<a>here</a>.");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).hint(SWT.DEFAULT,
30).applyTo(signupLink);
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-09
11:11:41 UTC (rev 38542)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2012-02-09
11:54:01 UTC (rev 38543)
@@ -38,9 +38,11 @@
public static final String PROPERTY_RHLOGIN = "rhLogin";
public static final String PROPERTY_PASSWORD = "password";
public static final String PROPERTY_CREDENTIALS_STATUS = "credentialsStatus";
+ public static final String PROPERTY_REMEMBER_PASSWORD = "rememberPassword";
private String rhLogin;
private String password;
+ private boolean rememberPassword;
private IStatus credentialsStatus;
private StringPreferenceValue rhLoginPreferenceValue;
private final String libraServer;
@@ -52,7 +54,7 @@
this.libraServer = initLibraServer();
this.rhLogin = initRhLogin();
initSecureStore(libraServer, rhLogin);
- this.password = initPassword();
+ initPassword();
resetCredentialsStatus();
}
@@ -65,12 +67,13 @@
return null;
}
- private SecurePasswordStore initSecureStore(final String platform, final String
username) {
+ private void initSecureStore(final String platform, final String username) {
final OpenShiftPasswordStorageKey key = new OpenShiftPasswordStorageKey(platform,
username);
- store = new SecurePasswordStore(key);
- return store;
+ if (key != null) {
+ this.store = new SecurePasswordStore(key);
+ }
}
-
+
protected String initRhLogin() {
String rhLogin = null;
rhLogin = rhLoginPreferenceValue.get();
@@ -80,24 +83,36 @@
return rhLogin;
}
- protected String initPassword() {
- if (libraServer != null && rhLogin != null && !rhLogin.isEmpty()
&& store!= null) {
+ protected void initPassword() {
+ if (libraServer != null && rhLogin != null && !rhLogin.isEmpty()
&& store != null) {
try {
- return store.getPassword();
+ this.password = store.getPassword();
+ setRememberPassword(this.password != null && !this.password.isEmpty());
} catch (SecurePasswordStoreException e) {
Logger.error("Failed to retrieve OpenShift user's password from Secured
Store", e);
}
}
- return null;
}
private void storePassword(String password) {
try {
- store.setPassword(password);
+ if (store != null) {
+ store.setPassword(password);
+ }
} catch (SecurePasswordStoreException e) {
Logger.error(e.getMessage(), e);
}
}
+
+ private void erasePasswordStore() {
+ try {
+ if (store != null) {
+ store.remove();
+ }
+ } catch (SecurePasswordStoreException e) {
+ Logger.error(e.getMessage(), e);
+ }
+ }
protected String getUserConfiguration() {
String configuredUsername = null;
@@ -132,6 +147,21 @@
}
}
+ /**
+ * @return the rememberPassword
+ */
+ public boolean isRememberPassword() {
+ return rememberPassword;
+ }
+
+ /**
+ * @param rememberPassword
+ * the rememberPassword to set
+ */
+ public void setRememberPassword(boolean rememberPassword) {
+ firePropertyChange(PROPERTY_REMEMBER_PASSWORD, this.rememberPassword,
this.rememberPassword = rememberPassword);
+ }
+
private void resetCredentialsStatus() {
setCredentialsStatus(null);
}
@@ -159,8 +189,10 @@
// reset without notifying
// this.credentialsValidity = null;
IUser user = OpenShiftUIActivator.getDefault().createUser(getRhLogin(),
getPassword());
- if (user.isValid()) {
+ if (user.isValid() && rememberPassword) {
storePassword(password);
+ } else if(user.isValid() && !rememberPassword) {
+ erasePasswordStore();
}
} catch (NotFoundOpenShiftException e) {
// valid user without domain
@@ -174,4 +206,5 @@
setCredentialsStatus(status);
return status;
}
+
}