Search in sources :

Example 6 with UserImpl

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");
}
Also used : Permissions(org.graylog2.shared.security.Permissions) Test(org.junit.Test)

Example 7 with UserImpl

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"));
}
Also used : Permissions(org.graylog2.shared.security.Permissions) Test(org.junit.Test)

Example 8 with UserImpl

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);
}
Also used : Permissions(org.graylog2.shared.security.Permissions) Test(org.junit.Test)

Example 9 with UserImpl

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);
}
Also used : Permissions(org.graylog2.shared.security.Permissions) Permission(org.apache.shiro.authz.Permission) AllPermission(org.apache.shiro.authz.permission.AllPermission) CaseSensitiveWildcardPermission(org.graylog.security.permissions.CaseSensitiveWildcardPermission) CaseSensitiveWildcardPermission(org.graylog.security.permissions.CaseSensitiveWildcardPermission) Test(org.junit.Test)

Example 10 with UserImpl

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

Aggregations

Test (org.junit.Test)14 Permissions (org.graylog2.shared.security.Permissions)13 UserImpl (org.graylog2.users.UserImpl)11 PasswordAlgorithmFactory (org.graylog2.security.PasswordAlgorithmFactory)8 User (org.graylog2.plugin.database.users.User)5 HashMap (java.util.HashMap)3 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)3 Role (org.graylog2.shared.users.Role)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 NotificationDto (org.graylog.events.notifications.NotificationDto)2 Configuration (org.graylog2.Configuration)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 MongoConnection (org.graylog2.database.MongoConnection)2 ValidationResult (org.graylog2.plugin.database.validators.ValidationResult)2 LdapEntry (org.graylog2.shared.security.ldap.LdapEntry)2 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)2 UserService (org.graylog2.shared.users.UserService)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)1