mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
17.55.2013 4355ed2b03fb949638055db26a075e1c3d084906
OPENDJ-960 (CR-1858) Rest2LDAP - Validate http-config.json file 


Enhanced JsonValue by adding a record/verify mode for key accesses.
Client code must call record recordKeyAccesses() to verifyAllKeysAccessed().
When an unaccessed key exists, a JsonException will be thrown and all unaccessed keys will be reported (unaccessed keys located under other unaccessed keys are not reported to reduce noise).


Rest2LDAP.java, Rest2LDAPAuthnFilter.java, Rest2LDAPConnectionFactoryProvider.java:
Called recordKeyAccesses() before accessing the keys, then verifyAllKeysAccessed() to verify all the keys have been accessed after we are done with the JSON config.
3 files modified
38 ■■■■■ changed files
opendj3/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java 5 ●●●● patch | view | raw | blame | history
opendj3/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPConnectionFactoryProvider.java 18 ●●●●● patch | view | raw | blame | history
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Rest2LDAP.java 15 ●●●●● patch | view | raw | blame | history
opendj3/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java
@@ -318,7 +318,7 @@
            }
            // Parse the authentication configuration.
            final JsonValue configuration = new JsonValue(content);
            final JsonValue configuration = new JsonValue(content).recordKeyAccesses();
            final JsonValue authnConfig = configuration.get("authenticationFilter");
            if (!authnConfig.isNull()) {
                supportHTTPBasicAuthentication =
@@ -373,6 +373,9 @@
                bindLDAPConnectionFactory =
                        Rest2LDAP.configureConnectionFactory(configuration.get(
                                "ldapConnectionFactories").required(), ldapFactoryName);
                // we are now done reading the config,
                configuration.verifyAllKeysAccessed();
                // Set the completion handler factory based on the Servlet API version.
                syncFactory = ServletApiVersionAdapter.getInstance(config.getServletContext());
opendj3/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPConnectionFactoryProvider.java
@@ -15,8 +15,8 @@
 */
package org.forgerock.opendj.rest2ldap.servlet;
import static org.forgerock.json.resource.Resources.newInternalConnectionFactory;
import static org.forgerock.opendj.rest2ldap.Rest2LDAP.configureConnectionFactory;
import static org.forgerock.json.resource.Resources.*;
import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*;
import java.io.InputStream;
import java.util.Map;
@@ -38,6 +38,8 @@
import org.forgerock.opendj.rest2ldap.Rest2LDAP;
import org.forgerock.opendj.rest2ldap.Rest2LDAP.Builder;
import com.forgerock.opendj.util.StaticUtils;
/**
 * The connection factory provider which is used by the OpenDJ Commons REST LDAP
 * Gateway.
@@ -81,7 +83,7 @@
                throw new ServletException("Servlet configuration file '" + configFileName
                        + "' does not contain a valid JSON configuration");
            }
            final JsonValue configuration = new JsonValue(content);
            final JsonValue configuration = new JsonValue(content).recordKeyAccesses();
            // Parse the authorization configuration.
            final AuthorizationPolicy authzPolicy =
@@ -113,6 +115,10 @@
                                .configureMapping(mapping).build();
                router.addRoute(mappingUrl, provider);
            }
            // we are now done reading the config,
            configuration.verifyAllKeysAccessed();
            final ConnectionFactory factory = newInternalConnectionFactory(router);
            if (ldapFactory != null) {
                /*
@@ -147,11 +153,7 @@
            throw new ServletException("Servlet configuration file '" + configFileName
                    + "' could not be read: " + e.getMessage());
        } finally {
            try {
                configFile.close();
            } catch (final Exception e) {
                // Ignore.
            }
            StaticUtils.closeSilently(configFile);
        }
    }
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Rest2LDAP.java
@@ -16,9 +16,9 @@
package org.forgerock.opendj.rest2ldap;
import static org.forgerock.opendj.ldap.requests.Requests.newSearchRequest;
import static org.forgerock.opendj.ldap.schema.CoreSchema.getEntryUUIDAttributeType;
import static org.forgerock.opendj.rest2ldap.ReadOnUpdatePolicy.CONTROLS;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.forgerock.opendj.rest2ldap.ReadOnUpdatePolicy.*;
import static org.forgerock.opendj.rest2ldap.Utils.ensureNotNull;
import java.util.ArrayList;
@@ -575,11 +575,16 @@
     * @throws IllegalArgumentException
     *             If the configuration is invalid.
     */
    public static ConnectionFactory configureConnectionFactory(final JsonValue configuration,
    public static ConnectionFactory configureConnectionFactory(JsonValue configuration,
            final String name) {
        configuration = configuration.recordKeyAccesses();
        final JsonValue normalizedConfiguration =
                normalizeConnectionFactory(configuration, name, 0);
        return configureConnectionFactory(normalizedConfiguration);
        final ConnectionFactory connectionFactory =
            configureConnectionFactory(normalizedConfiguration);
        // we are now done reading the config,
        configuration.verifyAllKeysAccessed();
        return connectionFactory;
    }
    public static AttributeMapper constant(final Object value) {