Search in sources :

Example 56 with Authorizable

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

the class UserQueryTest method testFindProperty3.

@Test
public void testFindProperty3() throws RepositoryException {
    Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.eq("@numberOfLegs", vf.createValue(8)));
        }
    });
    Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {

        public boolean apply(User user) {
            try {
                Value[] numberOfLegs = user.getProperty("numberOfLegs");
                return numberOfLegs != null && numberOfLegs.length == 1 && numberOfLegs[0].getLong() == 8;
            } catch (RepositoryException e) {
                fail(e.getMessage());
            }
            return false;
        }
    });
    assertTrue(result.hasNext());
    assertSameElements(result, expected);
}
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) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 57 with Authorizable

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

the class UserQueryTest method testFindGroupsInGroup.

@Test
public void testFindGroupsInGroup() throws RepositoryException {
    Group[] groups = new Group[] { mammals, vertebrates, apes };
    for (final Group g : groups) {
        Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

            public <T> void build(QueryBuilder<T> builder) {
                try {
                    builder.setSelector(Group.class);
                    builder.setScope(g.getID(), true);
                } catch (RepositoryException e) {
                    fail(e.getMessage());
                }
            }
        });
        Iterator<Authorizable> members = g.getDeclaredMembers();
        Iterator<Authorizable> users = Iterators.filter(members, new Predicate<Authorizable>() {

            public boolean apply(Authorizable authorizable) {
                return authorizable.isGroup();
            }
        });
        assertSameElements(result, users);
    }
}
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) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 58 with Authorizable

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

the class UserQueryTest method testCondition2.

@Test
public void testCondition2() throws RepositoryException {
    Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.or(builder.eq("profile/@food", vf.createValue("mice")), builder.eq("profile/@food", vf.createValue("nectar"))));
        }
    });
    Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {

        public boolean apply(User user) {
            try {
                Value[] food = user.getProperty("profile/food");
                return food != null && food.length == 1 && (food[0].getString().equals("mice") || food[0].getString().equals("nectar"));
            } catch (RepositoryException e) {
                fail(e.getMessage());
            }
            return false;
        }
    });
    assertTrue(result.hasNext());
    assertSameElements(result, expected);
}
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) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 59 with Authorizable

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

the class UserQueryTest method testPropertyExistence.

@Test
public void testPropertyExistence() throws RepositoryException {
    Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.exists("@poisonous"));
        }
    });
    Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {

        public boolean apply(User user) {
            try {
                Value[] poisonous = user.getProperty("poisonous");
                return poisonous != null && poisonous.length == 1;
            } catch (RepositoryException e) {
                fail(e.getMessage());
            }
            return false;
        }
    });
    assertTrue(result.hasNext());
    assertSameElements(result, expected);
}
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) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 60 with Authorizable

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

the class UserQueryTest method testDirectScope.

@Test
public void testDirectScope() throws RepositoryException {
    Group[] groups = new Group[] { mammals, vertebrates, apes };
    for (final Group g : groups) {
        Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {

            public <T> void build(QueryBuilder<T> builder) {
                try {
                    builder.setScope(g.getID(), true);
                } catch (RepositoryException e) {
                    fail(e.getMessage());
                }
            }
        });
        Iterator<Authorizable> members = g.getDeclaredMembers();
        assertSameElements(result, members);
    }
}
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) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Aggregations

Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)466 Test (org.junit.Test)254 User (org.apache.jackrabbit.api.security.user.User)104 Group (org.apache.jackrabbit.api.security.user.Group)101 UserManager (org.apache.jackrabbit.api.security.user.UserManager)93 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)64 Principal (java.security.Principal)58 Node (javax.jcr.Node)55 RepositoryException (javax.jcr.RepositoryException)55 Query (org.apache.jackrabbit.api.security.user.Query)50 Session (javax.jcr.Session)49 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)45 Value (javax.jcr.Value)29 NodeImpl (org.apache.jackrabbit.core.NodeImpl)29 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)28 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)24 SimpleCredentials (javax.jcr.SimpleCredentials)21 HashMap (java.util.HashMap)18 QueryBuilder (org.apache.jackrabbit.api.security.user.QueryBuilder)16