Search in sources :

Example 56 with ExternalIdentityRef

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef in project jackrabbit-oak by apache.

the class DefaultSyncHandlerTest method testFindExternalIdentity.

@Test
public void testFindExternalIdentity() throws Exception {
    login(new SimpleCredentials(USER_ID, new char[0])).close();
    root.refresh();
    SyncedIdentity id = syncHandler.findIdentity(userManager, USER_ID);
    assertNotNull("known authorizable should exist", id);
    ExternalIdentityRef ref = id.getExternalIdRef();
    assertNotNull(ref);
    assertEquals("external user should have correct external ref.idp", idp.getName(), ref.getProviderName());
    assertEquals("external user should have correct external ref.id", USER_ID, id.getExternalIdRef().getId());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) DefaultSyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity) SyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity) Test(org.junit.Test)

Example 57 with ExternalIdentityRef

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testSyncMembershipDepth1.

@Test
public void testSyncMembershipDepth1() throws Exception {
    ExternalUser externalUser = idp.listUsers().next();
    Authorizable a = syncCtx.createUser(externalUser);
    syncCtx.syncMembership(externalUser, a, 1);
    assertTrue(root.hasPendingChanges());
    for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
        Group g = userManager.getAuthorizable(ref.getId(), Group.class);
        assertNotNull(g);
        assertTrue(g.isDeclaredMember(a));
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 58 with ExternalIdentityRef

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef in project jackrabbit-oak by apache.

the class LdapIdentityProvider method getDeclaredMemberRefs.

/**
     * Collects the declared (direct) members of a group
     * @param ref the reference to the group
     * @return map of identity refers
     * @throws ExternalIdentityException if an error occurs
     */
Map<String, ExternalIdentityRef> getDeclaredMemberRefs(ExternalIdentityRef ref) throws ExternalIdentityException {
    if (!isMyRef(ref)) {
        return Collections.emptyMap();
    }
    LdapConnection connection = null;
    try {
        Map<String, ExternalIdentityRef> members = new HashMap<String, ExternalIdentityRef>();
        DebugTimer timer = new DebugTimer();
        connection = connect();
        timer.mark("connect");
        Entry entry = connection.lookup(ref.getId());
        timer.mark("lookup");
        Attribute attr = entry.get(config.getGroupMemberAttribute());
        if (attr == null) {
            log.warn("LDAP group does not have configured attribute: {}", config.getGroupMemberAttribute());
        } else {
            for (Value value : attr) {
                ExternalIdentityRef memberRef = new ExternalIdentityRef(value.getString(), this.getName());
                members.put(memberRef.getId(), memberRef);
            }
        }
        timer.mark("iterate");
        if (log.isDebugEnabled()) {
            log.debug("members lookup of {} found {} members. {}", ref.getId(), members.size(), timer.getString());
        }
        return members;
    } catch (Exception e) {
        String msg = "Error during ldap group members lookup.";
        log.error(msg, e);
        throw new ExternalIdentityException(msg, e);
    } finally {
        disconnect(connection);
    }
}
Also used : DebugTimer(org.apache.jackrabbit.oak.commons.DebugTimer) Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) HashMap(java.util.HashMap) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LoginException(javax.security.auth.login.LoginException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExternalIdentityException(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 59 with ExternalIdentityRef

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef in project jackrabbit-oak by apache.

the class LargeLdapProviderTest method assertIfEquals.

public static void assertIfEquals(String message, String[] expected, Iterable<ExternalIdentityRef> result) {
    List<String> dns = new LinkedList<String>();
    for (ExternalIdentityRef ref : result) {
        dns.add(ref.getId());
    }
    Collections.sort(dns);
    Arrays.sort(expected);
    String exp = Text.implode(expected, ",\n");
    String res = Text.implode(dns.toArray(new String[dns.size()]), ",\n");
    assertEquals(message, exp, res);
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) LinkedList(java.util.LinkedList)

Example 60 with ExternalIdentityRef

use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef in project jackrabbit-oak by apache.

the class LargeLdapProviderTest method testGetMembers.

@Test
public void testGetMembers() throws Exception {
    ExternalIdentityRef ref = new ExternalIdentityRef(GROUP_DN, IDP_NAME);
    ExternalIdentity id = idp.getIdentity(ref);
    assertTrue("Group instance", id instanceof ExternalGroup);
    ExternalGroup grp = (ExternalGroup) id;
    assertIfEquals("Group members", TEST_MEMBERS, grp.getDeclaredMembers());
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity) Test(org.junit.Test)

Aggregations

ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)64 Test (org.junit.Test)47 ExternalUser (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser)23 ExternalIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity)18 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)15 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)14 Group (org.apache.jackrabbit.api.security.user.Group)11 User (org.apache.jackrabbit.api.security.user.User)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)7 SyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity)6 Nonnull (javax.annotation.Nonnull)5 DebugTimer (org.apache.jackrabbit.oak.commons.DebugTimer)5 ExternalIdentityException (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException)5 SyncResult (org.apache.jackrabbit.oak.spi.security.authentication.external.SyncResult)5 Principal (java.security.Principal)4 HashMap (java.util.HashMap)4 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 Root (org.apache.jackrabbit.oak.api.Root)4 DefaultSyncedIdentity (org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncedIdentity)4