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;
}
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!");
}
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());
}
}
Aggregations