Search in sources :

Example 1 with AuthClient

use of com.emc.vipr.client.AuthClient in project coprhd-controller by CoprHD.

the class ApisvcTestBase method getViprClient.

/**
 * Get a logged in ViPR client instance.
 * @param viprIP -- IP address (or FQDN) of Vipr server or devkit.
 * @param userName -- String user name.
 * @param password -- String password (unobfuscated).
 * @return ViPRCoreClient that has been authenticated
 */
public ViPRCoreClient getViprClient(String viprIP, String userName, String password) {
    ClientConfig clientConfig = new ClientConfig().withHost(viprIP).withRequestLoggingDisabled().withMaxRetries(10).withMediaType("application/json").withIgnoringCertificates(true);
    viprCoreClient = new ViPRCoreClient(clientConfig);
    AuthClient auth = viprCoreClient.auth();
    String token = auth.login(userName, password);
    viprCoreClient.setAuthToken(token);
    log.info("Auth token is: " + token);
    return viprCoreClient;
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) AuthClient(com.emc.vipr.client.AuthClient) ClientConfig(com.emc.vipr.client.ClientConfig)

Example 2 with AuthClient

use of com.emc.vipr.client.AuthClient in project coprhd-controller by CoprHD.

the class ValidationApiTest method PasswordChangeValidation.

@Test
public void PasswordChangeValidation() throws Exception {
    AuthClient authClient = new AuthClient(controllerNodeEndpoint);
    try {
        authClient.validatePasswordChange("svcuser", "wrong-old-password", "password");
        Assert.fail("should fail, wrong old password");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 1008);
        Assert.assertTrue(see.getMessage().contains("Old password is invalid"));
    }
    // new password too short
    try {
        authClient.validatePasswordChange("svcuser", password, "short");
        Assert.fail("should fail, new password too short");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 1008);
        Assert.assertTrue(see.getMessage().contains("at least 8 characters long"));
    }
    // new password no numbers
    try {
        authClient.validatePasswordChange("svcuser", password, "NoNumbers");
        Assert.fail("should fail, contains no digital");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 1008);
        Assert.assertTrue(see.getMessage().contains("at least 1 numeric character"));
    }
    // new password no upppercase char
    try {
        authClient.validatePasswordChange("svcuser", password, "nouppercase");
        Assert.fail("should fail, contains no uppercase");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 1008);
        Assert.assertTrue(see.getMessage().contains("at least 1 uppercase alphabetic"));
    }
    // new password no lowercase char
    try {
        authClient.validatePasswordChange("svcuser", password, "NOLOWERCASE");
        Assert.fail("should fail, contains no lower case");
    } catch (ServiceErrorException see) {
        Assert.assertEquals(see.getCode(), 1008);
        Assert.assertTrue(see.getMessage().contains("at least 1 lowercase alphabetic"));
    }
    // positive test, should be no exception
    authClient.validatePasswordChange("svcuser", password, "ChangeMe1!");
}
Also used : AuthClient(com.emc.vipr.client.AuthClient) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) Test(org.junit.Test)

Example 3 with AuthClient

use of com.emc.vipr.client.AuthClient in project coprhd-controller by CoprHD.

the class TaskUtil method refreshSession.

private static synchronized void refreshSession(RestClient client) {
    if (client.getLoginTime() > 0 && (System.currentTimeMillis() - client.getLoginTime()) > client.getConfig().getSessionKeyRenewTimeout() && client.getUsername() != null && client.getPassword() != null) {
        AuthClient authClient = new AuthClient(client);
        authClient.logout();
        authClient.login(client.getUsername(), client.getPassword());
        client.setProxyToken(authClient.proxyToken());
    }
}
Also used : AuthClient(com.emc.vipr.client.AuthClient)

Aggregations

AuthClient (com.emc.vipr.client.AuthClient)3 ClientConfig (com.emc.vipr.client.ClientConfig)1 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)1 ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)1 Test (org.junit.Test)1