Search in sources :

Example 1 with TypeFilter

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();
}
Also used : RefFilter(com.evolveum.midpoint.prism.query.RefFilter) Task(com.evolveum.midpoint.task.api.Task) RoleSelectionSpecification(com.evolveum.midpoint.model.api.RoleSelectionSpecification) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) Test(org.testng.annotations.Test)

Example 2 with TypeFilter

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;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 3 with TypeFilter

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;
}
Also used : QName(javax.xml.namespace.QName) TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter)

Example 4 with TypeFilter

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;
}
Also used : TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 5 with TypeFilter

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());
}
Also used : QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TypeFilter(com.evolveum.midpoint.prism.query.TypeFilter) LabeledString(com.evolveum.midpoint.schema.LabeledString) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) InitialDataImport(com.evolveum.midpoint.init.InitialDataImport) RestartResponseException(org.apache.wicket.RestartResponseException) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) NotFilter(com.evolveum.midpoint.prism.query.NotFilter) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

TypeFilter (com.evolveum.midpoint.prism.query.TypeFilter)6 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)4 Task (com.evolveum.midpoint.task.api.Task)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 QName (javax.xml.namespace.QName)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 InitialDataImport (com.evolveum.midpoint.init.InitialDataImport)1 RoleSelectionSpecification (com.evolveum.midpoint.model.api.RoleSelectionSpecification)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 NotFilter (com.evolveum.midpoint.prism.query.NotFilter)1 QueryFactory (com.evolveum.midpoint.prism.query.QueryFactory)1 RefFilter (com.evolveum.midpoint.prism.query.RefFilter)1 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)1