Child pages
  • DELETE ME PLEASE

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleorg.apache.kafka.common.security.oauthbearer.SubstitutableModuleOptionsCallback
collapsetrue
package org.apache.kafka.common.security.oauthbearer;

/**
 * A {@code Callback} related to introspection requests against a JAAS
 * configuration
 *
 * @see SubstitutableModuleOptionsCallbackHandler
 * @see SubstitutableModuleOptions
 */
public class SubstitutableModuleOptionsCallback implements Callback {
    /**
     * Constructor
     *
     * @param substitutableModuleOptions
     *            the mandatory substitutable module options
     * @param optionName
     *            the mandatory option name, which must exist as a module option
     *            name in the given substitutable module options
     */
    public SubstitutableModuleOptionsCallback(SubstitutableModuleOptions substitutableModuleOptions,
            String optionName) {
        // etc...
    }
 
    /**
     * Return the substitutable module options provided at construction time
     *
     * @return the substitutable module options provided at construction time
     */
    public SubstitutableModuleOptions substitutableModuleOptions() {
        return substitutableModuleOptions;
    }

    /**
     * Return the option name provided at construction time
     *
     * @return the option name provided at construction time
     */
    public String optionName() {
        return optionName;
    }
 
    /**
     * Identify that the option identified by {@link #optionName()}, on the instance
     * returned by {@link #substitutableModuleOptions()}, has had substitution
     * performed for it resulting in the given non-password value. This method can
     * be successfully invoked (and is idempotent) only when the option value isn't
     * being changed.
     *
     * @param substitutionValue
     *            the mandatory non-password substitution value to set
     */
    public void setSubstitutionValue(String substitutionValue) {
        substitutableModuleOptions.setSubstitutionValue(optionName, Objects.requireNonNull(substitutionValue));
    }
 
    /**
     * Identify that the option identified by {@link #optionName()}, on the instance
     * returned by {@link #substitutableModuleOptions()}, has had substitution
     * performed for it resulting in the given password-related value. This method
     * can be successfully invoked (and is idempotent) only when the option value
     * isn't being changed.
     *
     * @param substitutionValue
     *            the mandatory password-related substitution value to set
     */
    public void setSubstitutionValue(Password substitutionValue) {
        substitutableModuleOptions.setSubstitutionValue(optionName, Objects.requireNonNull(substitutionValue));
    }
 
    /**
     * Return the substitution value, if any has been set, otherwise null. Any
     * non-null value will be either a {@code String} or a {@code Password}. Note
     * that the value may not have been set via a call to
     * {@link #setSubstitutionValue(Password)} or
     * {@link #setSubstitutionValue(String)}; it is possible that the value was
     * already set prior to construction of this instance, in which case that value
     * will be returned here.
     *
     * @return the substitution value, if any has been set, otherwise null
     */
    public Object substitutionValue() {
        return substitutableModuleOptions.moduleOptionSubstitutionState().get(optionName);
    }
 
    // etc...
}**
     * Return the substitution text, if any has been set, otherwise null.
     * 
     * @return the substitution value, if any has been set, otherwise null.
     */
    public String substitutionText() {
        Object substitutionValue = substitutionValue();
        if (substitutionValue == null)
            return null;
        return substitutionValue instanceof String ? (String) substitutionValue
                : ((Password) substitutionValue).value();
    }
}
Code Block
languagejava
titleorg.apache.kafka.common.security.oauthbearer.SubstitutableModuleOptionsCallbackHandler
collapsetrue
package org.apache.kafka.common.security.oauthbearer;

/**
 * A {@code CallbackHandler} that handles introspection requests against a JAAS
 * configuration
 *
 * @see SubstitutableModuleOptionsCallback
 * @see SubstitutableModuleOptions
 */
public class SubstitutableModuleOptionsCallbackHandler implements CallbackHandler {
    @Override
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        for (Callback callback : callbacks) {
            if (callback instanceof SubstitutableModuleOptionsCallback) {
                SubstitutableModuleOptionsCallback substitutableModuleOptionsCallback = (SubstitutableModuleOptionsCallback) callback;
                // only perform substitution if it has not yet been done
                if (substitutableModuleOptionsCallback.substitutionValue() != null)
                    continue;
                String optionName = substitutableModuleOptionsCallback.optionName();
                SubstitutableModuleOptions substitutableModuleOptions = substitutableModuleOptionsCallback
                        .substitutableModuleOptions();
                String rawValue = substitutableModuleOptions.moduleOptionsMap().get(optionName);
                if (rawValue != null) {
                    Object substitutionValue = getSubstitutionValue(optionName, rawValue);
                    if (substitutionValue instanceof String)
                        substitutableModuleOptionsCallback.setSubstitutionValue((String) substitutionValue);
                    else
                        substitutableModuleOptionsCallback.setSubstitutionValue((Password) substitutionValue);
                }
            } else
                throw new UnsupportedCallbackException(callback,
                        String.format("Unrecognized Callback type: %s", callback.getClass().getName()));
        }
    }
 
    /*
     * Handle substitution, dealing with circular references, constraints, etc.
     */
    private Object getSubstitutionValue(String optionName, String rawValue) throws IOException {
        // etc...
    }
 
    // etc...
}

...

Code Block
languagejava
titleRetrieving Values
SubstitutableModuleOptions substitutableModuleOptionsoptions = new SubstitutableModuleOptions(moduleOptionsMap);
SubstitutableModuleOptionsCallback callback = new SubstitutableModuleOptionsCallback(substitutableModuleOptionsoptions, "thePassword");
CallbackHandler callbackHandler =     "thePassword");
substitutableModuleOptionsCallbackHandlernew SubstitutableModuleOptionsCallbackHandler()
callbackHandler.handle(new Callback[] {callback});
Object substitutionValue = callback.substitutionValue();
String thePassword = substitutionValue instanceof String ? (String) substitutionValue
        : ((Password) substitutionValue).valuecallback.substitutionText();

The initial set of supported substitution types and their specifiable constraints are as follows:

...