use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UsersResource method listUsers.
@GET
@RequiresPermissions(RestPermissions.USERS_LIST)
@ApiOperation(value = "List all users", notes = "The permissions assigned to the users are always included.")
public UserList listUsers() {
final List<User> users = userService.loadAll();
final Collection<MongoDbSession> sessions = sessionService.loadAll();
// among all active sessions, find the last recently used for each user
//noinspection OptionalGetWithoutIsPresent
final Map<String, Optional<MongoDbSession>> lastSessionForUser = sessions.stream().filter(s -> s.getUsernameAttribute().isPresent()).collect(groupingBy(s -> s.getUsernameAttribute().get(), maxBy(Comparator.comparing(MongoDbSession::getLastAccessTime))));
final List<UserSummary> resultUsers = Lists.newArrayListWithCapacity(users.size() + 1);
final User adminUser = userService.getAdminUser();
resultUsers.add(toUserResponse(adminUser, lastSessionForUser.getOrDefault(adminUser.getName(), Optional.empty())));
for (User user : users) {
resultUsers.add(toUserResponse(user, lastSessionForUser.getOrDefault(user.getName(), Optional.empty())));
}
return UserList.create(resultUsers);
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class InMemoryRolePermissionResolver method resolveStringPermission.
@Nonnull
public Set<String> resolveStringPermission(String roleId) {
final ImmutableMap<String, Role> index = idToRoleIndex.get();
final Role role = index.get(roleId);
if (role == null) {
log.debug("Unknown role {}, cannot resolve permissions.", roleId);
return Collections.emptySet();
}
final Set<String> permissions = role.getPermissions();
if (permissions == null) {
log.debug("Role {} has no permissions assigned, cannot resolve permissions.", roleId);
return Collections.emptySet();
}
return permissions;
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class PermissionsTest method testPluginPermissions.
@Test
public void testPluginPermissions() throws Exception {
final ImmutableSet<Permission> pluginPermissions = ImmutableSet.of(Permission.create("foo:bar", "bar"), Permission.create("foo:baz", "baz"), Permission.create("hello:world", "hello"));
final PermissionsPluginPermissions plugin = new PermissionsPluginPermissions(pluginPermissions);
final Permissions permissions = new Permissions(ImmutableSet.of(restPermissions, plugin));
assertThat(permissions.allPermissionsMap().get("foo")).containsOnly("bar", "baz");
assertThat(permissions.allPermissionsMap().get("hello")).containsOnly("world");
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class PermissionsTest method setUp.
@Before
public void setUp() throws Exception {
restPermissions = new RestPermissions();
permissions = new Permissions(ImmutableSet.of(restPermissions));
}
use of org.graylog2.shared.security.Permissions 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");
}
Aggregations