Search in sources :

Example 6 with UserManager

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

the class WriteTest method testMultipleGroupPermissionsOnNode.

public void testMultipleGroupPermissionsOnNode() throws NotExecutableException, RepositoryException {
    Group testGroup = getTestGroup();
    /* create a second group the test user is member of */
    Principal principal = new TestPrincipal("testGroup" + UUID.randomUUID());
    UserManager umgr = getUserManager(superuser);
    Group group2 = umgr.createGroup(principal);
    try {
        group2.addMember(testUser);
        if (!umgr.isAutoSave() && superuser.hasPendingChanges()) {
            superuser.save();
        }
        /* add privileges for the Group the test-user is member of */
        Privilege[] privileges = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES);
        givePrivileges(path, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path));
        withdrawPrivileges(path, group2.getPrincipal(), privileges, getRestrictions(superuser, path));
        /*
             testuser must get the permissions/privileges inherited from
             the group it is member of.
             the denial of group2 must succeed
            */
        String actions = javax.jcr.Session.ACTION_SET_PROPERTY + "," + javax.jcr.Session.ACTION_READ;
        AccessControlManager testAcMgr = getTestACManager();
        assertFalse(getTestSession().hasPermission(path, actions));
        Privilege[] privs = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES);
        assertFalse(testAcMgr.hasPrivileges(path, privs));
    } finally {
        group2.remove();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Group(org.apache.jackrabbit.api.security.user.Group) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Privilege(javax.jcr.security.Privilege) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 7 with UserManager

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

the class GroupAdministratorTest method testRemoveMembershipForOwnAuthorizable.

public void testRemoveMembershipForOwnAuthorizable() throws RepositoryException, NotExecutableException {
    UserManager umgr = getUserManager(uSession);
    Authorizable user = umgr.getAuthorizable(uID);
    Group gr = (Group) umgr.getAuthorizable(groupAdmin.getID());
    // removing himself from group. should succeed.
    assertTrue(gr.removeMember(user));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Example 8 with UserManager

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

the class GroupAdministratorTest method testIsGroupAdmin.

public void testIsGroupAdmin() throws RepositoryException, NotExecutableException {
    UserManager umgr = getUserManager(uSession);
    Group gr = (Group) umgr.getAuthorizable(grID);
    assertTrue(gr.isMember(umgr.getAuthorizable(uID)));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager)

Example 9 with UserManager

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

the class AuthorizableImplTest method testMultiValuedToSingle.

public void testMultiValuedToSingle() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

Example 10 with UserManager

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

the class AuthorizableImplTest method testSingleToMultiValued.

public void testSingleToMultiValued() throws Exception {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    UserManager uMgr = getUserManager(superuser);
    try {
        Value v = superuser.getValueFactory().createValue("anyValue");
        user.setProperty("someProp", v);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
        Value[] vs = new Value[] { v, v };
        user.setProperty("someProp", vs);
        if (!uMgr.isAutoSave()) {
            superuser.save();
        }
    } finally {
        if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
            superuser.save();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue)

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