Search in sources :

Example 11 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeNotMember.

@Test
public void testQueryScopeNotMember() throws Exception {
    Group g = createGroup("g1", null);
    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);
}
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 12 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeEveryoneWithIdDiffersPrincipalName.

@Test
public void testQueryScopeEveryoneWithIdDiffersPrincipalName() throws Exception {
    Group g = createGroup("eGroup", EveryonePrincipal.getInstance());
    g.setProperty(propertyName, v);
    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("eGroup", 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 13 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeEveryoneNonExisting.

@Test
public void testQueryScopeEveryoneNonExisting() throws Exception {
    String userId = user.getID();
    Query q = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.nameMatches(userId));
            builder.setScope(EveryonePrincipal.NAME, false);
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result, user);
}
Also used : 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 14 with QueryBuilder

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

the class UserQueryManagerTest method testQuerySortIgnoreCase.

@Test
public void testQuerySortIgnoreCase() 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, true);
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertEquals(ImmutableList.of(user, g2, g), 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 15 with QueryBuilder

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

the class UserQueryManagerTest method testQueryBoundWithSortOrderMissingCondition.

@Test
public void testQueryBoundWithSortOrderMissingCondition() 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);
        }
    };
    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)

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