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");
}
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");
}
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();
}
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();
}
Aggregations