use of com.evolveum.midpoint.prism.query.TypeFilter in project midpoint by Evolveum.
the class TestSecurityBasic method test290AutzJackRoleOwnerAssign.
@Test
public void test290AutzJackRoleOwnerAssign() throws Exception {
final String TEST_NAME = "test290AutzJackRoleOwnerAssign";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
cleanupAutzTest(USER_JACK_OID);
assignRole(USER_JACK_OID, ROLE_ROLE_OWNER_ASSIGN_OID);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
login(USER_JACK_USERNAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
assertReadAllow(NUMBER_OF_ALL_USERS + 1);
assertAddDeny();
assertModifyDeny();
assertDeleteDeny();
PrismObject<UserType> user = getUser(USER_JACK_OID);
assertAssignments(user, 2);
assertAssignedRole(user, ROLE_ROLE_OWNER_ASSIGN_OID);
assertAllow("assign application role 1 to jack", (task, result) -> assignRole(USER_JACK_OID, ROLE_APPLICATION_1_OID, task, result));
user = getUser(USER_JACK_OID);
assertAssignments(user, 3);
assertAssignedRole(user, ROLE_APPLICATION_1_OID);
assertDeny("assign application role 2 to jack", new Attempt() {
@Override
public void run(Task task, OperationResult result) throws Exception {
assignRole(USER_JACK_OID, ROLE_APPLICATION_2_OID, task, result);
}
});
assertAllow("unassign application role 1 from jack", (task, result) -> unassignRole(USER_JACK_OID, ROLE_APPLICATION_1_OID, task, result));
user = getUser(USER_JACK_OID);
assertAssignments(user, 2);
RoleSelectionSpecification spec = getAssignableRoleSpecification(getUser(USER_JACK_OID));
assertRoleTypes(spec);
assertFilter(spec.getFilter(), TypeFilter.class);
assertEquals("Wrong type filter type", RoleType.COMPLEX_TYPE, ((TypeFilter) spec.getFilter()).getType());
ObjectFilter subfilter = ((TypeFilter) spec.getFilter()).getFilter();
assertFilter(subfilter, RefFilter.class);
assertEquals(1, ((RefFilter) subfilter).getValues().size());
assertEquals("Wrong OID in ref filter", USER_JACK_OID, ((RefFilter) subfilter).getValues().get(0).getOid());
assertGlobalStateUntouched();
}
use of com.evolveum.midpoint.prism.query.TypeFilter in project midpoint by Evolveum.
the class ReportServiceImpl method parseQuery.
@Override
public ObjectQuery parseQuery(String query, Map<QName, Object> parameters) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
if (StringUtils.isBlank(query)) {
return null;
}
ObjectQuery parsedQuery;
try {
Task task = taskManager.createTaskInstance();
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, task.getResult()));
SearchFilterType filter = prismContext.parserFor(query).parseRealValue(SearchFilterType.class);
LOGGER.trace("filter {}", filter);
ObjectFilter f = QueryConvertor.parseFilter(filter, UserType.class, prismContext);
LOGGER.trace("f {}", f.debugDump());
if (!(f instanceof TypeFilter)) {
throw new IllegalArgumentException("Defined query must contain type. Use 'type filter' in your report query.");
}
ObjectFilter subFilter = ((TypeFilter) f).getFilter();
ObjectQuery q = ObjectQuery.createObjectQuery(subFilter);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinitions(parameters);
q = ExpressionUtil.evaluateQueryExpressions(q, variables, expressionFactory, prismContext, "parsing expression values for report", task, task.getResult());
((TypeFilter) f).setFilter(q.getFilter());
parsedQuery = ObjectQuery.createObjectQuery(f);
LOGGER.trace("query dump {}", parsedQuery.debugDump());
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw e;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
return parsedQuery;
}
use of com.evolveum.midpoint.prism.query.TypeFilter in project midpoint by Evolveum.
the class ObjectFilterAsserter method assertType.
public ObjectFilterAsserter<RA> assertType(QName expectedTypeName) {
assertClass(TypeFilter.class);
QName actualType = ((TypeFilter) filter).getType();
AssertJUnit.assertTrue("Wrong type in type clause, expected " + expectedTypeName + ", but was " + actualType + "; in " + desc(), expectedTypeName.equals(actualType));
return this;
}
use of com.evolveum.midpoint.prism.query.TypeFilter in project midpoint by Evolveum.
the class ObjectFilterAsserter method type.
public ObjectFilterAsserter<ObjectFilterAsserter<RA>> type(QName expectedTypeName) {
assertType(expectedTypeName);
ObjectFilter subfilter = ((TypeFilter) this.filter).getFilter();
ObjectFilterAsserter<ObjectFilterAsserter<RA>> asserter = new ObjectFilterAsserter<>(subfilter, this, "type subfilter in " + desc());
copySetupTo(asserter);
return asserter;
}
use of com.evolveum.midpoint.prism.query.TypeFilter in project midpoint by Evolveum.
the class PageAbout method resetStateToInitialConfig.
private void resetStateToInitialConfig(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_DELETE_ALL_OBJECTS);
String taskOid = null;
String taskName = "Delete all objects";
QueryFactory factory = getPrismContext().queryFactory();
TypeFilter nodeFilter = factory.createType(NodeType.COMPLEX_TYPE, factory.createAll());
final ObjectFilter taskFilter = getPrismContext().queryFor(TaskType.class).item(TaskType.F_NAME).eq(taskName).buildFilter();
NotFilter notNodeFilter = factory.createNot(nodeFilter);
NotFilter notTaskFilter = factory.createNot(taskFilter);
try {
QName type = ObjectType.COMPLEX_TYPE;
taskOid = deleteObjectsAsync(type, factory.createQuery(factory.createAnd(notTaskFilter, notNodeFilter)), taskName, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.allObject.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete all objects", ex);
}
final String taskOidToRemoving = taskOid;
try {
while (!getTaskManager().getTaskPlain(taskOid, result).isClosed()) {
TimeUnit.SECONDS.sleep(5);
}
runPrivileged(new Producer<Object>() {
private static final long serialVersionUID = 1L;
@Override
public Object run() {
Task task = createAnonymousTask(OPERATION_DELETE_TASK);
OperationResult result = new OperationResult(OPERATION_DELETE_TASK);
ObjectDelta<TaskType> delta = getPrismContext().deltaFactory().object().createDeleteDelta(TaskType.class, taskOidToRemoving);
Collection<ObjectDelta<? extends ObjectType>> deltaCollection = Collections.singletonList(delta);
try {
getModelService().executeChanges(deltaCollection, null, task, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.task.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete task", ex);
}
result.computeStatus();
return null;
}
});
InitialDataImport initialDataImport = new InitialDataImport();
initialDataImport.setModel(getModelService());
initialDataImport.setTaskManager(getTaskManager());
initialDataImport.setPrismContext(getPrismContext());
initialDataImport.setConfiguration(getMidpointConfiguration());
initialDataImport.init(true);
// TODO consider if we need to go clusterwide here
getCacheDispatcher().dispatchInvalidation(null, null, true, null);
getModelService().shutdown();
getModelService().postInit(result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.import.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import initial objects", ex);
}
showResult(result);
target.add(getFeedbackPanel());
}
Aggregations