Search in sources :

Example 91 with SecurityViolationException

use of com.evolveum.midpoint.util.exception.SecurityViolationException in project midpoint by Evolveum.

the class AbstractSecurityTest method assertDeny.

protected <O extends ObjectType> void assertDeny(String opname, Attempt attempt) throws Exception {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertDeny." + opname);
    OperationResult result = task.getResult();
    try {
        logAttempt(opname);
        attempt.run(task, result);
        failDeny(opname);
    } catch (SecurityViolationException e) {
        // this is expected
        logDeny(opname);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 92 with SecurityViolationException

use of com.evolveum.midpoint.util.exception.SecurityViolationException in project midpoint by Evolveum.

the class AbstractSecurityTest method assertSearch.

protected <O extends ObjectType> void assertSearch(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, int expectedResults) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertSearchObjects");
    OperationResult result = task.getResult();
    try {
        logAttempt("search", type, query);
        List<PrismObject<O>> objects = modelService.searchObjects(type, query, options, task, result);
        display("Search returned", objects.toString());
        if (objects.size() > expectedResults) {
            failDeny("search", type, query, expectedResults, objects.size());
        } else if (objects.size() < expectedResults) {
            failAllow("search", type, query, expectedResults, objects.size());
        }
        result.computeStatus();
        TestUtil.assertSuccess(result);
    } catch (SecurityViolationException e) {
        // this should not happen
        result.computeStatus();
        TestUtil.assertFailure(result);
        failAllow("search", type, query, e);
    }
    task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertSearchObjectsIterative");
    result = task.getResult();
    try {
        logAttempt("searchIterative", type, query);
        final List<PrismObject<O>> objects = new ArrayList<>();
        ResultHandler<O> handler = new ResultHandler<O>() {

            @Override
            public boolean handle(PrismObject<O> object, OperationResult parentResult) {
                objects.add(object);
                return true;
            }
        };
        modelService.searchObjectsIterative(type, query, handler, options, task, result);
        display("Search iterative returned", objects.toString());
        if (objects.size() > expectedResults) {
            failDeny("searchIterative", type, query, expectedResults, objects.size());
        } else if (objects.size() < expectedResults) {
            failAllow("searchIterative", type, query, expectedResults, objects.size());
        }
        result.computeStatus();
        TestUtil.assertSuccess(result);
    } catch (SecurityViolationException e) {
        // this should not happen
        result.computeStatus();
        TestUtil.assertFailure(result);
        failAllow("searchIterative", type, query, e);
    }
    task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertSearchObjects.count");
    result = task.getResult();
    try {
        logAttempt("count", type, query);
        int numObjects = modelService.countObjects(type, query, options, task, result);
        display("Count returned", numObjects);
        if (numObjects > expectedResults) {
            failDeny("count", type, query, expectedResults, numObjects);
        } else if (numObjects < expectedResults) {
            failAllow("count", type, query, expectedResults, numObjects);
        }
        result.computeStatus();
        TestUtil.assertSuccess(result);
    } catch (SecurityViolationException e) {
        // this should not happen
        result.computeStatus();
        TestUtil.assertFailure(result);
        failAllow("search", type, query, e);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler)

Example 93 with SecurityViolationException

use of com.evolveum.midpoint.util.exception.SecurityViolationException in project midpoint by Evolveum.

the class AbstractSecurityTest method assertGetDeny.

protected <O extends ObjectType> void assertGetDeny(Class<O> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertGetDeny");
    OperationResult result = task.getResult();
    try {
        logAttempt("get", type, oid, null);
        PrismObject<O> object = modelService.getObject(type, oid, options, task, result);
        failDeny("get", type, oid, null);
    } catch (SecurityViolationException e) {
        // this is expected
        logDeny("get", type, oid, null);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 94 with SecurityViolationException

use of com.evolveum.midpoint.util.exception.SecurityViolationException in project midpoint by Evolveum.

the class AbstractSecurityTest method assertAddDeny.

protected <O extends ObjectType> void assertAddDeny(File file, ModelExecuteOptions options) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, IOException {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertAddDeny");
    OperationResult result = task.getResult();
    PrismObject<O> object = PrismTestUtil.parseObject(file);
    ObjectDelta<O> addDelta = object.createAddDelta();
    try {
        logAttempt("add", object.getCompileTimeClass(), object.getOid(), null);
        modelService.executeChanges(MiscSchemaUtil.createCollection(addDelta), options, task, result);
        failDeny("add", object.getCompileTimeClass(), object.getOid(), null);
    } catch (SecurityViolationException e) {
        // this is expected
        logDeny("add", object.getCompileTimeClass(), object.getOid(), null);
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 95 with SecurityViolationException

use of com.evolveum.midpoint.util.exception.SecurityViolationException in project midpoint by Evolveum.

the class AbstractSecurityTest method assertAllow.

protected <O extends ObjectType> void assertAllow(String opname, Attempt attempt) throws Exception {
    Task task = taskManager.createTaskInstance(AbstractSecurityTest.class.getName() + ".assertAllow." + opname);
    OperationResult result = task.getResult();
    try {
        logAttempt(opname);
        attempt.run(task, result);
    } catch (SecurityViolationException e) {
        failAllow(opname, e);
    }
    result.computeStatus();
    TestUtil.assertSuccess(result);
    logAllow(opname);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)131 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)109 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)93 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)84 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)66 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)64 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)57 Task (com.evolveum.midpoint.task.api.Task)53 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)29 PrismObject (com.evolveum.midpoint.prism.PrismObject)24 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)19 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)17 ArrayList (java.util.ArrayList)17 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)15 QName (javax.xml.namespace.QName)13 Test (org.testng.annotations.Test)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)11