Search in sources :

Example 16 with QueryBuilder

use of org.apache.jackrabbit.api.security.user.QueryBuilder in project jackrabbit-oak by apache.

the class UserQueryManagerTest method testQueryBoundWithSortOrder.

@Test
public void testQueryBoundWithSortOrder() throws Exception {
    Group g = createGroup("g1", null);
    g.setProperty(propertyName, valueFactory.createValue(50));
    Group g2 = createGroup("g2", null);
    g2.setProperty(propertyName, valueFactory.createValue(60));
    user.setProperty(propertyName, valueFactory.createValue(101));
    root.commit();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setLimit(valueFactory.createValue(100), Long.MAX_VALUE);
            builder.setSortOrder(propertyName, QueryBuilder.Direction.ASCENDING);
            builder.setCondition(builder.gt(propertyName, valueFactory.createValue(20)));
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result, user);
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) Query(org.apache.jackrabbit.api.security.user.Query) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) QueryBuilder(org.apache.jackrabbit.api.security.user.QueryBuilder) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 17 with QueryBuilder

use of org.apache.jackrabbit.api.security.user.QueryBuilder in project jackrabbit-oak by apache.

the class UserQueryManagerTest method testQueryMaxCountZero.

@Test
public void testQueryMaxCountZero() throws Exception {
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> queryBuilder) {
            queryBuilder.setLimit(0, 0);
        }
    };
    assertSame(Iterators.emptyIterator(), queryMgr.findAuthorizables(q));
}
Also used : Query(org.apache.jackrabbit.api.security.user.Query) QueryBuilder(org.apache.jackrabbit.api.security.user.QueryBuilder) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with QueryBuilder

use of org.apache.jackrabbit.api.security.user.QueryBuilder in project jackrabbit-oak by apache.

the class UserQueryTest method testNameMatch2.

/**
     * The name matching condition must not only search for node-name and
     * principal name but also needs to take the new rep:authoriableId into
     * account that has been introduced as of Oak 1.0
     *
     * @see <a href="https://issues.apache.org/jira/browse/OAK-2243">OAK-2243</a>
     */
@Test
public void testNameMatch2() throws RepositoryException {
    // create a user with different id and principal name
    User user = userMgr.createUser("moloch", null, new PrincipalImpl("MolochHorridus"), "reptiles");
    String userPath = user.getPath();
    // move it such that the node name doesn't reveal the id.
    superuser.move(userPath, Text.getRelativeParent(userPath, 1) + "/thorny_dragon");
    superuser.save();
    authorizables.add(user);
    // search for the authorizable ID
    Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.nameMatches("moloch"));
        }
    });
    assertTrue(result.hasNext());
    Authorizable a = result.next();
    assertEquals("moloch", a.getID());
    assertFalse(result.hasNext());
    // search for the principal name (basically just for backwards compatibility)
    result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.nameMatches("MolochHorridus"));
        }
    });
    assertTrue(result.hasNext());
    a = result.next();
    assertEquals("MolochHorridus", a.getPrincipal().getName());
    assertFalse(result.hasNext());
    // search for the node name
    result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.nameMatches("thorny_dragon"));
        }
    });
    assertTrue(result.hasNext());
    a = result.next();
    assertEquals("thorny_dragon", Text.getName(a.getPath()));
    assertFalse(result.hasNext());
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Query(org.apache.jackrabbit.api.security.user.Query) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) QueryBuilder(org.apache.jackrabbit.api.security.user.QueryBuilder) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Aggregations

Query (org.apache.jackrabbit.api.security.user.Query)18 QueryBuilder (org.apache.jackrabbit.api.security.user.QueryBuilder)18 Test (org.junit.Test)17 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)16 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)16 Group (org.apache.jackrabbit.api.security.user.Group)14 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)2 User (org.apache.jackrabbit.api.security.user.User)1