@Transactional
 public User storeUser(User user) {
   try {
     userRepository.save(user);
   } catch (DataIntegrityViolationException e) {
     LOGGER.error("Error while storing user (DataIntegrityViolationException).", e);
     return null;
   }
   LOGGER.info("User user={} stored.", user);
   return user;
 }
  /**
   * Creates a new tweet and stores it.
   *
   * @return authenticated 'user object
   */
  public User getUser() {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    if (principal instanceof String) {
      return null;
    }

    org.springframework.security.core.userdetails.User userDetails =
        (org.springframework.security.core.userdetails.User) principal;
    User user = userRepository.findByUsername(userDetails.getUsername());
    if (user == null) {
      LOGGER.warn("User from session not found. username={}.", userDetails.getUsername());
      return null;
    }

    return user;
  }
 public boolean emailExists(String email) {
   return email != null && userRepository.findByEmail(email) != null;
 }
 public boolean userExists(String username) {
   return username != null && userRepository.findByUsername(username) != null;
 }
 public User findUser(String username) {
   return userRepository.findByUsername(username);
 }
 public User findUser(long id) {
   return userRepository.findOne(id);
 }
 public List<User> findUsers() {
   return IteratorUtils.toList(userRepository.findAll().iterator());
 }