Search in sources :

Example 1 with RoleService

use of org.graylog2.users.RoleService in project graylog2-server by Graylog2.

the class UserServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    this.mongoConnection = mongoRule.getMongoConnection();
    this.configuration = new Configuration();
    this.userFactory = new UserImplFactory(configuration);
    this.permissions = new Permissions(ImmutableSet.of(new RestPermissions()));
    this.userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionsResolver);
    when(roleService.getAdminRoleObjectId()).thenReturn("deadbeef");
}
Also used : RestPermissions(org.graylog2.shared.security.RestPermissions) Configuration(org.graylog2.Configuration) RestPermissions(org.graylog2.shared.security.RestPermissions) Permissions(org.graylog2.shared.security.Permissions) Before(org.junit.Before)

Example 2 with RoleService

use of org.graylog2.users.RoleService in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetPermissionsForUser.

@Test
public void testGetPermissionsForUser() throws Exception {
    final InMemoryRolePermissionResolver permissionResolver = mock(InMemoryRolePermissionResolver.class);
    final UserService userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionResolver);
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    user.setName("user");
    final Role role = createRole("Foo");
    user.setRoleIds(Collections.singleton(role.getId()));
    user.setPermissions(Collections.singletonList("hello:world"));
    when(permissionResolver.resolveStringPermission(role.getId())).thenReturn(Collections.singleton("foo:bar"));
    assertThat(userService.getPermissionsForUser(user)).containsOnly("users:passwordchange:user", "users:edit:user", "foo:bar", "hello:world");
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) UserService(org.graylog2.shared.users.UserService) InMemoryRolePermissionResolver(org.graylog2.security.InMemoryRolePermissionResolver) Test(org.junit.Test)

Aggregations

Configuration (org.graylog2.Configuration)2 InMemoryRolePermissionResolver (org.graylog2.security.InMemoryRolePermissionResolver)1 Permissions (org.graylog2.shared.security.Permissions)1 RestPermissions (org.graylog2.shared.security.RestPermissions)1 Role (org.graylog2.shared.users.Role)1 UserService (org.graylog2.shared.users.UserService)1 Before (org.junit.Before)1 Test (org.junit.Test)1