Search in sources :

Example 66 with UserManager

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

the class AuthorizableImplTest method testHashCode.

/**
     * @since OAK 1.0
     */
@Test
public void testHashCode() throws Exception {
    Authorizable user = userMgr.getAuthorizable(testUser.getID());
    Authorizable group = userMgr.getAuthorizable(testGroup.getID());
    Map<Authorizable, Authorizable> sameHashCode = new HashMap();
    sameHashCode.put(testUser, testUser);
    sameHashCode.put(testGroup, testGroup);
    sameHashCode.put(user, user);
    sameHashCode.put(group, group);
    sameHashCode.put(testUser, user);
    sameHashCode.put(testGroup, group);
    for (Map.Entry entry : sameHashCode.entrySet()) {
        assertEquals(entry.getKey().hashCode(), entry.getValue().hashCode());
    }
    UserManager otherUserManager = getUserConfiguration().getUserManager(root, getNamePathMapper());
    user = otherUserManager.getAuthorizable(testUser.getID());
    group = otherUserManager.getAuthorizable(testGroup.getID());
    Map<Authorizable, Authorizable> notSameHashCode = new HashMap();
    notSameHashCode.put(testUser, testGroup);
    notSameHashCode.put(user, group);
    notSameHashCode.put(testUser, user);
    notSameHashCode.put(testGroup, group);
    for (Map.Entry entry : notSameHashCode.entrySet()) {
        assertFalse(entry.getKey().hashCode() == entry.getValue().hashCode());
    }
}
Also used : HashMap(java.util.HashMap) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) HashMap(java.util.HashMap) Map(java.util.Map) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 67 with UserManager

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

the class AuthorizablePropertyTest method testSingleToMultiValued.

@Test
public void testSingleToMultiValued() throws Exception {
    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) Test(org.junit.Test)

Example 68 with UserManager

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

the class AbstractRemoveMembersByIdTest method before.

@Override
public void before() throws Exception {
    super.before();
    UserManager uMgr = getUserManager(root);
    for (String id : NON_EXISTING_IDS) {
        assertNull(uMgr.getAuthorizable(id));
    }
    testGroup = uMgr.createGroup("testGroup" + UUID.randomUUID().toString());
    memberGroup = uMgr.createGroup("memberGroup" + UUID.randomUUID().toString());
    testGroup.addMember(memberGroup);
    testGroup.addMember(getTestUser());
    root.commit();
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager)

Example 69 with UserManager

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

the class AuthorizableImplTest method testNotEqualAuthorizables.

/**
     * @since OAK 1.0
     */
@Test
public void testNotEqualAuthorizables() throws Exception {
    UserManager otherUserManager = getUserConfiguration().getUserManager(root, getNamePathMapper());
    Authorizable user = otherUserManager.getAuthorizable(testUser.getID());
    Authorizable group = otherUserManager.getAuthorizable(testGroup.getID());
    Map<Authorizable, Authorizable> notEqual = new HashMap();
    notEqual.put(testUser, testGroup);
    notEqual.put(user, group);
    notEqual.put(testUser, user);
    notEqual.put(testGroup, group);
    for (Map.Entry entry : notEqual.entrySet()) {
        assertFalse(entry.getKey().equals(entry.getValue()));
        assertFalse(entry.getValue().equals(entry.getKey()));
    }
}
Also used : HashMap(java.util.HashMap) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) HashMap(java.util.HashMap) Map(java.util.Map) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 70 with UserManager

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

the class L3_PrecedenceRulesTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (testSession != null && testSession.isLive()) {
            testSession.logout();
        }
        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
        Authorizable testUser = uMgr.getAuthorizable(testPrincipal);
        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)

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