Search in sources :

Example 51 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class AbstractAdLdapMultidomainTest method createSamAccountNameQuery.

protected ObjectQuery createSamAccountNameQuery(String samAccountName) throws SchemaException {
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
    ObjectQueryUtil.filterAnd(query.getFilter(), createAttributeFilter(ATTRIBUTE_SAM_ACCOUNT_NAME_NAME, samAccountName));
    return query;
}
Also used : ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 52 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class AbstractAdLdapMultidomainTest method test150SeachAllAccounts.

/**
	 * No paging. It should return all accounts.
	 */
@Test
public void test150SeachAllAccounts() throws Exception {
    final String TEST_NAME = "test150SeachAllAccounts";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
    rememberConnectorOperationCount();
    rememberConnectorSimulatedPagingSearchCount();
    // WHEN
    SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, NUMBER_OF_ACCOUNTS, task, result);
    // TODO: why 11? should be 1
    //        assertConnectorOperationIncrement(11);
    assertConnectorSimulatedPagingSearchIncrement(0);
    SearchResultMetadata metadata = searchResultList.getMetadata();
    if (metadata != null) {
        assertFalse(metadata.isPartialResults());
    }
//        assertLdapConnectorInstances(2);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 53 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class TestSecurityBasic method test242AutzJackManagerFullControlManagerMinistryOfRum.

@Test
public void test242AutzJackManagerFullControlManagerMinistryOfRum() throws Exception {
    final String TEST_NAME = "test242AutzJackManagerFullControlManagerMinistryOfRum";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    cleanupAutzTest(USER_JACK_OID);
    assignRole(USER_JACK_OID, ROLE_MANAGER_FULL_CONTROL_OID);
    assignOrg(USER_JACK_OID, ORG_MINISTRY_OF_RUM_OID, SchemaConstants.ORG_MANAGER);
    assignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, null);
    // precondition
    PrismObject<ShadowType> elaineShadow = getObject(ShadowType.class, ACCOUNT_SHADOW_ELAINE_DUMMY_OID);
    assertNotNull(elaineShadow);
    display("Elaine's shadow", elaineShadow);
    login(USER_JACK_USERNAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assertGetAllow(UserType.class, USER_JACK_OID);
    assertGetAllow(UserType.class, USER_JACK_OID, SelectorOptions.createCollection(GetOperationOptions.createRaw()));
    assertGetDeny(UserType.class, USER_GUYBRUSH_OID);
    assertGetDeny(UserType.class, USER_GUYBRUSH_OID, SelectorOptions.createCollection(GetOperationOptions.createRaw()));
    assertSearch(UserType.class, null, 4);
    assertSearch(UserType.class, createNameQuery(USER_JACK_USERNAME), 1);
    assertSearch(UserType.class, createNameQuery(USER_JACK_USERNAME), SelectorOptions.createCollection(GetOperationOptions.createRaw()), 1);
    assertSearch(UserType.class, createNameQuery(USER_GUYBRUSH_USERNAME), 0);
    assertSearch(UserType.class, createNameQuery(USER_GUYBRUSH_USERNAME), SelectorOptions.createCollection(GetOperationOptions.createRaw()), 0);
    assertAddDeny();
    assertModifyAllow(UserType.class, USER_JACK_OID, UserType.F_HONORIFIC_PREFIX, PrismTestUtil.createPolyString("Captain"));
    assertModifyAllowOptions(UserType.class, USER_JACK_OID, UserType.F_HONORIFIC_SUFFIX, ModelExecuteOptions.createRaw(), PrismTestUtil.createPolyString("CSc"));
    assertModifyDeny(UserType.class, USER_GUYBRUSH_OID, UserType.F_HONORIFIC_PREFIX, PrismTestUtil.createPolyString("Pirate"));
    assertDeleteDeny();
    assertGetAllow(UserType.class, userRumRogersOid);
    assertModifyAllow(UserType.class, userRumRogersOid, UserType.F_TITLE, PrismTestUtil.createPolyString("drunk"));
    // Cobb is in Scumm Bar, transitive descendant of Ministry of Rum
    assertGetAllow(UserType.class, userCobbOid);
    assertAddAllow(USER_MANCOMB_FILE);
    PrismObject<UserType> user = getUser(USER_JACK_OID);
    String accountOid = getSingleLinkOid(user);
    assertGetAllow(ShadowType.class, accountOid);
    PrismObject<ShadowType> shadow = getObject(ShadowType.class, accountOid);
    display("Jack's shadow", shadow);
    assertGetDeny(ShadowType.class, ACCOUNT_SHADOW_ELAINE_DUMMY_OID);
    assertVisibleUsers(5);
    assertGetAllow(OrgType.class, ORG_MINISTRY_OF_RUM_OID);
    assertSearch(OrgType.class, null, 2);
    assertModifyDeny(OrgType.class, ORG_MINISTRY_OF_RUM_OID, OrgType.F_DESCRIPTION, "blababla");
    assertModifyAllow(OrgType.class, ORG_SCUMM_BAR_OID, OrgType.F_DESCRIPTION, "Hosting the worst scumm of the World.");
    assignAccount(USER_ESTEVAN_OID, RESOURCE_DUMMY_OID, null);
    PrismObject<UserType> userEstevan = getUser(USER_ESTEVAN_OID);
    String accountEstevanOid = getSingleLinkOid(userEstevan);
    assertGetAllow(ShadowType.class, accountEstevanOid);
    PrismObject<ShadowType> shadowEstevan = getObject(ShadowType.class, accountEstevanOid);
    display("Estevan shadow", shadowEstevan);
    // MID-2822
    Task task = taskManager.createTaskInstance(TestSecurityBasic.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectQuery query = ObjectQuery.createObjectQuery(ObjectQueryUtil.createResourceAndObjectClassFilter(RESOURCE_DUMMY_OID, new QName(RESOURCE_DUMMY_NAMESPACE, "AccountObjectClass"), prismContext));
    try {
        modelService.searchObjects(ShadowType.class, query, null, task, result);
        AssertJUnit.fail("unexpected success");
    } catch (SchemaException e) {
        // This is expected. The authorizations will mix on-resource and off-resource search.
        display("Expected exception", e);
    }
    result.computeStatus();
    TestUtil.assertFailure(result);
    assertDeleteAllow(UserType.class, USER_ESTEVAN_OID);
    assertVisibleUsers(4);
    assertGlobalStateUntouched();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 54 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method resolve.

PrismObject<ShadowType> resolve(ProvisioningContext ctx, ResourceObjectReferenceType resourceObjectReference, QName objectClass, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (resourceObjectReference == null) {
        return null;
    }
    ObjectReferenceType shadowRef = resourceObjectReference.getShadowRef();
    if (shadowRef != null && shadowRef.getOid() != null) {
        if (resourceObjectReference.getResolutionFrequency() == null || resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.ONCE) {
            PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, shadowRef.getOid(), null, result);
            return shadow;
        }
    } else if (resourceObjectReference.getResolutionFrequency() == ResourceObjectReferenceResolutionFrequencyType.NEVER) {
        throw new ObjectNotFoundException("No shadowRef OID in " + desc + " and resolution frequency set to NEVER");
    }
    if (resourceObjectReference.getObjectClass() != null) {
        objectClass = resourceObjectReference.getObjectClass();
        if (objectClass.getNamespaceURI() == null) {
            objectClass = new QName(ResourceTypeUtil.getResourceNamespace(ctx.getResource()), objectClass.getLocalPart());
        }
    }
    ProvisioningContext subctx = ctx.spawn(objectClass);
    // Use "raw" definitions from the original schema to avoid endless loops
    subctx.setUseRefinedDefinition(false);
    subctx.assertDefinition();
    ObjectQuery refQuery = QueryJaxbConvertor.createObjectQuery(ShadowType.class, resourceObjectReference.getFilter(), prismContext);
    ObjectFilter baseFilter = ObjectQueryUtil.createResourceAndObjectClassFilter(ctx.getResource().getOid(), objectClass, prismContext);
    ObjectFilter filter = AndFilter.createAnd(baseFilter, refQuery.getFilter());
    ObjectQuery query = ObjectQuery.createObjectQuery(filter);
    // TODO: implement "repo" search strategies
    Collection<SelectorOptions<GetOperationOptions>> options = null;
    final Holder<ShadowType> shadowHolder = new Holder<>();
    ShadowHandler<ShadowType> handler = new ShadowHandler<ShadowType>() {

        @Override
        public boolean handle(ShadowType shadow) {
            if (shadowHolder.getValue() != null) {
                throw new IllegalStateException("More than one search results for " + desc);
            }
            shadowHolder.setValue(shadow);
            return true;
        }
    };
    shadowCache.searchObjectsIterative(subctx, query, options, handler, true, result);
    // TODO: implement storage of OID (ONCE search frequency)
    ShadowType shadowType = shadowHolder.getValue();
    return shadowType == null ? null : shadowType.asPrismObject();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Holder(com.evolveum.midpoint.util.Holder) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ResourceObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectReferenceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 55 with ObjectQuery

use of com.evolveum.midpoint.prism.query.ObjectQuery in project midpoint by Evolveum.

the class ShadowManager method searchObjectsIterativeRepository.

public SearchResultMetadata searchObjectsIterativeRepository(ProvisioningContext ctx, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, com.evolveum.midpoint.schema.ResultHandler<ShadowType> repoHandler, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ObjectQuery repoQuery = query.clone();
    processQueryMatchingRules(repoQuery, ctx.getObjectClassDefinition());
    // TODO think about strictSequential flag
    return repositoryService.searchObjectsIterative(ShadowType.class, repoQuery, repoHandler, options, false, parentResult);
}
Also used : ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)697 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)453 Test (org.testng.annotations.Test)335 PrismObject (com.evolveum.midpoint.prism.PrismObject)284 Task (com.evolveum.midpoint.task.api.Task)268 QName (javax.xml.namespace.QName)111 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)78 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)76 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 ArrayList (java.util.ArrayList)61 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)58 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)53 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)41 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)41 SystemException (com.evolveum.midpoint.util.exception.SystemException)38 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)37 NotNull (org.jetbrains.annotations.NotNull)35 List (java.util.List)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)27