コード例 #1
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 /** 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$
   }
 }
コード例 #2
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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$
   }
 }
コード例 #3
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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$
 }
コード例 #4
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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$
   }
 }
コード例 #5
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @Override
 public void destroyUser(CallingContext context, String userName) {
   checkParameter("User", userName); // $NON-NLS-1$
   log.info("Destroying user: "******"User '" + userName + "' not found.  Cannot destroy";
     log.error(error);
     throw RaptureExceptionFactory.create("User '" + userName + "' not found.  Cannot destroy");
   }
   if (usr.getInactive()) {
     String error = "User '" + userName + "' has not been disabled.  Cannot Destroy";
     log.error(error);
     throw RaptureExceptionFactory.create(error);
   }
   RaptureUserStorage.deleteByFields(userName, context.getUser(), "Destroying user record");
 }
コード例 #6
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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;
 }
コード例 #7
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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$
   }
 }
コード例 #8
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
 @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$
   }
 }
コード例 #9
0
ファイル: AdminApiImpl.java プロジェクト: zancapture/Rapture
  @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;
  }