Search in sources :

Example 1 with QueryBuilder

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

the class PrincipalProviderImpl method findAuthorizables.

private Iterator<Authorizable> findAuthorizables(@Nullable final String nameHint, final int searchType) throws RepositoryException {
    Query userQuery = new Query() {

        @Override
        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.like('@' + UserConstants.REP_PRINCIPAL_NAME, buildSearchPattern(nameHint)));
            builder.setSelector(AuthorizableType.getType(searchType).getAuthorizableClass());
        }
    };
    return userManager.findAuthorizables(userQuery);
}
Also used : Query(org.apache.jackrabbit.api.security.user.Query) QueryBuilder(org.apache.jackrabbit.api.security.user.QueryBuilder)

Example 2 with QueryBuilder

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

the class UserQueryManagerTest method testQueryNoScope.

@Test
public void testQueryNoScope() throws Exception {
    Group g = createGroup(null, 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));
        }
    };
    Iterator<Authorizable> result = queryMgr.findAuthorizables(q);
    assertResultContainsAuthorizables(result, user, 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 3 with QueryBuilder

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

the class UserQueryManagerTest method testQueryNameMatchesWithUnderscorePrincipalName.

@Test
public void testQueryNameMatchesWithUnderscorePrincipalName() throws Exception {
    Group g = createGroup("g", new PrincipalImpl("group_with_underscore"));
    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) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeEveryoneFiltersEveryone.

@Test
public void testQueryScopeEveryoneFiltersEveryone() throws Exception {
    Group g = createGroup(null, 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(EveryonePrincipal.NAME, 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 5 with QueryBuilder

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

the class UserQueryManagerTest method testQueryScopeDeclaredMember.

@Test
public void testQueryScopeDeclaredMember() throws Exception {
    Group g = createGroup("g1", null);
    g.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)

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