@Override
  protected void init(final Properties parameters) throws BadRealmException, NoSuchRealmException {
    super.init(parameters);
    _logger.log(Level.FINE, "Initializing {0}", this.getClass().getSimpleName());

    // Among the other custom properties, there is a property jaas-context (which is explained later
    // in this post).
    // This property should be set using the call setProperty method implemented in the parent
    // class.
    /// From: https://blogs.oracle.com/nithya/entry/groups_in_custom_realms
    checkAndSetProperty(JAAS_CONTEXT_PARAM, parameters);

    for (Map.Entry<String, String> entry : OPTIONAL_PROPERTIES.entrySet()) {
      setOptionalProperty(entry.getKey(), parameters, entry.getValue());
    }

    String digestAlgorithm = getProperty(PARAM_DIGEST_ALGORITHM);
    switch (digestAlgorithm) {
      case "none":
        transformer = new NullTransformer();
        break;
      default:
        transformer =
            new MessageDigestTransformer(
                digestAlgorithm,
                getProperty(PARAM_DIGEST_ENCODING),
                Charset.forName(getProperty(PARAM_PASSWORD_CHARSET)));
    }
  }
  private void checkAndSetProperty(final String name, final String value) throws BadRealmException {
    if (value == null) {
      String message = sm.getString("realm.missingprop", name, SERVICE_NAME);
      throw new BadRealmException(message);
    }
    log(FINE, "Setting property {0} to ''{1}''", name, value);

    super.setProperty(name, value);
  }