Search in sources :

Example 6 with PasswordResetParam

use of com.emc.storageos.model.password.PasswordResetParam in project coprhd-controller by CoprHD.

the class PasswordServiceTest method testUpdateUserPasswordEmptyParams.

@Test(expected = BadRequestException.class)
public void testUpdateUserPasswordEmptyParams() {
    PasswordService passwordResource = new PasswordService();
    passwordResource.setPropertiesMetadata(_propertiesMetadata);
    passwordResource.setAuditLogManager(new DummyAuditLogManager());
    PasswordResetParam passwordUpdate = getDummyPasswordReset(LOCAL_ROOT, "", "");
    LocalPasswordHandler ph = getPasswordHandler();
    ph.setLocalUsers(createLocalUsers());
    passwordResource.setPasswordHandler(ph);
    SecurityContext sc = new DummySecurityContext(LOCAL_ROOT);
    passwordResource.setSecurityContext(sc);
    Response res = passwordResource.updateUserPassword(passwordUpdate, false);
}
Also used : Response(javax.ws.rs.core.Response) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam) SecurityContext(javax.ws.rs.core.SecurityContext) LocalPasswordHandler(com.emc.storageos.systemservices.impl.util.LocalPasswordHandler) Test(org.junit.Test)

Example 7 with PasswordResetParam

use of com.emc.storageos.model.password.PasswordResetParam in project coprhd-controller by CoprHD.

the class PasswordServiceTest method testUpdateUserPassword.

@Test
public void testUpdateUserPassword() {
    PasswordService passwordResource = new PasswordService();
    passwordResource.setPropertiesMetadata(_propertiesMetadata);
    passwordResource.setAuditLogManager(new DummyAuditLogManager());
    PasswordResetParam passwordUpdate = getDummyPasswordReset(LOCAL_ROOT, "!changeMe3", "");
    LocalPasswordHandler ph = getDummyLocalPasswordHandler();
    ph.setLocalUsers(createLocalUsers());
    passwordResource.setPasswordHandler(ph);
    SecurityContext sc = new DummySecurityContext(LOCAL_ROOT);
    passwordResource.setSecurityContext(sc);
    Response res = passwordResource.updateUserPassword(passwordUpdate, false);
    int statusCode = res.getStatus();
    Assert.assertTrue("updatePassword failed with code " + statusCode + ": " + res.getEntity().toString(), statusCode == Status.OK.getStatusCode());
    sc = new DummySecurityContext(LOCAL_PROXYUSER);
    passwordResource.setSecurityContext(sc);
    passwordUpdate.setUsername(LOCAL_PROXYUSER);
    res = passwordResource.updateUserPassword(passwordUpdate, false);
    statusCode = res.getStatus();
    Assert.assertTrue("updatePassword failed with code " + statusCode + ": " + res.getEntity().toString(), statusCode == Status.OK.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam) SecurityContext(javax.ws.rs.core.SecurityContext) LocalPasswordHandler(com.emc.storageos.systemservices.impl.util.LocalPasswordHandler) Test(org.junit.Test)

Example 8 with PasswordResetParam

use of com.emc.storageos.model.password.PasswordResetParam in project coprhd-controller by CoprHD.

the class Password method reset.

/**
 * Change a given local user's password. The authenticated caller must have
 * SEC_ADMIN role.
 * <p>
 * API Call: PUT /password/reset
 *
 * @param username The local user name
 * @param password Clear text or encrypted password
 * @param encrypted If true, the provided password is encrypted
 * @param logoutUser If true, logout the user after updating the password
 */
public void reset(String username, String password, boolean encrypted, boolean logoutUser) {
    PasswordResetParam param = new PasswordResetParam();
    param.setUsername(username);
    if (encrypted) {
        param.setEncPassword(password);
    } else {
        param.setPassword(password);
    }
    client.putURI(String.class, param, client.uriBuilder(UPDATE_PASSWORD_URL).queryParam("logout_user", logoutUser).build());
}
Also used : PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam)

Example 9 with PasswordResetParam

use of com.emc.storageos.model.password.PasswordResetParam in project coprhd-controller by CoprHD.

the class AuthSvcTests method resetPassword.

/**
 * Routine to reset a user's password, with various parameters to account for different
 * scenarios
 *
 * @param user user for which to change the password
 * @param newPassword new password for the user
 * @param rootAltPasswd if the password change is happening after root's password was already changed,
 *            provide the current password for the root user, otherwise ChangeMe is assumed.
 * @param logout true if the sessions of the user need to be terminated as part of the password reset
 * @return the auth token of the root user's connection that did the reset
 * @throws NoSuchAlgorithmException
 */
private String resetPassword(String user, String newPassword, String rootAltPasswd, boolean logout) throws NoSuchAlgorithmException {
    PasswordResetParam passwordReset = new PasswordResetParam();
    passwordReset.setPassword(newPassword);
    passwordReset.setUsername(user);
    ClientResponse resp;
    _savedTokens.remove(USER_NAME);
    WebResource rRoot = createHttpsClient(USER_NAME, rootAltPasswd == null ? PASSWORD : rootAltPasswd, true).resource(baseAuthServiceURL);
    resp = rRoot.path("/login").get(ClientResponse.class);
    String rootResetToken = (String) _savedTokens.get(USER_NAME);
    Assert.assertEquals(200, resp.getStatus());
    resp = rRoot.path("/password/reset/").queryParam("logout_user", Boolean.toString(logout)).put(ClientResponse.class, passwordReset);
    Assert.assertEquals(200, resp.getStatus());
    // relogin with the new password otherwise the cluster check below will fail with 401
    if (user.equals(USER_NAME)) {
        _savedTokens.remove(USER_NAME);
        rRoot = createHttpsClient(USER_NAME, newPassword, true).resource(baseAuthServiceURL);
        resp = rRoot.path("/login").get(ClientResponse.class);
        rootResetToken = (String) _savedTokens.get(USER_NAME);
        Assert.assertEquals(200, resp.getStatus());
    }
    String info = "";
    Boolean notStable = true;
    while (notStable) {
        try {
            Thread.sleep(2000);
            System.out.println("Waiting for stable cluster state.");
        } catch (InterruptedException e) {
        // Empty on purpose
        }
        resp = rRoot.path("/upgrade/cluster-state").get(ClientResponse.class);
        info = resp.getEntity(String.class);
        if (info.contains("<cluster_state>STABLE</cluster_state>")) {
            notStable = false;
            System.out.println("Cluster state is stable.");
        }
    }
    return rootResetToken;
}
Also used : PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam)

Example 10 with PasswordResetParam

use of com.emc.storageos.model.password.PasswordResetParam in project coprhd-controller by CoprHD.

the class ApiTestBase method setupLicenseAndInitialPasswords.

protected void setupLicenseAndInitialPasswords() throws NoSuchAlgorithmException {
    rSys = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, baseUrls);
    rSys.path("/tenant").get(String.class);
    // Initialize proxyuser password to ChangeMe
    String[] usernames = { "sysmonitor", "proxyuser" };
    String pass_word = "ChangeMe1!";
    ClientResponse resp = null;
    for (String username : usernames) {
        PasswordResetParam params = new PasswordResetParam();
        params.setUsername(username);
        params.setPassword(pass_word);
        resp = rSys.path("/password/reset").put(ClientResponse.class, params);
        Assert.assertThat(resp.getStatus(), anyOf(is(200), is(400)));
        waitForClusterToBeStable();
    }
    if (!isControllerLicensed()) {
        addControllerLicense();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) PasswordResetParam(com.emc.storageos.model.password.PasswordResetParam)

Aggregations

PasswordResetParam (com.emc.storageos.model.password.PasswordResetParam)10 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 SecurityContext (javax.ws.rs.core.SecurityContext)5 LocalPasswordHandler (com.emc.storageos.systemservices.impl.util.LocalPasswordHandler)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)1