use of com.centurylink.mdw.auth.MdwSecurityException in project mdw-designer by CenturyLinkCloud.
the class LoginDialog method createButtonsSection.
private void createButtonsSection(Composite parent) {
// spacer
new Label(parent, SWT.NONE);
// ok
okButton = new Button(parent, SWT.PUSH);
okButton.setText("OK");
GridData data = new GridData(SWT.NONE, SWT.NONE, false, false);
data.widthHint = BUTTON_WIDTH;
data.verticalIndent = 10;
okButton.setLayoutData(data);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
try {
String user = userNameText.getText().trim();
String password = passwordText.getText().trim();
workflowProject.authenticate(user, password, saveCredentialsCheckbox.getSelection());
setReturnCode(OK);
close();
} catch (MdwSecurityException ex) {
messageLabel.setText(ex.getMessage());
}
}
});
}
});
// cancel
cancelButton = new Button(parent, SWT.PUSH);
cancelButton.setText("Cancel");
data = new GridData(SWT.NONE, SWT.NONE, false, false);
data.widthHint = BUTTON_WIDTH;
data.verticalIndent = 10;
cancelButton.setLayoutData(data);
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
}
use of com.centurylink.mdw.auth.MdwSecurityException in project mdw-designer by CenturyLinkCloud.
the class WorkflowProjectManager method authenticate.
/**
* Authenticates using the designated authenticator impl.
*/
public void authenticate(Authenticator authenticator, String user, String password, boolean saveInSecureStore) throws MdwSecurityException {
String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
authenticatedUsers.remove(key);
try {
authenticator.authenticate(user, password);
if (saveInSecureStore) {
try {
ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, user, false);
securePrefs.put(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, password, true);
securePrefs.flush();
} catch (Exception ex) {
// don't prevent user from being authenticated because of
// this
PluginMessages.log(ex);
}
}
if (authenticator instanceof MdwAuthenticator)
authenticatedUsers.put(key, new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken()));
else
authenticatedUsers.put(key, new User(user, password, null));
} catch (MdwSecurityException ex) {
PluginMessages.log(ex);
throw ex;
} catch (Exception ex) {
PluginMessages.log(ex);
throw new MdwSecurityException(ex.getMessage(), ex);
}
}
use of com.centurylink.mdw.auth.MdwSecurityException in project mdw-designer by CenturyLinkCloud.
the class WorkflowProjectManager method getAuthenticatedUser.
/**
* Triggers automatic authentication if credentials are in Eclipse secure
* store.
*/
public User getAuthenticatedUser(Authenticator authenticator) {
String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
User authUser = authenticatedUsers.get(key);
if (authUser == null) {
try {
ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
String user = securePrefs.get(PreferenceConstants.PREFS_MDW_USER + "_" + key, "");
if (user.length() > 0) {
String password = securePrefs.get(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, "");
if (password.length() > 0) {
try {
authenticate(authenticator, user, password, false);
if (authenticator instanceof MdwAuthenticator)
authUser = new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken());
else
authUser = new User(user, password, null);
} catch (MdwSecurityException ex) {
// prevent repeated attempts to auto-authenticate
securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, "", false);
securePrefs.flush();
}
}
}
} catch (Exception ex) {
// just log exception and force user to log in -- if pw expired
// they'll enter the new one
PluginMessages.log(ex);
}
}
return authUser;
}
use of com.centurylink.mdw.auth.MdwSecurityException in project mdw-designer by CenturyLinkCloud.
the class MdwAuthenticator method doAuthentication.
/**
* <p>
* Takes a cuid and pass combination and authenticates against JWT.
* </p>
*
* @param cuid
* @param pass
* @return the JWT access token
*/
public String doAuthentication(String cuid, String pass) throws MdwSecurityException {
String accessToken = null;
try {
if (StringHelper.isEmpty(tokenLocation)) {
throw new MdwSecurityException("Token location is empty, should point to an JWT token location endpoint." + " Unable to authenticate user " + cuid + " with JWT");
}
JSONObject json = new JSONObject();
json.put("user", cuid);
json.put("password", pass);
json.put("appId", appId);
try {
HttpHelper helper = new HttpHelper(new URL(tokenLocation));
Map<String, String> hdrs = new HashMap<>();
hdrs.put("Content-Type", "application/json; charset=utf-8");
helper.setHeaders(hdrs);
String response = helper.post(json.toString());
JSONObject responseJson = new JSONObject(response);
accessToken = responseJson.getString("mdwauth");
if (accessToken == null || accessToken.isEmpty())
throw new IOException("User authentication failed with response:" + responseJson);
} catch (IOException ex) {
throw new ServiceException(ex.getMessage(), ex);
}
} catch (Exception ex) {
String msg = "Unable to authenticate user " + cuid + " with JWT";
throw new AuthenticationException(msg, ex);
}
return accessToken;
}
Aggregations