Search in sources :

Example 21 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class ReadTest method testAllowEveryoneDenyGroup.

public void testAllowEveryoneDenyGroup() throws Exception {
    Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
    Principal group = getTestGroup().getPrincipal();
    Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
    /*
         allow READ privilege for everyone at 'path'
         */
    givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
    /*
         deny READ privilege for group at 'path'
         */
    withdrawPrivileges(path, group, privileges, getRestrictions(superuser, path));
    Session testSession = getTestSession();
    assertFalse(testSession.nodeExists(path));
}
Also used : Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 22 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class ReadTest method testDenyGroupAllowEveryone.

public void testDenyGroupAllowEveryone() throws Exception {
    Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
    Principal group = getTestGroup().getPrincipal();
    Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
    /*
         deny READ privilege for group at 'path'
         */
    withdrawPrivileges(path, group, privileges, getRestrictions(superuser, path));
    /*
         allow READ privilege for everyone at 'path'
         */
    givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
    Session testSession = getTestSession();
    assertTrue(testSession.nodeExists(path));
}
Also used : Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 23 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class ReadTest method testAllowEveryonePathDenyGroupChildPath.

public void testAllowEveryonePathDenyGroupChildPath() throws Exception {
    Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
    Principal group = getTestGroup().getPrincipal();
    Principal everyone = ((JackrabbitSession) superuser).getPrincipalManager().getEveryone();
    /*
         allow READ privilege for everyone at 'path'
         */
    givePrivileges(path, everyone, privileges, getRestrictions(superuser, path));
    /*
         deny READ privilege for group at 'childNPath'
         */
    withdrawPrivileges(path, group, privileges, getRestrictions(superuser, childNPath));
    Session testSession = getTestSession();
    assertFalse(testSession.nodeExists(childNPath));
}
Also used : Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 24 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class UserTest method testDisable.

public void testDisable() throws Exception {
    boolean remove = false;
    Session s = getHelper().getReadOnlySession();
    User user = null;
    String userID = null;
    String pw = "";
    try {
        User readonlyUser = getTestUser(s);
        if (readonlyUser.isAdmin()) {
            // configured readonly user is admin
            // -> need to create another test user
            pw = "test";
            userID = getUserManager(superuser).createUser(getTestPrincipal().getName(), pw).getID();
            remove = true;
        } else {
            userID = readonlyUser.getID();
        }
        user = (User) getUserManager(superuser).getAuthorizable(userID);
        // by default a user isn't disabled
        assertFalse(user.isDisabled());
        assertNull(user.getDisabledReason());
        // disable user
        String reason = "readonly user is disabled!";
        user.disable(reason);
        save(superuser);
        assertTrue(user.isDisabled());
        assertEquals(reason, user.getDisabledReason());
        // user must still be retrievable from user manager
        assertNotNull(getUserManager(superuser).getAuthorizable(userID));
        // ... and from principal manager as well
        assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(user.getPrincipal().getName()));
        // -> login must fail
        try {
            Session ss = getHelper().getRepository().login(new SimpleCredentials(userID, pw.toCharArray()));
            ss.logout();
            fail("A disabled user must not be allowed to login any more");
        } catch (LoginException e) {
        // success
        }
        // -> impersonating this user must fail
        try {
            Session ss = superuser.impersonate(new SimpleCredentials(userID, new char[0]));
            ss.logout();
            fail("A disabled user cannot be impersonated any more.");
        } catch (LoginException e) {
        // success
        }
        // enable user again
        user.disable(null);
        save(superuser);
        assertFalse(user.isDisabled());
        // -> login must succeed again
        getHelper().getRepository().login(new SimpleCredentials(userID, pw.toCharArray())).logout();
    } finally {
        s.logout();
        if (user != null) {
            if (user.isDisabled()) {
                user.disable(null);
            }
            if (remove) {
                user.remove();
                save(superuser);
            }
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) LoginException(javax.jcr.LoginException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 25 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.

the class CugImportBaseTest method testCugValidPrincipals.

@Test
public void testCugValidPrincipals() throws Exception {
    testGroup = ((JackrabbitSession) adminSession).getUserManager().createGroup(new PrincipalImpl(TEST_GROUP_PRINCIPAL_NAME));
    adminSession.save();
    Node targetNode = getTargetNode();
    targetNode.addMixin(CugConstants.MIX_REP_CUG_MIXIN);
    doImport(getTargetPath(), XML_CUG_POLICY);
    adminSession.save();
}
Also used : Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Aggregations

JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)114 UserManager (org.apache.jackrabbit.api.security.user.UserManager)51 Session (javax.jcr.Session)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)34 Node (javax.jcr.Node)25 Group (org.apache.jackrabbit.api.security.user.Group)25 User (org.apache.jackrabbit.api.security.user.User)24 Principal (java.security.Principal)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Test (org.junit.Test)16 SimpleCredentials (javax.jcr.SimpleCredentials)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)11 RepositoryException (javax.jcr.RepositoryException)10 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 Privilege (javax.jcr.security.Privilege)8 LoginException (javax.jcr.LoginException)6 Property (javax.jcr.Property)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)6 Item (javax.jcr.Item)5