Search in sources :

Example 11 with LdapEntry

use of org.graylog2.shared.security.ldap.LdapEntry in project graylog2-server by Graylog2.

the class LdapConnectorTest method testFindGroupsWithWhitespace.

@Test
public void testFindGroupsWithWhitespace() throws Exception {
    final LdapEntry ldapEntry1 = new LdapEntry();
    ldapEntry1.setDn("cn=John Doe,ou=users,dc=example,dc=com");
    ldapEntry1.put("uid", "john");
    final LdapEntry ldapEntry2 = new LdapEntry();
    ldapEntry2.setDn("cn=John Doe,  ou=users, dc=example, dc=com");
    ldapEntry2.put("uid", "john");
    final Set<String> groups1 = connector.findGroups(connection, "ou=groups,dc=example,dc=com", "(objectClass=groupOfUniqueNames)", "cn", ldapEntry1);
    final Set<String> groups2 = connector.findGroups(connection, "ou=groups,dc=example,dc=com", "(objectClass=groupOfUniqueNames)", "cn", ldapEntry2);
    assertThat(groups1).hasSize(2).containsOnly("Whitespace Engineers", "Engineers");
    assertThat(groups2).hasSize(2).containsOnly("Whitespace Engineers", "Engineers");
}
Also used : LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) Test(org.junit.Test)

Example 12 with LdapEntry

use of org.graylog2.shared.security.ldap.LdapEntry in project graylog2-server by Graylog2.

the class LdapConnectorTest method testGroupOfNamesLookup.

@Test
public void testGroupOfNamesLookup() throws Exception {
    final LdapEntry entry = connector.search(connection, "ou=users,dc=example,dc=com", "(&(objectClass=posixAccount)(uid={0}))", "cn", "john", false, "ou=groups,dc=example,dc=com", "cn", "(objectClass=groupOfNames)");
    assertThat(entry).isNotNull();
    assertThat(entry.getDn()).isNotNull().isEqualTo("cn=John Doe,ou=users,dc=example,dc=com");
    assertThat(entry.getGroups()).hasSize(1).contains("QA");
}
Also used : LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) Test(org.junit.Test)

Example 13 with LdapEntry

use of org.graylog2.shared.security.ldap.LdapEntry in project graylog2-server by Graylog2.

the class LdapUserAuthenticatorTest method testSyncFromLdapEntryExistingUser.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSyncFromLdapEntryExistingUser() {
    final LdapUserAuthenticator authenticator = spy(new LdapUserAuthenticator(ldapConnector, ldapSettingsService, userService, mock(RoleService.class), DateTimeZone.UTC));
    final LdapEntry userEntry = new LdapEntry();
    final LdapSettings ldapSettings = mock(LdapSettings.class);
    when(ldapSettings.getDisplayNameAttribute()).thenReturn("displayName");
    when(ldapSettings.getDefaultGroupId()).thenReturn("54e3deadbeefdeadbeef0001");
    when(ldapSettings.getAdditionalDefaultGroupIds()).thenReturn(Collections.emptySet());
    final HashMap<String, Object> fields = Maps.newHashMap();
    fields.put("permissions", Collections.singletonList("test:permission:1234"));
    when(userService.load(anyString())).thenReturn(new UserImpl(null, new Permissions(Collections.emptySet()), fields));
    final User ldapUser = authenticator.syncFromLdapEntry(userEntry, ldapSettings, "user");
    assertThat(ldapUser).isNotNull();
    assertThat(ldapUser.getPermissions()).contains("test:permission:1234");
    assertThat(ldapUser.isExternalUser()).isTrue();
    assertThat(ldapUser.getName()).isEqualTo("user");
    assertThat(ldapUser.getEmail()).isEqualTo("user@localhost");
    assertThat(ldapUser.getHashedPassword()).isEqualTo("User synced from LDAP.");
    assertThat(ldapUser.getTimeZone()).isEqualTo(DateTimeZone.UTC);
    assertThat(ldapUser.getRoleIds()).containsOnly("54e3deadbeefdeadbeef0001");
    assertThat(ldapUser.getPermissions()).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 14 with LdapEntry

use of org.graylog2.shared.security.ldap.LdapEntry in project graylog2-server by Graylog2.

the class LdapUserAuthenticatorTest method testSyncFromLdapEntry.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSyncFromLdapEntry() {
    final LdapUserAuthenticator authenticator = spy(new LdapUserAuthenticator(ldapConnector, ldapSettingsService, userService, mock(RoleService.class), DateTimeZone.UTC));
    final LdapEntry userEntry = new LdapEntry();
    final LdapSettings ldapSettings = mock(LdapSettings.class);
    when(ldapSettings.getDisplayNameAttribute()).thenReturn("displayName");
    when(ldapSettings.getDefaultGroupId()).thenReturn("54e3deadbeefdeadbeef0001");
    when(ldapSettings.getAdditionalDefaultGroupIds()).thenReturn(Collections.emptySet());
    when(userService.create()).thenReturn(new UserImpl(null, new Permissions(Collections.emptySet()), Maps.newHashMap()));
    final User ldapUser = authenticator.syncFromLdapEntry(userEntry, ldapSettings, "user");
    assertThat(ldapUser).isNotNull();
    assertThat(ldapUser.isExternalUser()).isTrue();
    assertThat(ldapUser.getName()).isEqualTo("user");
    assertThat(ldapUser.getEmail()).isEqualTo("user@localhost");
    assertThat(ldapUser.getHashedPassword()).isEqualTo("User synced from LDAP.");
    assertThat(ldapUser.getTimeZone()).isEqualTo(DateTimeZone.UTC);
    assertThat(ldapUser.getRoleIds()).containsOnly("54e3deadbeefdeadbeef0001");
    assertThat(ldapUser.getPermissions()).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

LdapEntry (org.graylog2.shared.security.ldap.LdapEntry)12 Test (org.junit.Test)8 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)4 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 User (org.graylog2.plugin.database.users.User)4 IOException (java.io.IOException)3 ValidationException (org.graylog2.plugin.database.ValidationException)3 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)3 UserImpl (org.graylog2.users.UserImpl)3 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)2 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 Nullable (javax.annotation.Nullable)2 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)2 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 LdapConnectionConfig (org.apache.directory.ldap.client.api.LdapConnectionConfig)2 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)2 NotFoundException (org.graylog2.database.NotFoundException)2 TrustAllX509TrustManager (org.graylog2.security.TrustAllX509TrustManager)2