Search in sources :

Example 1 with PasswordAlgorithmFactory

use of org.graylog2.security.PasswordAlgorithmFactory in project graylog2-server by Graylog2.

the class MigrationHelpersTest method newUser.

private User newUser(Permissions permissions) {
    final BCryptPasswordAlgorithm passwordAlgorithm = new BCryptPasswordAlgorithm(10);
    final PasswordAlgorithmFactory passwordAlgorithmFactory = new PasswordAlgorithmFactory(Collections.emptyMap(), passwordAlgorithm);
    return new UserImpl(passwordAlgorithmFactory, permissions, ImmutableMap.of());
}
Also used : PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) BCryptPasswordAlgorithm(org.graylog2.security.hashing.BCryptPasswordAlgorithm) UserImpl(org.graylog2.users.UserImpl)

Example 2 with PasswordAlgorithmFactory

use of org.graylog2.security.PasswordAlgorithmFactory 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 3 with PasswordAlgorithmFactory

use of org.graylog2.security.PasswordAlgorithmFactory 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 4 with PasswordAlgorithmFactory

use of org.graylog2.security.PasswordAlgorithmFactory 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 5 with PasswordAlgorithmFactory

use of org.graylog2.security.PasswordAlgorithmFactory 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)

Aggregations

Test (org.junit.Test)5 Permissions (org.graylog2.shared.security.Permissions)4 Permission (org.apache.shiro.authz.Permission)1 AllPermission (org.apache.shiro.authz.permission.AllPermission)1 CaseSensitiveWildcardPermission (org.graylog.security.permissions.CaseSensitiveWildcardPermission)1 PasswordAlgorithm (org.graylog2.plugin.security.PasswordAlgorithm)1 PasswordAlgorithmFactory (org.graylog2.security.PasswordAlgorithmFactory)1 BCryptPasswordAlgorithm (org.graylog2.security.hashing.BCryptPasswordAlgorithm)1 UserImpl (org.graylog2.users.UserImpl)1