Search in sources :

Example 96 with Authorizable

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

the class UserImportTest method testImportWithIntermediatePath.

@Test
public void testImportWithIntermediatePath() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"some\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>d5433be9-68d0-4fba-bf96-efc29f461993</sv:value></sv:property>" + "<sv:node sv:name=\"intermediate\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>d87354a4-037e-4756-a8fb-deb2eb7c5149</sv:value></sv:property>" + "<sv:node sv:name=\"path\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>24263272-b789-4568-957a-3bcaf99dbab3</sv:value></sv:property>" + "<sv:node sv:name=\"t3\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>0b8854ad-38f0-36c6-9807-928d28195609</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}4358694eeb098c6708ae914a10562ce722bbbc34</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t3</sv:value></sv:property>" + "</sv:node>" + "</sv:node>" + "</sv:node>" + "</sv:node>";
    Node target = getTargetNode();
    doImport(getTargetPath(), xml);
    Session s = getImportSession();
    assertTrue(target.isModified());
    assertTrue(s.hasPendingChanges());
    Authorizable newUser = getUserManager().getAuthorizable("t3");
    assertNotNull(newUser);
    assertFalse(newUser.isGroup());
    assertEquals("t3", newUser.getPrincipal().getName());
    assertEquals("t3", newUser.getID());
    Node n = s.getNode(newUser.getPath());
    assertTrue(n.isNew());
    Node parent = n.getParent();
    assertFalse(n.isSame(target));
    assertTrue(parent.isNodeType(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
    assertFalse(parent.getDefinition().isProtected());
    assertTrue(target.hasNode("some"));
    assertTrue(target.hasNode("some/intermediate/path"));
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 97 with Authorizable

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

the class UserImportWithActionsTest method testAccessControlActionExecutionForUser2.

@Test
public void testAccessControlActionExecutionForUser2() throws Exception {
    AccessControlAction a1 = new AccessControlAction();
    a1.init(securityProvider, ConfigurationParameters.of(AccessControlAction.USER_PRIVILEGE_NAMES, new String[] { Privilege.JCR_ALL }));
    setAuthorizableActions(a1);
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + "   <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + "   <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>tPrincipal</sv:value></sv:property>" + "   <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "</sv:node>";
    doImport(USERPATH, xml);
    Authorizable a = getUserManager().getAuthorizable("t");
    assertNotNull(a);
    assertFalse(a.isGroup());
    AccessControlManager acMgr = getImportSession().getAccessControlManager();
    AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
    assertNotNull(policies);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof AccessControlList);
    AccessControlEntry[] aces = ((AccessControlList) policies[0]).getAccessControlEntries();
    assertEquals(1, aces.length);
    assertEquals("tPrincipal", aces[0].getPrincipal().getName());
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlAction(org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AccessControlEntry(javax.jcr.security.AccessControlEntry) Test(org.junit.Test)

Example 98 with Authorizable

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

the class UserQueryTest method testContains1.

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

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.contains(".", "gold"));
        }
    });
    Iterator<User> expected = Iterators.singletonIterator(goldenToad);
    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) Test(org.junit.Test)

Example 99 with Authorizable

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

the class UserQueryTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Iterator<Authorizable> systemAuthorizables = userMgr.findAuthorizables("rep:principalName", null);
    while (systemAuthorizables.hasNext()) {
        Authorizable authorizable = systemAuthorizables.next();
        if (authorizable.isGroup()) {
            groups.add((Group) authorizable);
        } else {
            users.add((User) authorizable);
        }
        systemDefined.add(authorizable);
    }
    Group animals = createGroup("animals");
    Group invertebrates = createGroup("invertebrates");
    Group arachnids = createGroup("arachnids");
    Group insects = createGroup("insects");
    vertebrates = createGroup("vertebrates");
    mammals = createGroup("mammals");
    apes = createGroup("apes");
    Group reptiles = createGroup("reptiles");
    Group birds = createGroup("birds");
    Group amphibians = createGroup("amphibians");
    animals.addMember(invertebrates);
    animals.addMember(vertebrates);
    invertebrates.addMember(arachnids);
    invertebrates.addMember(insects);
    vertebrates.addMember(mammals);
    vertebrates.addMember(reptiles);
    vertebrates.addMember(birds);
    vertebrates.addMember(amphibians);
    mammals.addMember(apes);
    User blackWidow = createUser("black widow", "flies", 2, false);
    User gardenSpider = createUser("garden spider", "flies", 2, false);
    User jumpingSpider = createUser("jumping spider", "insects", 1, false);
    addMembers(arachnids, blackWidow, gardenSpider, jumpingSpider);
    User ant = createUser("ant", "leaves", 0.5, false);
    User bee = createUser("bee", "honey", 2.5, true);
    User fly = createUser("fly", "dirt", 1.3, false);
    addMembers(insects, ant, bee, fly);
    User jackrabbit = createUser("jackrabbit", "carrots", 2500, true);
    User backslash = createUser("foo\\bar", "characters", 2500, false);
    User deer = createUser("deer", "leaves", 120000, true);
    User opossum = createUser("opossum", "fruit", 1200, true);
    kangaroo = createUser("kangaroo", "grass", 90000, true);
    elephant = createUser("elephant", "leaves", 5000000, true);
    addMembers(mammals, jackrabbit, deer, opossum, kangaroo, elephant);
    User lemur = createUser("lemur", "nectar", 1100, true);
    User gibbon = createUser("gibbon", "meat", 20000, true);
    addMembers(apes, lemur, gibbon);
    User crocodile = createUser("crocodile", "meat", 80000, false);
    User turtle = createUser("turtle", "leaves", 10000, true);
    User lizard = createUser("lizard", "leaves", 1900, false);
    addMembers(reptiles, crocodile, turtle, lizard);
    User kestrel = createUser("kestrel", "mice", 2000, false);
    User goose = createUser("goose", "snails", 13000, true);
    User pelican = createUser("pelican", "fish", 15000, true);
    User dove = createUser("dove", "insects", 1600, false);
    addMembers(birds, kestrel, goose, pelican, dove);
    User salamander = createUser("salamander", "insects", 800, true);
    goldenToad = createUser("golden toad", "insects", 700, false);
    User poisonDartFrog = createUser("poison dart frog", "insects", 40, false);
    addMembers(amphibians, salamander, goldenToad, poisonDartFrog);
    setProperty("canFly", vf.createValue(true), bee, fly, kestrel, goose, pelican, dove);
    setProperty("poisonous", vf.createValue(true), blackWidow, bee, poisonDartFrog);
    setProperty("poisonous", vf.createValue(false), turtle, lemur);
    setProperty("hasWings", vf.createValue(false), blackWidow, gardenSpider, jumpingSpider, ant, jackrabbit, deer, opossum, kangaroo, elephant, lemur, gibbon, crocodile, turtle, lizard, salamander, goldenToad, poisonDartFrog);
    setProperty("color", vf.createValue("black"), blackWidow, gardenSpider, ant, fly, lizard, salamander);
    setProperty("color", vf.createValue("WHITE"), opossum, goose, pelican, dove);
    setProperty("color", vf.createValue("gold"), goldenToad);
    setProperty("numberOfLegs", vf.createValue(2), kangaroo, gibbon, kestrel, goose, dove);
    setProperty("numberOfLegs", vf.createValue(4), jackrabbit, deer, opossum, elephant, lemur, crocodile, turtle, lizard, salamander, goldenToad, poisonDartFrog);
    setProperty("numberOfLegs", vf.createValue(6), ant, bee, fly);
    setProperty("numberOfLegs", vf.createValue(8), blackWidow, gardenSpider, jumpingSpider);
    // testing ignore-case with sort order
    setProperty("continent", vf.createValue("africa"), lemur, gibbon);
    setProperty("continent", vf.createValue("Africa"), elephant);
    setProperty("continent", vf.createValue("australia"), kangaroo);
    setProperty("continent", vf.createValue("America"), opossum);
    elephant.getImpersonation().grantImpersonation(jackrabbit.getPrincipal());
    elephant.getImpersonation().grantImpersonation(backslash.getPrincipal());
    authorizables.addAll(users);
    authorizables.addAll(groups);
    if (!userMgr.isAutoSave()) {
        superuser.save();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 100 with Authorizable

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

the class UserQueryTest method testImpersonation.

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

        public <T> void build(QueryBuilder<T> builder) {
            builder.setCondition(builder.impersonates("jackrabbit"));
        }
    });
    Iterator<User> expected = Iterators.singletonIterator(elephant);
    assertTrue(result.hasNext());
    assertSameElements(expected, result);
}
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) 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