use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class UserImplTest method getPermissionsReturnsListOfPermissions.
@Test
public void getPermissionsReturnsListOfPermissions() throws Exception {
final Permissions permissions = new Permissions(Collections.emptySet());
final List<String> customPermissions = Collections.singletonList("subject:action");
final Map<String, Object> fields = ImmutableMap.of(UserImpl.USERNAME, "foobar", UserImpl.PERMISSIONS, customPermissions);
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
assertThat(user.getPermissions()).containsAll(permissions.userSelfEditPermissions("foobar")).contains("subject:action");
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class UserImplTest method getPermissionsWorksWithEmptyPermissions.
@Test
public void getPermissionsWorksWithEmptyPermissions() throws Exception {
final Permissions permissions = new Permissions(Collections.emptySet());
final Map<String, Object> fields = Collections.singletonMap(UserImpl.USERNAME, "foobar");
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
assertThat(user.getPermissions()).containsAll(permissions.userSelfEditPermissions("foobar"));
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class UserImplTest method permissionsArentModified.
@Test
public void permissionsArentModified() {
final Permissions permissions = new Permissions(Collections.emptySet());
final Map<String, Object> fields = Collections.singletonMap(UserImpl.USERNAME, "foobar");
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
final List<String> newPermissions = ImmutableList.<String>builder().addAll(user.getPermissions()).add("perm:1").build();
user.setPermissions(newPermissions);
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class UserImplTest method getObjectPermissions.
@Test
public void getObjectPermissions() {
final Permissions permissions = new Permissions(Collections.emptySet());
final List<String> customPermissions = ImmutableList.of("subject:action", "*");
final Map<String, Object> fields = ImmutableMap.of(UserImpl.USERNAME, "foobar", UserImpl.PERMISSIONS, customPermissions);
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
final Set<Permission> userSelfEditPermissions = permissions.userSelfEditPermissions("foobar").stream().map(CaseSensitiveWildcardPermission::new).collect(Collectors.toSet());
assertThat(user.getObjectPermissions()).containsAll(userSelfEditPermissions).contains(new CaseSensitiveWildcardPermission("subject:action")).extracting("class").containsOnlyOnce(AllPermission.class);
}
use of org.graylog2.users.UserImpl 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();
}
Aggregations