Search in sources :

Example 71 with UserManager

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

the class L4_AuthorizableIdTest method testGetByID.

@Test
public void testGetByID() throws RepositoryException {
    // EXERCISE fix the test-case
    UserManager uMgr = getUserManager(root);
    Group g = uMgr.getAuthorizable(testUser.getID(), Group.class);
    assertEquals(g, uMgr.getAuthorizable(testGroup.getID()));
    assertEquals(g, uMgr.getAuthorizable(testGroup.getPrincipal().getName()));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 72 with UserManager

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

the class L7_PrivilegeDiscoveryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    SimpleCredentials creds = new SimpleCredentials("u", "u".toCharArray());
    UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
    User u = uMgr.createUser(creds.getUserID(), creds.getUserID());
    Group g = uMgr.createGroup("g");
    g.addMember(u);
    uPrincipal = u.getPrincipal();
    gPrincipal = g.getPrincipal();
    Node n = superuser.getNode(testRoot).addNode(nodeName1);
    testPath = n.getPath();
    Property p = n.setProperty(propertyName1, "value");
    propPath = p.getPath();
    Privilege[] privs = AccessControlUtils.privilegesFromNames(superuser, Privilege.JCR_VERSION_MANAGEMENT, Privilege.JCR_ADD_CHILD_NODES, Privilege.JCR_MODIFY_PROPERTIES);
    AccessControlUtils.addAccessControlEntry(superuser, n.getPath(), gPrincipal, privs, true);
    AccessControlUtils.addAccessControlEntry(superuser, n.getPath(), uPrincipal, new String[] { Privilege.JCR_VERSION_MANAGEMENT }, false);
    Node child = n.addNode(nodeName2);
    childPath = child.getPath();
    superuser.save();
    userSession = getHelper().getRepository().login(creds);
    // NOTE the following precondition defined by the test-setup!
    assertTrue(userSession.nodeExists(testPath));
    assertTrue(userSession.nodeExists(childPath));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Privilege(javax.jcr.security.Privilege) Property(javax.jcr.Property)

Example 73 with UserManager

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

the class L3_UserVsPrincipalTest method before.

@Override
public void before() throws Exception {
    super.before();
    UserManager userMgr = getUserManager(root);
    testUser = ExerciseUtility.createTestUser(userMgr);
    testGroup = userMgr.createGroup(testGroupId, testGroupPrincipal, null);
    testGroup.addMember(testUser);
    root.commit();
    principalManager = getPrincipalManager(root);
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager)

Example 74 with UserManager

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

the class ObservationQueueTest method prepareTestData.

@Override
protected void prepareTestData(Session s) throws RepositoryException {
    UserManager uMgr = ((JackrabbitSession) s).getUserManager();
    User user = uMgr.createUser(USER, PASSWORD);
    s.save();
    AccessControlManager acMgr = s.getAccessControlManager();
    JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/");
    tmpl.addEntry(user.getPrincipal(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) }, true, Collections.<String, Value>emptyMap());
    acMgr.setPolicy(tmpl.getPath(), tmpl);
    s.save();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 75 with UserManager

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

the class AbstractRandomizedTest method setupAuthorizables.

protected void setupAuthorizables() throws RepositoryException {
    for (JackrabbitSession s : writeSessions) {
        UserManager userManager = s.getUserManager();
        User user = userManager.createUser(userId, userId);
        Group group = userManager.createGroup("group1");
        group.addMember(user);
        Group group2 = userManager.createGroup("group2");
        group2.addMember(user);
        s.save();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

UserManager (org.apache.jackrabbit.api.security.user.UserManager)234 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)93 Test (org.junit.Test)90 Group (org.apache.jackrabbit.api.security.user.Group)81 User (org.apache.jackrabbit.api.security.user.User)72 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)52 Session (javax.jcr.Session)45 RepositoryException (javax.jcr.RepositoryException)40 Principal (java.security.Principal)38 SimpleCredentials (javax.jcr.SimpleCredentials)34 AccessDeniedException (javax.jcr.AccessDeniedException)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Node (javax.jcr.Node)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)14 Value (javax.jcr.Value)11 Root (org.apache.jackrabbit.oak.api.Root)11 AccessControlManager (javax.jcr.security.AccessControlManager)9 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)9