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