Search in sources :

Example 16 with JackrabbitSession

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

the class AddMembersTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        if (!ImportBehavior.NAME_BESTEFFORT.equals(importBehavior)) {
            authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER + "0");
            if (authorizable != null) {
                Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
                n.remove();
            }
        }
        s.save();
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 17 with JackrabbitSession

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

the class AbstractLoginTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        AccessControlUtils.addAccessControlEntry(s, "/", EveryonePrincipal.getInstance(), new String[] { Privilege.JCR_READ }, true);
        if (USER.equals(runAsUser)) {
            ((JackrabbitSession) s).getUserManager().createUser(USER, USER);
        }
    } finally {
        s.save();
        s.logout();
    }
}
Also used : Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 18 with JackrabbitSession

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

the class AbstractLoginTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER);
        if (authorizable != null) {
            authorizable.remove();
            s.save();
        }
    } finally {
        s.logout();
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 19 with JackrabbitSession

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

the class ACLTemplateTest method testMultiplePrincipals.

public void testMultiplePrincipals() throws RepositoryException, NotExecutableException {
    PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
    Principal everyone = pMgr.getEveryone();
    Principal grPrincipal = null;
    PrincipalIterator it = pMgr.findPrincipals("", PrincipalManager.SEARCH_TYPE_GROUP);
    while (it.hasNext()) {
        Group gr = (Group) it.nextPrincipal();
        if (!everyone.equals(gr)) {
            grPrincipal = gr;
        }
    }
    if (grPrincipal == null || grPrincipal.equals(everyone)) {
        throw new NotExecutableException();
    }
    Privilege[] privs = privilegesFromName(Privilege.JCR_READ);
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    pt.addAccessControlEntry(testPrincipal, privs);
    assertFalse(pt.addAccessControlEntry(testPrincipal, privs));
    // add same privileges for another principal -> must modify as well.
    assertTrue(pt.addAccessControlEntry(everyone, privs));
    // .. 2 entries must be present.
    assertTrue(pt.getAccessControlEntries().length == 2);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) Group(java.security.acl.Group) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal)

Example 20 with JackrabbitSession

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

the class ReadTest method testDenyGroupPathAllowEveryoneChildPath.

public void testDenyGroupPathAllowEveryoneChildPath() 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 'childNPath'
         */
    givePrivileges(path, everyone, privileges, getRestrictions(superuser, childNPath));
    Session testSession = getTestSession();
    assertTrue(testSession.nodeExists(childNPath));
}
Also used : Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

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