コード例 #1
0
  /**
   * returns the currently logged in user.
   *
   * @param request the request
   * @return the currently logged user or null (should not happen)
   */
  public final User getCurrentUser(final HttpServletRequest request) {
    Principal principal = request.getUserPrincipal();
    if (principal != null) {
      String name = principal.getName();
      return userService.findByUsername(name);
    }

    return null;
  }
コード例 #2
0
 /**
  * creates a new user.
  *
  * @param username the name of the user.
  * @param password the password.
  * @return the dto object created after registering the user.
  */
 public final User register(final String username, final String password) {
   User user = new User();
   user.setUsername(username);
   user.setPassword(password);
   user = userService.save(user);
   // set the default role for the user
   addToDefaultRole(user);
   return user;
 }
コード例 #3
0
 /**
  * checks if a user with the given {@code username} already exists.
  *
  * @param username the username
  * @return trivial
  */
 public final boolean userExists(final String username) {
   User user = userService.findByUsername(username);
   return user != null;
 }