Search in sources :

Example 91 with JackrabbitSession

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

the class L7_ImpersonationTest method testAdvancedImpersonationTest.

public void testAdvancedImpersonationTest() throws RepositoryException {
    // EXERCISE: change the permission setup such that the test-user is allowed to make himself an impersonator of 'another' user.
    Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID()));
    sessionList.add(testSession);
    UserManager uMgr = ((JackrabbitSession) testSession).getUserManager();
    User another = uMgr.getAuthorizable(anotherUser.getID(), User.class);
    assertNotNull(another);
    Principal princ = uMgr.getAuthorizable(testUser.getID()).getPrincipal();
    another.getImpersonation().grantImpersonation(princ);
    testSession.save();
    testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])).logout();
    try {
        Session s = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0]));
        sessionList.add(s);
        fail("Test user must no longer be able to edit the impersonation of the test user");
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) LoginException(javax.jcr.LoginException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 92 with JackrabbitSession

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

the class L4_PrivilegesAndPermissionsTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (testSession != null && testSession.isLive()) {
            testSession.logout();
        }
        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
        if (testUser != null) {
            testUser.remove();
        }
        Authorizable testGroup = uMgr.getAuthorizable(testGroupPrincipal);
        if (testGroup != null) {
            testGroup.remove();
        }
        superuser.save();
    } finally {
        super.tearDown();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 93 with JackrabbitSession

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

the class L5_SpecialPermissionsTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (testSession != null && testSession.isLive()) {
            testSession.logout();
        }
        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
        if (testUser != null) {
            testUser.remove();
        }
        if (testUser2 != null) {
            testUser2.remove();
        }
        Authorizable testGroup = uMgr.getAuthorizable(testGroupPrincipal);
        if (testGroup != null) {
            testGroup.remove();
        }
        removePolicies(paths);
        superuser.save();
    } finally {
        super.tearDown();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 94 with JackrabbitSession

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

the class L5_SpecialPermissionsTest method testRepositoryLevelPrivileges.

public void testRepositoryLevelPrivileges() throws RepositoryException {
    // EXERCISE : setup the permissions such that test-session can register a
    // - new namespace|node type|privilege (note: workspace management not yet supported)
    // EXERCISE: refactory the test to verify that granting these privs at 'childPath' doesn;t have the desired effect.
    JackrabbitSession s = (JackrabbitSession) createTestSession();
    NamespaceRegistry nsRegistry = s.getWorkspace().getNamespaceRegistry();
    nsRegistry.registerNamespace("jr", "http://jackrabbit.apache.org");
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 95 with JackrabbitSession

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

the class L7_PrivilegeDiscoveryTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        userSession.logout();
        superuser.getNode(testPath).remove();
        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
        Authorizable a = uMgr.getAuthorizable("u");
        if (a != null) {
            a.remove();
        }
        a = uMgr.getAuthorizable("g");
        if (a != null) {
            a.remove();
        }
        superuser.save();
    } finally {
        super.tearDown();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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