Search in sources :

Example 6 with QueryBuilder

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

the class UserQueryManagerTest method testQueryBoundWithoutSortOrder.

@Test
public void testQueryBoundWithoutSortOrder() 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.setCondition(builder.gt(propertyName, valueFactory.createValue(20)));
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result, user, g, g2);
}
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 7 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeInheritedMembership.

@Test
public void testQueryScopeInheritedMembership() throws Exception {
    Group g = createGroup("g1", null);
    Group g2 = createGroup("g2", null);
    g.addMember(g2);
    g2.addMember(user);
    user.setProperty(propertyName, v);
    root.commit();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.eq(propertyName, v));
            builder.setScope("g1", false);
        }
    };
    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 8 with QueryBuilder

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

the class UserQueryManagerTest method testQueryNameMatchesWithUnderscoreId.

@Test
public void testQueryNameMatchesWithUnderscoreId() throws Exception {
    Group g = createGroup("group_with_underscore", null);
    root.commit();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.nameMatches("group_with_underscore"));
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result, g);
}
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 9 with QueryBuilder

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

the class UserQueryManagerTest method testQuerySortRespectCase.

@Test
public void testQuerySortRespectCase() throws Exception {
    Group g = createGroup("g1", null);
    g.setProperty(propertyName, valueFactory.createValue("aaa"));
    Group g2 = createGroup("g2", null);
    g2.setProperty(propertyName, valueFactory.createValue("BBB"));
    user.setProperty(propertyName, valueFactory.createValue("c"));
    root.commit();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.exists(propertyName));
            builder.setSortOrder(propertyName, QueryBuilder.Direction.DESCENDING, false);
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertEquals(ImmutableList.of(user, g, g2), ImmutableList.copyOf(result));
}
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 10 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeDeclaredMembership.

@Test
public void testQueryScopeDeclaredMembership() throws Exception {
    Group g = createGroup("g1", null);
    Group g2 = createGroup("g2", null);
    g.addMember(g2);
    g2.addMember(user);
    user.setProperty(propertyName, v);
    root.commit();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.eq(propertyName, v));
            builder.setScope("g1", true);
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result);
}
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)

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