Search in sources :

Example 1 with AuthenticationException

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());
        }
    }
}
Also used : User(com.centurylink.mdw.plugin.User) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) LoginDialog(com.centurylink.mdw.plugin.designer.dialogs.LoginDialog)

Example 2 with AuthenticationException

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;
}
Also used : JSONObject(org.json.JSONObject) ServiceException(com.centurylink.mdw.common.service.ServiceException) HashMap(java.util.HashMap) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) URL(java.net.URL) ServiceException(com.centurylink.mdw.common.service.ServiceException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException)

Aggregations

AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)2 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)1 ServiceException (com.centurylink.mdw.common.service.ServiceException)1 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)1 User (com.centurylink.mdw.plugin.User)1 LoginDialog (com.centurylink.mdw.plugin.designer.dialogs.LoginDialog)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1