@Transactional public User save(User user, boolean changePassword) { if (changePassword) { user.setPassword(passwordEncoder.encode(user.getPassword())); } else if (!user.isNew()) { user.setPassword(findOne(user.getId()).getPassword()); } return userRepository.saveAndFlush(user); }
@Transactional(readOnly = true) @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); if (user == null) { throw new UsernameNotFoundException("The username could not be found on database."); } return user; }
@Override @Transactional(readOnly = true) public List<User> findAll() { List<User> resultList = new ArrayList<User>(); if (DilectuUtils.isAdministrator()) { resultList = userRepository.findAll(); } else { List<User> userList = findByTenant(TenantContextHolder.getTenant()); for (User user : userList) { if (!user.getGroup().getPermissions().contains(UserPermission.ADMIN)) { resultList.add(user); } } } return resultList; }
@Override @Transactional(readOnly = true) public List<User> findAll(Specification<User> specification) { return userRepository.findAll(specification); }
@Transactional(readOnly = true) @Override public User findSystemUser() { return userRepository.findByUsername(SYSTEM_LOGIN); }
@Transactional(readOnly = true) @Override public User findOne(Long id) { return userRepository.findOne(id); }
@Transactional(readOnly = true) @Override public User findByUsername(String username) { return userRepository.findByUsername(username); }
@Override @Transactional(readOnly = true) public List<User> findByTenant(String tenant) { return userRepository.findByTenant(tenant); }
@Override @Transactional(readOnly = true) public List<User> findUserUniqueUsername(User instance) { return userRepository.findAll(UserSpecification.isUniqueUsername(instance)); }