use of com.emc.vipr.client.exceptions.ServiceErrorException in project coprhd-controller by CoprHD.
the class TenantModificationTest method securityAdminModifyUserMapping.
@Test
public void securityAdminModifyUserMapping() throws Exception {
TenantUpdateParam tenantUpdateParam = new TenantUpdateParam();
UserMappingChanges changes = new UserMappingChanges();
List<UserMappingParam> listAdd = new ArrayList<UserMappingParam>();
UserMappingParam param = new UserMappingParam();
param.setDomain("Not Exist");
listAdd.add(param);
changes.setAdd(listAdd);
tenantUpdateParam.setUserMappingChanges(changes);
try {
secAdminClient.tenants().update(rootTenantID, tenantUpdateParam);
Assert.fail("fail, as the input contains wrong domain");
} catch (ServiceErrorException see) {
// verify the exception is not insufficent permission.
Assert.assertNotEquals(see.getCode(), 3000);
Assert.assertTrue(see.getMessage().contains("Parameter was provided but invalid"));
}
}
use of com.emc.vipr.client.exceptions.ServiceErrorException in project coprhd-controller by CoprHD.
the class TenantModificationTest method securityAdminCreateTenant.
@Test
public void securityAdminCreateTenant() throws Exception {
ViPRClientHelper viPRClientHelper1 = new ViPRClientHelper(secAdminClient);
try {
viPRClientHelper1.createTenant("testTenant", "not-exist.com", "attr", "value");
Assert.fail("should fail, as input domain not exist");
} catch (ServiceErrorException see) {
// verify the exception is not insufficent permission.
Assert.assertNotEquals(see.getCode(), 3000);
Assert.assertTrue(see.getMessage().contains("Parameter was provided but invalid"));
}
}
use of com.emc.vipr.client.exceptions.ServiceErrorException 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.exceptions.ServiceErrorException in project coprhd-controller by CoprHD.
the class PasswordUtil method validatePassword.
/**
* Validates a password using the ViPR api call.
*
* @param plaintext password to validate
* @return If validation passes, returns an empty string. If validation fails, returns the validation error message.
*/
public static String validatePassword(String value) {
ViPRSystemClient client = BourneUtil.getSysClient();
try {
String decrypted = decryptedValue(value);
client.password().validate(decrypted);
} catch (ServiceErrorException e) {
if (e.getHttpCode() == 400 && e.getServiceError() != null) {
return e.getServiceError().getDetailedMessage();
}
} catch (Exception e) {
Logger.error(e, "Error executing api call to validate password");
return MessagesUtils.get("setup.password.notValid");
}
return StringUtils.EMPTY;
}
use of com.emc.vipr.client.exceptions.ServiceErrorException in project coprhd-controller by CoprHD.
the class ExceptionOnErrorFilter method handle.
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ClientResponse response = getNext().handle(request);
int status = response.getStatus();
if (status >= 400 && status < 600) {
if (isSupportedType(response.getType())) {
ServiceErrorRestRep serviceError;
try {
serviceError = response.getEntity(ServiceErrorRestRep.class);
} catch (Exception e) {
// Cause to fall-through to default exception
log.error("Error parsing error message", e);
serviceError = null;
}
if (serviceError != null) {
logAndThrow(new ServiceErrorException(status, serviceError));
}
}
// Fallback for unknown entity types
String content = response.getEntity(String.class);
logAndThrow(new ViPRHttpException(status, content));
}
return response;
}
Aggregations