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

Matthew Swift
15.46.2016 bbf61700f00b42853eb36ddf6b8da975faae4542
Minor code cleanup

* remove unused methods
* remove extra whitespace
* convert tabs to spaces.
11 files modified
119 ■■■■ changed files
opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/Rest2ldapEndpointConfiguration.xml 5 ●●●●● patch | view | raw | blame | history
opendj-rest2ldap-servlet/src/main/webapp/WEB-INF/classes/opendj-rest2ldap-config.json 2 ●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AuthenticatedConnectionContext.java 22 ●●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java 7 ●●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Rest2LDAP.java 13 ●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java 40 ●●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/DirectConnectionFilter.java 8 ●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/ProxiedAuthV2Filter.java 9 ●●●● patch | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Utils.java 11 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/config/config.ldif patch | view | raw | blame | history
opendj-server-legacy/resource/schema/02-config.ldif 2 ●●● patch | view | raw | blame | history
opendj-maven-plugin/src/main/resources/config/xml/org/forgerock/opendj/server/config/Rest2ldapEndpointConfiguration.xml
@@ -44,18 +44,19 @@
            URL of the REST2LDAP configuration file.
        </adm:synopsis>
        <adm:syntax>
      <adm:string>
          <adm:pattern>
            <adm:regex>.*</adm:regex>
            <adm:usage>URL</adm:usage>
            <adm:synopsis>
              An URL to an existing file that is readable by the server.
            A URL to an existing file that is readable by the server.
            </adm:synopsis>
          </adm:pattern>
      </adm:string>
        </adm:syntax>
        <adm:profile name="ldap">
            <ldap:attribute>
                <ldap:name>ds-cfg-config-url</ldap:name>
            </ldap:attribute>
        </adm:profile>
    </adm:property>
</adm:managed-object>
opendj-rest2ldap-servlet/src/main/webapp/WEB-INF/classes/opendj-rest2ldap-config.json
@@ -98,7 +98,7 @@
        // The authorization policies to use. Supported policies are "anonymous", "basic" and "oauth2".
        "policies": [ "basic" ],
        // Perform all operations using a pre-authorization connection.
        // Perform all operations using a pre-authorized connection.
        "anonymous": {
            // Specify the connection factory to use to perform LDAP operations.
            // If missing, the "root" factory will be used.
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AuthenticatedConnectionContext.java
@@ -15,7 +15,7 @@
 */
package org.forgerock.opendj.rest2ldap;
import static org.forgerock.opendj.rest2ldap.Utils.*;
import static org.forgerock.util.Reject.checkNotNull;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.services.context.AbstractContext;
@@ -49,25 +49,7 @@
     *            re-used for subsequent LDAP operations.
     */
    public AuthenticatedConnectionContext(final Context parent, final Connection connection) {
        super(ensureNotNull(parent), "authenticated connection");
        this.connection = connection;
    }
    /**
     * Creates a new pre-authenticated cached LDAP connection context having the
     * provided ID and parent.
     *
     * @param id
     *            The context ID.
     * @param parent
     *            The parent context.
     * @param connection
     *            The cached pre-authenticated LDAP connection which should be
     *            re-used for subsequent LDAP operations.
     */
    AuthenticatedConnectionContext(final String id, final Context parent,
            final Connection connection) {
        super(id, "authenticated connection", ensureNotNull(parent));
        super(checkNotNull(parent), "authenticated connection");
        this.connection = connection;
    }
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferenceAttributeMapper.java
@@ -19,8 +19,8 @@
import static org.forgerock.opendj.ldap.LdapException.newLdapException;
import static org.forgerock.opendj.ldap.requests.Requests.newSearchRequest;
import static org.forgerock.opendj.rest2ldap.Rest2LDAP.asResourceException;
import static org.forgerock.opendj.rest2ldap.Utils.ensureNotNull;
import static org.forgerock.opendj.rest2ldap.Utils.newBadRequestException;
import static org.forgerock.util.Reject.checkNotNull;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -54,6 +54,7 @@
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.util.AsyncFunction;
import org.forgerock.util.Function;
import org.forgerock.util.Reject;
import org.forgerock.util.promise.ExceptionHandler;
import org.forgerock.util.promise.Promise;
import org.forgerock.util.promise.PromiseImpl;
@@ -96,7 +97,7 @@
     * @return This attribute mapper.
     */
    public ReferenceAttributeMapper searchFilter(final Filter filter) {
        this.filter = ensureNotNull(filter);
        this.filter = checkNotNull(filter);
        return this;
    }
@@ -123,7 +124,7 @@
     * @return This attribute mapper.
     */
    public ReferenceAttributeMapper searchScope(final SearchScope scope) {
        this.scope = ensureNotNull(scope);
        this.scope = checkNotNull(scope);
        return this;
    }
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Rest2LDAP.java
@@ -26,10 +26,10 @@
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.rest2ldap.Utils.ensureNotNull;
import static org.forgerock.opendj.rest2ldap.Utils.newBadRequestException;
import static org.forgerock.opendj.rest2ldap.Utils.newLocalizedIllegalArgumentException;
import static org.forgerock.opendj.rest2ldap.Utils.newJsonValueException;
import static org.forgerock.util.Reject.checkNotNull;
import static org.forgerock.util.time.Duration.*;
import static org.forgerock.opendj.ldap.KeyManagers.useSingleCertificate;
@@ -77,6 +77,7 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.util.Options;
import org.forgerock.util.Reject;
import org.forgerock.util.time.Duration;
/** Provides core factory methods and builders for constructing LDAP resource collections. */
@@ -158,7 +159,7 @@
         * @return A reference to this LDAP resource collection builder.
         */
        public Builder baseDN(final DN dn) {
            ensureNotNull(dn);
            Reject.ifNull(dn);
            this.baseDN = dn;
            return this;
        }
@@ -180,7 +181,7 @@
         * @return The new LDAP resource collection.
         */
        public CollectionResourceProvider build() {
            ensureNotNull(baseDN);
            Reject.ifNull(baseDN);
            if (rootMapper == null) {
                throw new IllegalStateException(ERR_CONFIG_NO_MAPPINGS_PROVIDED.get().toString());
            }
@@ -282,7 +283,7 @@
         * @return A reference to this LDAP resource collection builder.
         */
        public Builder readOnUpdatePolicy(final ReadOnUpdatePolicy policy) {
            this.readOnUpdatePolicy = ensureNotNull(policy);
            this.readOnUpdatePolicy = checkNotNull(policy);
            return this;
        }
@@ -296,7 +297,7 @@
         * @return A reference to this LDAP resource collection builder.
         */
        public Builder schema(final Schema schema) {
            this.schema = ensureNotNull(schema);
            this.schema = checkNotNull(schema);
            return this;
        }
@@ -645,7 +646,7 @@
            if (this.dnAttribute.equals(idAttribute)) {
                throw newLocalizedIllegalArgumentException(ERR_CONFIG_NAMING_STRATEGY_DN_AND_ID_NOT_DIFFERENT.get());
            }
            this.idAttribute = ensureNotNull(idAttribute);
            this.idAttribute = checkNotNull(idAttribute);
            this.isServerProvided = isServerProvided;
        }
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
@@ -15,7 +15,6 @@
 */
package org.forgerock.opendj.rest2ldap;
import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.*;
import static javax.xml.bind.DatatypeConverter.parseDateTime;
import static javax.xml.bind.DatatypeConverter.printDateTime;
import static org.forgerock.opendj.ldap.Filter.alwaysFalse;
@@ -26,6 +25,7 @@
import static org.forgerock.opendj.ldap.schema.CoreSchema.getBooleanSyntax;
import static org.forgerock.opendj.ldap.schema.CoreSchema.getGeneralizedTimeSyntax;
import static org.forgerock.opendj.ldap.schema.CoreSchema.getIntegerSyntax;
import static org.forgerock.opendj.rest2ldap.Rest2ldapMessages.ERR_UNRECOGNIZED_JSON_VALUE;
import java.io.BufferedReader;
import java.io.File;
@@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.forgerock.i18n.LocalizableMessage;
@@ -80,12 +79,6 @@
        }
    }
    static Object attributeToJson(final Attribute a) {
        final Function<ByteString, Object, NeverThrowsException> f = byteStringToJson(a.getAttributeDescription());
        final boolean isSingleValued = a.getAttributeDescription().getAttributeType().isSingleValue();
        return isSingleValued ? a.parse().as(f) : asList(a.parse().asSetOf(f));
    }
    static Function<Object, ByteString, NeverThrowsException> base64ToByteString() {
        return BASE64_TO_BYTESTRING;
    }
@@ -113,24 +106,6 @@
        };
    }
    static <T> T ensureNotNull(final T object) {
        if (object == null) {
            throw new NullPointerException();
        }
        return object;
    }
    static <T> T ensureNotNull(final T object, final String message) {
        if (object == null) {
            throw new NullPointerException(message);
        }
        return object;
    }
    static String getAttributeName(final Attribute a) {
        return a.getAttributeDescription().withoutOption("binary").toString();
    }
    /**
     * Stub formatter for i18n strings.
     *
@@ -144,7 +119,7 @@
        return String.format(format, args);
    }
    static boolean isJSONPrimitive(final Object value) {
    private static boolean isJSONPrimitive(final Object value) {
        return value instanceof String || value instanceof Boolean || value instanceof Number;
    }
@@ -152,10 +127,6 @@
        return v == null || v.isNull() || (v.isList() && v.size() == 0);
    }
    static Attribute jsonToAttribute(final Object value, final AttributeDescription ad) {
        return jsonToAttribute(value, ad, jsonToByteString(ad));
    }
    static Attribute jsonToAttribute(final Object value, final AttributeDescription ad,
            final Function<Object, ByteString, NeverThrowsException> f) {
        if (isJSONPrimitive(value)) {
@@ -242,13 +213,6 @@
        return new BadRequestException(message.toString(), cause);
    }
    private static <T> List<T> asList(final Collection<T> c) {
        if (c instanceof List) {
            return (List<T>) c;
        }
        return new ArrayList<>(c);
    }
    /** Prevent instantiation. */
    private Utils() {
        // No implementation required.
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/DirectConnectionFilter.java
@@ -26,7 +26,6 @@
import org.forgerock.http.protocol.Response;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.rest2ldap.AuthenticatedConnectionContext;
import org.forgerock.services.context.Context;
import org.forgerock.util.AsyncFunction;
@@ -64,12 +63,7 @@
                        connectionHolder.set(connection);
                        return next.handle(new AuthenticatedConnectionContext(context, connection), request);
                    }
                }, new AsyncFunction<LdapException, Response, NeverThrowsException>() {
                    @Override
                    public Promise<Response, NeverThrowsException> apply(LdapException exception) {
                        return asErrorResponse(exception);
                    }
                })
                }, handleConnectionFailure())
                .thenFinally(close(connectionHolder));
    }
}
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/ProxiedAuthV2Filter.java
@@ -16,8 +16,8 @@
package org.forgerock.opendj.rest2ldap.authz;
import static org.forgerock.opendj.ldap.controls.ProxiedAuthV2RequestControl.newControl;
import static org.forgerock.opendj.rest2ldap.authz.Utils.asErrorResponse;
import static org.forgerock.opendj.rest2ldap.authz.Utils.close;
import static org.forgerock.opendj.rest2ldap.authz.Utils.handleConnectionFailure;
import static org.forgerock.services.context.SecurityContext.AUTHZID_DN;
import static org.forgerock.services.context.SecurityContext.AUTHZID_ID;
import static org.forgerock.util.Reject.checkNotNull;
@@ -99,12 +99,7 @@
                    public Promise<Response, NeverThrowsException> apply(Connection connection) {
                        return next.handle(new AuthenticatedConnectionContext(context, connection), request);
                    }
                }, new AsyncFunction<LdapException, Response, NeverThrowsException>() {
                    @Override
                    public Promise<Response, NeverThrowsException> apply(LdapException ldapException) {
                        return asErrorResponse(ldapException);
                    }
                })
                }, handleConnectionFailure())
                .thenFinally(close(connectionHolder));
    }
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/authz/Utils.java
@@ -26,6 +26,8 @@
import org.forgerock.http.protocol.Status;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.json.resource.ResourceException;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.util.AsyncFunction;
import org.forgerock.util.promise.NeverThrowsException;
import org.forgerock.util.promise.Promise;
import org.forgerock.util.promise.Promises;
@@ -55,6 +57,15 @@
        };
    }
    static AsyncFunction<LdapException, Response, NeverThrowsException> handleConnectionFailure() {
        return new AsyncFunction<LdapException, Response, NeverThrowsException>() {
            @Override
            public Promise<Response, NeverThrowsException> apply(final LdapException exception) {
                return asErrorResponse(exception);
            }
        };
    }
    static Promise<Response, NeverThrowsException> asErrorResponse(final Throwable t) {
        final ResourceException e = asResourceException(t);
        final Response response = new Response()
opendj-server-legacy/resource/config/config.ldif
opendj-server-legacy/resource/schema/02-config.ldif
@@ -5997,7 +5997,7 @@
  NAME 'ds-cfg-rest2ldap-endpoint'
  SUP ds-cfg-http-endpoint
  STRUCTURAL
  MUST ( ds-cfg-config-url )
  MUST ( ds-cfg-config-url $ ds-cfg-resource )
  X-ORIGIN 'OpenDJ Directory Server' )
objectClasses: ( 1.3.6.1.4.1.36733.2.1.2.36
  NAME 'ds-cfg-http-authorization-mechanism'