예제 #1
0
 private void printUsers(Iterable<User> users) {
   if (users != null) {
     int maxCreateDateWidth = 1;
     int maxIdWidth = 1;
     int maxUsernameWidth = 1;
     int maxEmailAddressWidth = 1;
     int maxDisplayNameWidth = 1;
     int maxLoginCountWidth = 1;
     int maxPrivilegesWidth = privilegesAsString(Privilege.ALL).length();
     for (User user : users) {
       maxCreateDateWidth = maxWidth(user.getCreateDate(), maxCreateDateWidth);
       maxIdWidth = maxWidth(user.getUserId(), maxIdWidth);
       maxUsernameWidth = maxWidth(user.getUsername(), maxUsernameWidth);
       maxEmailAddressWidth = maxWidth(user.getEmailAddress(), maxEmailAddressWidth);
       maxDisplayNameWidth = maxWidth(user.getDisplayName(), maxDisplayNameWidth);
       maxLoginCountWidth = maxWidth(Integer.toString(user.getLoginCount()), maxLoginCountWidth);
     }
     String format =
         String.format(
             "%%%ds %%%ds %%%ds %%%ds %%%ds %%%dd %%%ds%%n",
             -1 * maxCreateDateWidth,
             -1 * maxIdWidth,
             -1 * maxUsernameWidth,
             -1 * maxEmailAddressWidth,
             -1 * maxDisplayNameWidth,
             maxLoginCountWidth,
             -1 * maxPrivilegesWidth);
     for (User user : users) {
       System.out.printf(
           format,
           valueOrBlank(user.getCreateDate()),
           user.getUserId(),
           user.getUsername(),
           valueOrBlank(user.getEmailAddress()),
           user.getDisplayName(),
           user.getLoginCount(),
           privilegesAsString(getUserRepository().getPrivileges(user)));
     }
   } else {
     System.out.println("No users");
   }
 }
예제 #2
0
  private int delete(CommandLine cmd) {
    User user = findUser(cmd);
    if (user == null) {
      printUserNotFoundError(cmd);
      return 2;
    }

    getUserRepository().delete(user);
    System.out.println("Deleted user " + user.getUserId());
    return 0;
  }
예제 #3
0
  private int setPrivileges(CommandLine cmd) {
    String privilegesString = cmd.getOptionValue(CMD_OPT_PRIVILEGES);
    Set<Privilege> privileges = null;
    if (privilegesString != null) {
      privileges = Privilege.stringToPrivileges(privilegesString);
    }

    User user = findUser(cmd);
    if (user == null) {
      printUserNotFoundError(cmd);
      return 2;
    }

    if (privileges != null) {
      System.out.println("Assigning privileges " + privileges + " to user " + user.getUserId());
      getUserRepository().setPrivileges(user, privileges);
      user = getUserRepository().findById(user.getUserId());
    }

    printUser(user);
    return 0;
  }
예제 #4
0
파일: Login.java 프로젝트: boiler256/lumify
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String username = UrlUtils.urlDecode(request.getParameter("username"));

    User user = getUserRepository().findByUsername(username);
    if (user == null) {
      // For form based authentication, username and displayName will be the same
      String randomPassword = UserRepository.createRandomPassword();
      user = getUserRepository().addUser(username, username, null, randomPassword, new String[0]);
    }
    getUserRepository().recordLogin(user, AuthenticationHandler.getRemoteAddr(request));

    CurrentUser.set(request, user.getUserId(), user.getUsername());
    JSONObject json = new JSONObject();
    json.put("status", "OK");
    respondWithJson(response, json);
  }
예제 #5
0
 private void printUser(User user) {
   System.out.println("                        ID: " + user.getUserId());
   System.out.println("                  Username: "******"            E-Mail Address: " + valueOrBlank(user.getEmailAddress()));
   System.out.println("              Display Name: " + user.getDisplayName());
   System.out.println("               Create Date: " + valueOrBlank(user.getCreateDate()));
   System.out.println("        Current Login Date: " + valueOrBlank(user.getCurrentLoginDate()));
   System.out.println(
       " Current Login Remote Addr: " + valueOrBlank(user.getCurrentLoginRemoteAddr()));
   System.out.println("       Previous Login Date: " + valueOrBlank(user.getPreviousLoginDate()));
   System.out.println(
       "Previous Login Remote Addr: " + valueOrBlank(user.getPreviousLoginRemoteAddr()));
   System.out.println("               Login Count: " + user.getLoginCount());
   System.out.println(
       "                Privileges: "
           + privilegesAsString(getUserRepository().getPrivileges(user)));
   System.out.println(
       "            Authorizations: "
           + authorizationsAsString(getUserRepository().getAuthorizations(user)));
   System.out.println("");
 }