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 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 #4
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 #5
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;
  }