All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.molgenis.data.security.user.UserServiceImpl Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data.security.user;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static org.molgenis.data.security.auth.UserMetadata.USER;

import java.util.List;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.molgenis.data.DataService;
import org.molgenis.data.security.auth.User;
import org.molgenis.data.security.auth.UserMetadata;
import org.molgenis.data.support.QueryImpl;
import org.molgenis.security.core.runas.RunAsSystem;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
  private final DataService dataService;

  UserServiceImpl(DataService dataService) {
    this.dataService = requireNonNull(dataService);
  }

  @Override
  @RunAsSystem
  public List getUsers() {
    return dataService.findAll(USER, User.class).collect(toList());
  }

  @Override
  @RunAsSystem
  public List getSuEmailAddresses() {
    Stream superUsers =
        dataService.findAll(
            USER, new QueryImpl().eq(UserMetadata.SUPERUSER, true), User.class);
    return superUsers.map(User::getEmail).collect(toList());
  }

  @Override
  @RunAsSystem
  public @Nullable @CheckForNull User getUser(String username) {
    return dataService.findOne(
        USER, new QueryImpl().eq(UserMetadata.USERNAME, username), User.class);
  }

  @Override
  @RunAsSystem
  public void update(User user) {
    dataService.update(USER, user);
  }

  @Override
  @RunAsSystem
  public User getUserByEmail(String email) {
    return dataService.findOne(
        USER, new QueryImpl().eq(UserMetadata.EMAIL, email), User.class);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy