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

Jean-Noel Rouvignac
29.36.2015 bb06bd9623e697d560bf132ea5aef90f6d5c6a78
AutoRefactor'ed code cleanups
Manually fixed the test assertions
5 files modified
71 ■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java 23 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java 2 ●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java 18 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java 14 ●●●●● patch | view | raw | blame | history
opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java 14 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java
@@ -204,17 +204,16 @@
        } else if (ruleString.startsWith("[") || ruleString.indexOf(':') != -1) {
            ruleType = RuleType.IPv6;
        } else {
            int wildCount = 0;
            int wildcardsCount = 0;
            final String[] s = ruleString.split("\\.", -1);
            /*
             * Try to figure out how many wildcards and if the rule is hostname
             * (can't begin with digit) or ipv4 address. Default to IPv4
             * ruletype.
             * (can't begin with digit) or ipv4 address. Default to IPv4 ruletype.
             */
            ruleType = RuleType.HOST;
            for (final String value : s) {
                if (value.equals("*")) {
                    wildCount++;
                if ("*".equals(value)) {
                    wildcardsCount++;
                    continue;
                }
                // Looks like an ipv4 address
@@ -224,7 +223,7 @@
                }
            }
            // All wildcards (*.*.*.*)
            if (wildCount == s.length) {
            if (wildcardsCount == s.length) {
                ruleType = RuleType.ALLWILDCARD;
            }
        }
@@ -249,12 +248,11 @@
            return false;
        }
        for (int i = 0; i < prefixMask.length; i++) {
            if (!wildCard.get(i)) {
                if ((ruleMask[i] & prefixMask[i]) != (remoteMask[i] & prefixMask[i])) {
            if (!wildCard.get(i)
                    && (ruleMask[i] & prefixMask[i]) != (remoteMask[i] & prefixMask[i])) {
                    return false;
                }
            }
        }
        return true;
    }
@@ -276,12 +274,11 @@
        }
        for (int i = 0; i < s.length; i++) {
            // skip if wildcard
            if (!hostName[i].equals("*")) {
                if (!s[i].equalsIgnoreCase(hostName[i])) {
            if (!"*".equals(hostName[i])
                    && !s[i].equalsIgnoreCase(hostName[i])) {
                    return false;
                }
            }
        }
        return true;
    }
@@ -401,7 +398,7 @@
            }
            for (int i = 0; i < IN4ADDRSZ; i++) {
                final String quad = s[i].trim();
                if (quad.equals("*")) {
                if ("*".equals(quad)) {
                    wildCard.set(i); // see wildcard mark bitset
                } else {
                    final long val = Integer.parseInt(quad);
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
@@ -67,7 +67,7 @@
        private final Set<String> optionalAttributes = new LinkedHashSet<String>();
        private final Set<String> requiredAttributes = new LinkedHashSet<String>();
        private final Set<String> superiorClasses = new LinkedHashSet<String>();
        private ObjectClassType type = null;
        private ObjectClassType type;
        Builder(final ObjectClass oc, final SchemaBuilder builder) {
            super(builder, oc);
opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java
@@ -26,6 +26,9 @@
 */
package org.forgerock.opendj.ldap;
import static org.fest.assertions.Assertions.*;
import static org.testng.Assert.*;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -33,9 +36,6 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.*;
import static org.testng.Assert.*;
/**
 * This class defines a set of tests for the org.forgerock.opendj.ldap.DN class.
 */
@@ -546,13 +546,13 @@
        final int h2 = dn2.hashCode();
        if (result == 0) {
            if (h1 != h2) {
                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
            }
            assertThat(h1)
                    .as("Hash codes for <" + first + "> and <" + second + "> should be the same.")
                    .isEqualTo(h2);
        } else {
            if (h1 == h2) {
                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
            }
            assertThat(h1)
                    .as("Hash codes for <" + first + "> and <" + second + "> should NOT be the same.")
                    .isNotEqualTo(h2);
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java
@@ -27,6 +27,7 @@
package org.forgerock.opendj.ldap;
import static org.fest.assertions.Assertions.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -34,6 +35,7 @@
import java.util.Arrays;
import java.util.Iterator;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.Schema;
@@ -436,13 +438,13 @@
        final int h2 = rdn2.hashCode();
        if (result == 0) {
            if (h1 != h2) {
                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
            }
            assertThat(h1)
                    .as("Hash codes for <" + first + "> and <" + second + "> should be the same.")
                    .isEqualTo(h2);
        } else {
            if (h1 == h2) {
                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
            }
            assertThat(h1)
                    .as("Hash codes for <" + first + "> and <" + second + "> should NOT be the same.")
                    .isNotEqualTo(h2);
        }
    }
}
opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java
@@ -123,7 +123,7 @@
        }
        // First of all parse the HTTP headers for authentication credentials.
        if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) {
        if ((!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse))) {
            // This should never happen.
            throw new ServletException("non-HTTP request or response");
        }
@@ -165,7 +165,7 @@
            } else if (headerAuthorization != null) {
                final StringTokenizer st = new StringTokenizer(headerAuthorization);
                final String method = st.nextToken();
                if (method == null || !method.equalsIgnoreCase(HttpServletRequest.BASIC_AUTH)) {
                if (method == null || !HttpServletRequest.BASIC_AUTH.equalsIgnoreCase(method)) {
                    throw ResourceException.getException(401);
                }
                final String b64Credentials = st.nextToken();
@@ -450,11 +450,11 @@
    private AuthenticationMethod parseAuthenticationMethod(final JsonValue configuration) {
        if (configuration.isDefined("method")) {
            final String method = configuration.get("method").asString();
            if (method.equalsIgnoreCase("simple")) {
            if ("simple".equalsIgnoreCase(method)) {
                return AuthenticationMethod.SIMPLE;
            } else if (method.equalsIgnoreCase("sasl-plain")) {
            } else if ("sasl-plain".equalsIgnoreCase(method)) {
                return AuthenticationMethod.SASL_PLAIN;
            } else if (method.equalsIgnoreCase("search-simple")) {
            } else if ("search-simple".equalsIgnoreCase(method)) {
                return AuthenticationMethod.SEARCH_SIMPLE;
            } else {
                throw new JsonValueException(configuration,
@@ -469,9 +469,9 @@
    private SearchScope parseSearchScope(final JsonValue configuration) {
        if (configuration.isDefined("searchScope")) {
            final String scope = configuration.get("searchScope").asString();
            if (scope.equalsIgnoreCase("sub")) {
            if ("sub".equalsIgnoreCase(scope)) {
                return SearchScope.WHOLE_SUBTREE;
            } else if (scope.equalsIgnoreCase("one")) {
            } else if ("one".equalsIgnoreCase(scope)) {
                return SearchScope.SINGLE_LEVEL;
            } else {
                throw new JsonValueException(configuration,