Search in sources :

Example 16 with ServiceErrorException

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"));
    }
}
Also used : UserMappingChanges(com.emc.storageos.model.tenant.UserMappingChanges) UserMappingParam(com.emc.storageos.model.tenant.UserMappingParam) ArrayList(java.util.ArrayList) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) TenantUpdateParam(com.emc.storageos.model.tenant.TenantUpdateParam) Test(org.junit.Test)

Example 17 with ServiceErrorException

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"));
    }
}
Also used : ViPRClientHelper(com.emc.storageos.usermanagement.util.ViPRClientHelper) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) Test(org.junit.Test)

Example 18 with ServiceErrorException

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!");
}
Also used : AuthClient(com.emc.vipr.client.AuthClient) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) Test(org.junit.Test)

Example 19 with ServiceErrorException

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;
}
Also used : ViPRSystemClient(com.emc.vipr.client.ViPRSystemClient) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException)

Example 20 with ServiceErrorException

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException)

Aggregations

ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)26 Test (org.junit.Test)7 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)5 ArrayList (java.util.ArrayList)5 UnManagedVolumeRestRep (com.emc.storageos.model.block.UnManagedVolumeRestRep)4 URI (java.net.URI)4 ViPRException (com.emc.vipr.client.exceptions.ViPRException)3 VolumeCreate (com.emc.storageos.model.block.VolumeCreate)2 ServiceErrorRestRep (com.emc.storageos.model.errorhandling.ServiceErrorRestRep)2 TenantUpdateParam (com.emc.storageos.model.tenant.TenantUpdateParam)2 UserMappingChanges (com.emc.storageos.model.tenant.UserMappingChanges)2 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)2 ViPRClientHelper (com.emc.storageos.usermanagement.util.ViPRClientHelper)2 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)2 ViPRSystemClient (com.emc.vipr.client.ViPRSystemClient)2 FlashException (controllers.util.FlashException)2 ACLUpdateBuilder (util.builders.ACLUpdateBuilder)2 ExecutionException (com.emc.sa.engine.ExecutionException)1 CreateBlockVolumeHelper (com.emc.sa.service.vipr.block.CreateBlockVolumeHelper)1 DeactivateBlockExport (com.emc.sa.service.vipr.block.tasks.DeactivateBlockExport)1