Example #1
0
 /** Some type specific calls */
 @Override
 public void deleteUser(CallingContext context, String userName) {
   checkParameter("User", userName); // $NON-NLS-1$
   // Assuming the userName is not "you", mark the user as inactive
   if (userName.equals(context.getUser())) {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoDeleteYourself")); // $NON-NLS-1$
   }
   log.info(Messages.getString("Admin.RemovingUser") + userName); // $NON-NLS-1$
   RaptureUser usr = getUser(context, userName);
   if (!usr.getInactive()) {
     if (usr.getHasRoot()) {
       throw RaptureExceptionFactory.create(
           HttpURLConnection.HTTP_BAD_REQUEST,
           Messages.getString("Admin.NoDeleteRoot")); // $NON-NLS-1$
     }
     usr.setInactive(true);
     RaptureUserStorage.add(
         usr,
         context.getUser(),
         Messages.getString("Admin.Made")
             + userName
             + Messages.getString("Admin.Inactive")); // $NON-NLS-1$ //$NON-NLS-2$
   }
 }
Example #2
0
 @Override
 public void addUser(
     CallingContext context,
     String userName,
     String description,
     String hashPassword,
     String email) {
   checkParameter("User", userName); // $NON-NLS-1$
   // Does the user already exist?
   RaptureUser usr = getUser(context, userName);
   if (usr == null) {
     usr = new RaptureUser();
     usr.setUsername(userName);
     usr.setDescription(description);
     usr.setHashPassword(hashPassword);
     usr.setEmailAddress(email);
     RaptureUserHelper.validateSalt(usr);
     usr.setInactive(false);
     RaptureUserStorage.add(
         usr, context.getUser(), Messages.getString("Admin.AddedUser") + userName); // $NON-NLS-1$
   } else {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.UserAlreadyExists")); // $NON-NLS-1$
   }
 }
Example #3
0
 @Override
 public void updateUserEmail(CallingContext context, String userName, String newEmail) {
   checkParameter("User", userName); // $NON-NLS-1$
   RaptureUser user = getUser(context, userName);
   if (user != null) {
     user.setEmailAddress(newEmail);
     RaptureUserStorage.add(
         user, context.getUser(), Messages.getString("Admin.UpdateEmail") + userName);
   } else {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoExistUser")); // $NON-NLS-1$
   }
 }
Example #4
0
 @Override
 public void cancelPasswordResetToken(CallingContext context, String username) {
   checkParameter("User", username);
   RaptureUser user = getUser(context, username);
   if (user == null) {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoExistUser")); // $NON-NLS-1$
   }
   // expire token now
   user.setTokenExpirationTime(System.currentTimeMillis());
   RaptureUserStorage.add(
       user, context.getUser(), "Cancel password reset token for user " + username); // $NON-NLS-1$
 }
Example #5
0
 @Override
 public void restoreUser(CallingContext context, String userName) {
   checkParameter("User", userName); // $NON-NLS-1$
   log.info(Messages.getString("Admin.RestoringUser") + userName); // $NON-NLS-1$
   RaptureUser usr = getUser(context, userName);
   if (usr.getInactive()) {
     usr.setInactive(false);
     RaptureUserStorage.add(
         usr,
         context.getUser(),
         Messages.getString("Admin.Made")
             + userName
             + Messages.getString("Admin.Active")); // $NON-NLS-1$ //$NON-NLS-2$
   }
 }
Example #6
0
 @Override
 public String createPasswordResetToken(CallingContext context, String username) {
   checkParameter("User", username);
   RaptureUser user = getUser(context, username);
   if (user == null) {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoExistUser")); // $NON-NLS-1$
   }
   String token = generateSecureToken();
   user.setPasswordResetToken(token);
   user.setTokenExpirationTime(DateTime.now().plusDays(1).getMillis());
   RaptureUserStorage.add(
       user,
       context.getUser(),
       "Generate password reset token for user " + username); // $NON-NLS-1$
   return token;
 }
Example #7
0
 @Override
 public void resetUserPassword(CallingContext context, String userName, String newHashPassword) {
   checkParameter("User", userName); // $NON-NLS-1$
   checkParameter("Password", newHashPassword); // $NON-NLS-1$
   // Set a new password for this user
   RaptureUser usr = getUser(context, userName);
   if (usr != null) {
     usr.setInactive(false);
     usr.setHashPassword(newHashPassword);
     RaptureUserStorage.add(
         usr,
         context.getUser(),
         Messages.getString("Admin.PasswordChange") + userName); // $NON-NLS-1$
   } else {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoExistUser")); // $NON-NLS-1$
   }
 }
Example #8
0
  @Override
  public RaptureUser generateApiUser(CallingContext context, String prefix, String description) {
    // Special treatment of prefix "debug"
    checkParameter("Prefix", prefix); // $NON-NLS-1$

    String userId = "zz-" + prefix; // $NON-NLS-1$

    if (!prefix.equals("debug")) { // $NON-NLS-1$
      userId = prefix + "-" + IDGenerator.getUUID(); // $NON-NLS-1$
    }
    RaptureUser usr = new RaptureUser();
    usr.setUsername(userId);
    usr.setDescription(description);
    usr.setHashPassword(""); // $NON-NLS-1$
    usr.setInactive(false);
    usr.setApiKey(true);
    RaptureUserStorage.add(
        usr, context.getUser(), Messages.getString("Admin.CreatedApi")); // $NON-NLS-1$
    return usr;
  }