use of com.centurylink.mdw.auth.AuthenticationException in project mdw-designer by CenturyLinkCloud.
the class DesignerProxy method handleLazyUserAuth.
private void handleLazyUserAuth() throws AuthenticationException {
if (project.isFilePersist() && !project.isRemote()) {
// authentication not needed
project.setUser(new User(System.getProperty("user.name")));
} else {
// user authentication
Boolean authenticated = project.isAuthenticated();
if (authenticated == null)
throw new AuthenticationException("Not authorized for project: " + project.getName());
if (!authenticated) {
LoginDialog loginDialog = new LoginDialog(MdwPlugin.getShell(), project);
int res = loginDialog.open();
if (res == Dialog.CANCEL || !project.isAuthenticated())
throw new AuthenticationException("Not authorized for project: " + project.getName());
}
}
}
use of com.centurylink.mdw.auth.AuthenticationException 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