コード例 #1
0
  public String decrypt(final RootXmlReadHandler root, final String encryptedPassword) {
    if (StringUtils.isEmpty(encryptedPassword)) {
      // empty string vs. null may have significance.
      return encryptedPassword;
    }

    final Object helperObject = root.getHelperObject(ContentRootElementHandler.PRPT_SPEC_VERSION);
    final boolean legacyFix;
    if (helperObject instanceof Integer) {
      final Integer version = (Integer) helperObject;
      if (version == -1) {
        logger.warn("Decrypting password skipped, as we are dealing with an older version. ");
        return encryptedPassword;
      }

      legacyFix = (version.intValue() < ClassicEngineBoot.computeVersionId(5, 0, 0));
    } else {
      legacyFix = false;
    }

    final int separatorPos = encryptedPassword.indexOf(':');
    if (separatorPos == -1) {
      // assume legacy mode
      logger.warn("Decrypting password skipped, as the password-text has no service indicator. ");
      return encryptedPassword;
    }

    final String serviceName = encryptedPassword.substring(0, separatorPos);
    final String payload = encryptedPassword.substring(separatorPos + 1);
    final PasswordEncryptionServiceProvider provider = services.get(serviceName);

    if (legacyFix
        && ObscurificatePasswordEncryptionServiceProvider.SERVICE_TAG.equals(serviceName)) {
      return new Obscurificate48PasswordEncryptionServiceProvider().decrypt(payload);
    }
    if (provider != null) {
      return provider.decrypt(payload);
    }
    logger.debug("Decrypting password skipped, as the service indicator is not recognized. ");
    return encryptedPassword;
  }