Пример #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$
   }
 }
Пример #2
0
 @Override
 public void deleteRemote(CallingContext context, String name) {
   RaptureRemoteStorage.deleteByFields(
       name,
       context.getUser(),
       Messages.getString("Admin.RemoveRemote")); // $NON-NLS-1$ //$NON-NLS-2$
 }
Пример #3
0
 @Override
 public void deleteArchiveConfig(CallingContext context, String raptureURIString) {
   RaptureURI addressURI = new RaptureURI(raptureURIString, Scheme.DOCUMENT);
   checkParameter(NAME, addressURI.getDocPath());
   TypeArchiveConfigStorage.deleteByAddress(
       addressURI, context.getUser(), "Removed archive config");
 }
Пример #4
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$
   }
 }
Пример #5
0
 /** The ip white list is a document that is stored in the settings repo */
 @Override
 public void addIPToWhiteList(CallingContext context, String ipAddress) {
   RaptureIPWhiteList wlist = RaptureIPWhiteListStorage.readByFields();
   wlist.getIpWhiteList().add(ipAddress);
   RaptureIPWhiteListStorage.add(
       wlist, context.getUser(), Messages.getString("Admin.AddedToWhiteList")); // $NON-NLS-1$
 }
Пример #6
0
 @Override
 public void putArchiveConfig(
     CallingContext context, String raptureURIString, TypeArchiveConfig config) {
   RaptureURI internalURI = new RaptureURI(raptureURIString, Scheme.DOCUMENT);
   checkParameter(NAME, internalURI.getDocPath());
   config.setAuthority(internalURI.getAuthority());
   config.setTypeName(internalURI.getDocPath());
   TypeArchiveConfigStorage.add(config, context.getUser(), "Created type archive config");
 }
Пример #7
0
  @Override
  public void addMetadata(CallingContext context, Map<String, String> values, Boolean overwrite) {
    if ((values == null) || values.isEmpty()) return;

    Map<String, String> metadata = context.getMetadata();
    if (metadata == null) metadata = new HashMap<String, String>();
    for (String key : values.keySet()) {
      if (!overwrite && metadata.containsKey(key)) {
        throw RaptureExceptionFactory.create(
            HttpURLConnection.HTTP_BAD_REQUEST, key + " exists and overwrite was disallowed");
      }
      metadata.put(key, values.get(key));
    }
    context.setMetadata(metadata);
    getEphemeralRepo()
        .addToStage(
            RaptureConstants.OFFICIAL_STAGE,
            "session/" + context.getContext(),
            JacksonUtil.jsonFromObject(context),
            false);
  }
Пример #8
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$
 }
Пример #9
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$
   }
 }
Пример #10
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$
   }
 }
Пример #11
0
 @Override
 public void updateRemoteApiKey(CallingContext context, String name, String apiKey) {
   checkParameter(NAME, name);
   checkParameter("ApiKey", apiKey); // $NON-NLS-1$
   RaptureRemote ret = Kernel.INSTANCE.getRemote(name);
   if (ret == null) {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_BAD_REQUEST,
         Messages.getString("Admin.NoFindRemote") + name); // $NON-NLS-1$
   } else {
     ret.setApiKey(apiKey);
     RaptureRemoteStorage.add(
         ret, context.getUser(), Messages.getString("Admin.UpdatedApi")); // $NON-NLS-1$
   }
 }
Пример #12
0
 @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");
 }
Пример #13
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;
 }
Пример #14
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$
   }
 }
Пример #15
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;
  }
Пример #16
0
 @Override
 public RaptureRemote addRemote(
     CallingContext context,
     String name,
     String description,
     String url,
     String apiKey,
     String optPass) {
   checkParameter(NAME, name);
   checkParameter("Url", url); // $NON-NLS-1$
   checkParameter("ApiKey", apiKey); // $NON-NLS-1$
   RaptureRemote ret = new RaptureRemote();
   ret.setName(name);
   ret.setDescription(description);
   ret.setUrl(url);
   ret.setApiKey(apiKey);
   ret.setOptionalPass(optPass);
   RaptureRemoteStorage.add(
       ret, context.getUser(), Messages.getString("Admin.AddRemote")); // $NON-NLS-1$
   return ret;
 }
Пример #17
0
 private void putEnvInfo(CallingContext context, EnvironmentInfo info) {
   EnvironmentInfoStorage.add(info, context.getUser(), "Updated environment info");
 }