Search in sources :

Example 41 with UserManager

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

the class SyncMBeanImplTest method testPurgeOrphanedUsers.

@Test
public void testPurgeOrphanedUsers() throws Exception {
    syncMBean.syncAllExternalUsers();
    sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp);
    sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp);
    String[] result = syncMBean.purgeOrphanedUsers();
    assertResultMessages(result, ImmutableMap.of("thirdUser", "del", "g", "del"));
    UserManager userManager = getUserManager();
    assertNull(userManager.getAuthorizable("thirdUser"));
    assertNull(userManager.getAuthorizable("g"));
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) TestIdentityProvider(org.apache.jackrabbit.oak.spi.security.authentication.external.TestIdentityProvider) Test(org.junit.Test)

Example 42 with UserManager

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

the class SyncMBeanImplTest method testSyncExternalUsersLastSyncedProperty.

@Test
public void testSyncExternalUsersLastSyncedProperty() throws Exception {
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    syncMBean.syncExternalUsers(externalId);
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    long lastSynced = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class);
        long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
        assertTrue(lastSynced == groupLastSynced);
    }
    while (System.currentTimeMillis() <= lastSynced) {
    // wait for system time to move
    }
    // default value for forceGroup sync is defined to be 'true' => verify result
    syncMBean.syncExternalUsers(externalId);
    userManager = getUserManager();
    testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    long lastSynced2 = testUser.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
    assertTrue("lastSynced: " + lastSynced + ", lastSynced2: " + lastSynced2, lastSynced < lastSynced2);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        Group gr = userManager.getAuthorizable(groupRef.getId(), Group.class);
        long groupLastSynced = gr.getProperty(DefaultSyncContext.REP_LAST_SYNCED)[0].getLong();
        assertTrue(lastSynced2 == groupLastSynced);
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 43 with UserManager

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

the class SyncMBeanImplTest method testSyncAllExternalUsersAgain.

@Test
public void testSyncAllExternalUsersAgain() throws Exception {
    syncMBean.syncAllExternalUsers();
    // sync again
    String[] result = syncMBean.syncAllExternalUsers();
    // verify result
    Map<String, String> expected = getExpectedUserResult("upd", false);
    assertResultMessages(result, expected);
    UserManager userManager = getUserManager();
    for (String id : expected.keySet()) {
        ExternalIdentity ei = idp.getUser(id);
        if (ei == null) {
            ei = idp.getGroup(id);
        }
        assertSync(ei, userManager);
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) Test(org.junit.Test)

Example 44 with UserManager

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

the class SyncMBeanImplTest method testPurgeOrphanedUsersThrowingHandler2.

/**
     * @see <a href="https://issues.apache.org/jira/browse/OAK-4362">OAK-4362</a>
     */
@Test
public void testPurgeOrphanedUsersThrowingHandler2() throws Exception {
    sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp);
    sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp);
    String[] result = createThrowingSyncMBean(true).purgeOrphanedUsers();
    assertResultMessages(result, ImmutableMap.of("thirdUser", "ERR", "g", "ERR"));
    UserManager userManager = getUserManager();
    assertNotNull(userManager.getAuthorizable("thirdUser"));
    assertNotNull(userManager.getAuthorizable("g"));
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) TestIdentityProvider(org.apache.jackrabbit.oak.spi.security.authentication.external.TestIdentityProvider) Test(org.junit.Test)

Example 45 with UserManager

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

the class SyncMBeanImplTest method testInitialSyncExternalUsersNoNesting.

@Test
public void testInitialSyncExternalUsersNoNesting() throws Exception {
    syncConfig.user().setMembershipNestingDepth(-1);
    ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_TEST_USER);
    String[] externalId = new String[] { externalUser.getExternalId().getString() };
    String[] result = syncMBean.syncExternalUsers(externalId);
    assertResultMessages(result, TestIdentityProvider.ID_TEST_USER, "add");
    UserManager userManager = getUserManager();
    User testUser = userManager.getAuthorizable(externalUser.getId(), User.class);
    assertNotNull(testUser);
    for (ExternalIdentityRef groupRef : externalUser.getDeclaredGroups()) {
        assertNull(userManager.getAuthorizable(groupRef.getId()));
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

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