You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2017/12/28 10:43:09 UTC
[2/3] mina-sshd git commit: Replaced all usages of Pair with
SimpleImmutableEntry (exists since Java 1.6)
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java b/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
deleted file mode 100644
index 5cb56d5..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/Pair.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sshd.common.util;
-
-import java.util.Comparator;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Represents an un-modifiable pair of values
- *
- * @param <F> First value type
- * @param <S> Second value type
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class Pair<F, S> implements Map.Entry<F, S> {
- @SuppressWarnings({"rawtypes", "unchecked"})
- private static final Comparator<Map.Entry<Comparable, ?>> BY_KEY_COMPARATOR = (o1, o2) -> {
- Comparable k1 = o1.getKey();
- Comparable k2 = o2.getKey();
- return k1.compareTo(k2);
- };
-
- private final F first;
- private final S second;
-
- public Pair(F first, S second) {
- this.first = first;
- this.second = second;
- }
-
- @Override
- public final F getKey() {
- return getFirst();
- }
-
- @Override
- public S getValue() {
- return getSecond();
- }
-
- @Override
- public S setValue(S value) {
- throw new UnsupportedOperationException("setValue(" + value + ") N/A");
- }
-
- public final F getFirst() {
- return first;
- }
-
- public final S getSecond() {
- return second;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(getFirst()) * 31 + Objects.hashCode(getSecond());
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
-
- if (obj == this) {
- return true;
- }
-
- if (getClass() != obj.getClass()) {
- return false;
- }
-
- Pair<?, ?> other = (Pair<?, ?>)obj;
- return Objects.equals(getFirst(), other.getFirst()) && Objects.equals(getSecond(), other.getSecond());
- }
-
- @Override
- public String toString() {
- return Objects.toString(getFirst()) + ", " + Objects.toString(getSecond());
- }
-
- /**
- * @param <K> The {@link Comparable} key type
- * @param <V> The associated entry value
- * @return A {@link Comparator} for {@link java.util.Map.Entry}-ies that
- * compares the key values
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static <K extends Comparable<K>, V> Comparator<Map.Entry<K, V>> byKeyEntryComparator() {
- return (Comparator) BY_KEY_COMPARATOR;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/util/io/ModifiableFileWatcher.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/io/ModifiableFileWatcher.java b/sshd-core/src/main/java/org/apache/sshd/common/util/io/ModifiableFileWatcher.java
index ba8c276..032260b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/io/ModifiableFileWatcher.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/io/ModifiableFileWatcher.java
@@ -27,6 +27,7 @@ import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.PosixFilePermission;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
@@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
/**
@@ -209,14 +209,14 @@ public class ModifiableFileWatcher extends AbstractLoggingBean {
* @param path The {@link Path} to be checked - ignored if {@code null}
* or does not exist
* @param options The {@link LinkOption}s to use to query the file's permissions
- * @return The violated permission as {@link Pair} where {@link Pair#getClass()}
- * is a loggable message and {@link Pair#getSecond()} is the offending object
+ * @return The violated permission as {@link SimpleImmutableEntry} where key
+ * is a loggable message and value is the offending object
* - e.g., {@link PosixFilePermission} or {@link String} for owner. Return
* value is {@code null} if no violations detected
* @throws IOException If failed to retrieve the permissions
* @see #STRICTLY_PROHIBITED_FILE_PERMISSION
*/
- public static Pair<String, Object> validateStrictConfigFilePermissions(Path path, LinkOption... options) throws IOException {
+ public static SimpleImmutableEntry<String, Object> validateStrictConfigFilePermissions(Path path, LinkOption... options) throws IOException {
if ((path == null) || (!Files.exists(path, options))) {
return null;
}
@@ -229,7 +229,7 @@ public class ModifiableFileWatcher extends AbstractLoggingBean {
if (OsUtils.isUNIX()) {
PosixFilePermission p = IoUtils.validateExcludedPermissions(perms, STRICTLY_PROHIBITED_FILE_PERMISSION);
if (p != null) {
- return new Pair<>(String.format("Permissions violation (%s)", p), p);
+ return new SimpleImmutableEntry<>(String.format("Permissions violation (%s)", p), p);
}
}
@@ -250,7 +250,7 @@ public class ModifiableFileWatcher extends AbstractLoggingBean {
}
if (!expected.contains(owner)) {
- return new Pair<>(String.format("Owner violation (%s)", owner), owner);
+ return new SimpleImmutableEntry<>(String.format("Owner violation (%s)", owner), owner);
}
return null;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/common/util/security/eddsa/SignatureEd25519.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/security/eddsa/SignatureEd25519.java b/sshd-core/src/main/java/org/apache/sshd/common/util/security/eddsa/SignatureEd25519.java
index cd601f6..0d16812 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/security/eddsa/SignatureEd25519.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/security/eddsa/SignatureEd25519.java
@@ -18,11 +18,12 @@
*/
package org.apache.sshd.common.util.security.eddsa;
+import java.util.Map;
+
import net.i2p.crypto.eddsa.EdDSAEngine;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.signature.AbstractSignature;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
/**
@@ -36,11 +37,11 @@ public class SignatureEd25519 extends AbstractSignature {
@Override
public boolean verify(byte[] sig) throws Exception {
byte[] data = sig;
- Pair<String, byte[]> encoding = extractEncodedSignature(data);
+ Map.Entry<String, byte[]> encoding = extractEncodedSignature(data);
if (encoding != null) {
- String keyType = encoding.getFirst();
+ String keyType = encoding.getKey();
ValidateUtils.checkTrue(KeyPairProvider.SSH_ED25519.equals(keyType), "Mismatched key type: %s", keyType);
- data = encoding.getSecond();
+ data = encoding.getValue();
}
return doVerify(data);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticator.java
index fc7070a..9fac9e6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/DefaultAuthorizedKeysAuthenticator.java
@@ -27,13 +27,13 @@ import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import java.util.Objects;
import org.apache.sshd.common.auth.UsernameHolder;
import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.server.session.ServerSession;
@@ -113,10 +113,10 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica
log.debug("reloadAuthorizedKeys({})[{}] check permissions of {}", username, session, path);
}
- Pair<String, Object> violation = KeyUtils.validateStrictKeyFilePermissions(path);
+ Map.Entry<String, ?> violation = KeyUtils.validateStrictKeyFilePermissions(path);
if (violation != null) {
log.warn("reloadAuthorizedKeys({})[{}] invalid file={} permissions: {}",
- username, session, path, violation.getFirst());
+ username, session, path, violation.getKey());
updateReloadAttributes();
return Collections.emptyList();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
index a54a7d5..2e043fb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/AbstractSftpSubsystemHelper.java
@@ -51,6 +51,7 @@ import java.nio.file.attribute.UserPrincipal;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.attribute.UserPrincipalNotFoundException;
import java.security.Principal;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -91,7 +92,6 @@ import org.apache.sshd.common.util.EventListenerUtils;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.NumberUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.SelectorUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -1180,7 +1180,7 @@ public abstract class AbstractSftpSubsystemHelper
}
Map<String, ?> attrs = Collections.emptyMap();
- Pair<Path, Boolean> result;
+ Map.Entry<Path, Boolean> result;
try {
int version = getVersion();
if (version < SftpConstants.SFTP_V6) {
@@ -1222,9 +1222,9 @@ public abstract class AbstractSftpSubsystemHelper
getPathResolutionLinkOption(SftpConstants.SSH_FXP_REALPATH, "", p);
result = doRealPathV6(id, path, extraPaths, p, options);
- p = result.getFirst();
+ p = result.getKey();
options = getPathResolutionLinkOption(SftpConstants.SSH_FXP_REALPATH, "", p);
- Boolean status = result.getSecond();
+ Boolean status = result.getValue();
switch (control) {
case SftpConstants.SSH_FXP_REALPATH_STAT_IF:
if (status == null) {
@@ -1268,10 +1268,10 @@ public abstract class AbstractSftpSubsystemHelper
return;
}
- sendPath(BufferUtils.clear(buffer), id, result.getFirst(), attrs);
+ sendPath(BufferUtils.clear(buffer), id, result.getKey(), attrs);
}
- protected Pair<Path, Boolean> doRealPathV6(
+ protected SimpleImmutableEntry<Path, Boolean> doRealPathV6(
int id, String path, Collection<String> extraPaths, Path p, LinkOption... options) throws IOException {
int numExtra = GenericUtils.size(extraPaths);
if (numExtra > 0) {
@@ -1294,7 +1294,7 @@ public abstract class AbstractSftpSubsystemHelper
return validateRealPath(id, path, p, options);
}
- protected Pair<Path, Boolean> doRealPathV345(int id, String path, Path p, LinkOption... options) throws IOException {
+ protected SimpleImmutableEntry<Path, Boolean> doRealPathV345(int id, String path, Path p, LinkOption... options) throws IOException {
return validateRealPath(id, path, p, options);
}
@@ -1303,15 +1303,15 @@ public abstract class AbstractSftpSubsystemHelper
* @param path The original path
* @param f The resolve {@link Path}
* @param options The {@link LinkOption}s to use to verify file existence and access
- * @return A {@link Pair} whose left-hand is the <U>absolute <B>normalized</B></U>
- * {@link Path} and right-hand is a {@link Boolean} indicating its status
+ * @return A {@link SimpleImmutableEntry} whose key is the <U>absolute <B>normalized</B></U>
+ * {@link Path} and value is a {@link Boolean} indicating its status
* @throws IOException If failed to validate the file
* @see IoUtils#checkFileExists(Path, LinkOption...)
*/
- protected Pair<Path, Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) throws IOException {
+ protected SimpleImmutableEntry<Path, Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) throws IOException {
Path p = normalize(f);
Boolean status = IoUtils.checkFileExists(p, options);
- return new Pair<>(p, status);
+ return new SimpleImmutableEntry<>(p, status);
}
protected void doRemoveDirectory(Buffer buffer, int id) throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
index eaf3deb..113dc98 100644
--- a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
@@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.agent.local.LocalAgentFactory;
@@ -36,7 +37,6 @@ import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
@@ -82,7 +82,7 @@ public class AgentTest extends BaseTestSupport {
String authSocket = agent.start();
try (SshAgent client = new AgentClient(authSocket)) {
- List<Pair<PublicKey, String>> keys = client.getIdentities();
+ List<? extends Map.Entry<PublicKey, String>> keys = client.getIdentities();
assertNotNull("No initial identities", keys);
assertEquals("Unexpected initial identities size", 0, keys.size());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
index d636096..b491c61 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
@@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.session.ClientSession;
@@ -46,7 +47,6 @@ import org.apache.sshd.common.subsystem.sftp.SftpConstants;
import org.apache.sshd.common.subsystem.sftp.SftpException;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.NumberUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
@@ -184,8 +184,8 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
try (SftpClient sftp = session.createSftpClient()) {
CheckFileNameExtension file = assertExtensionCreated(sftp, CheckFileNameExtension.class);
try {
- Pair<String, ?> result = file.checkFileName(srcFolder, algorithms, 0L, 0L, hashBlockSize);
- fail("Unexpected success to hash folder=" + srcFolder + ": " + result.getFirst());
+ Map.Entry<String, ?> result = file.checkFileName(srcFolder, algorithms, 0L, 0L, hashBlockSize);
+ fail("Unexpected success to hash folder=" + srcFolder + ": " + result.getKey());
} catch (IOException e) { // expected - not allowed to hash a folder
assertTrue("Not an SftpException", e instanceof SftpException);
}
@@ -193,8 +193,8 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
CheckFileHandleExtension hndl = assertExtensionCreated(sftp, CheckFileHandleExtension.class);
try (CloseableHandle dirHandle = sftp.openDir(srcFolder)) {
try {
- Pair<String, ?> result = hndl.checkFileHandle(dirHandle, algorithms, 0L, 0L, hashBlockSize);
- fail("Unexpected handle success on folder=" + srcFolder + ": " + result.getFirst());
+ Map.Entry<String, ?> result = hndl.checkFileHandle(dirHandle, algorithms, 0L, 0L, hashBlockSize);
+ fail("Unexpected handle success on folder=" + srcFolder + ": " + result.getKey());
} catch (IOException e) { // expected - not allowed to hash a folder
assertTrue("Not an SftpException", e instanceof SftpException);
}
@@ -208,13 +208,13 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
}
}
- private void validateHashResult(NamedResource hasher, Pair<String, Collection<byte[]>> result, String expectedAlgorithm, byte[] expectedHash) {
+ private void validateHashResult(NamedResource hasher, Map.Entry<String, ? extends Collection<byte[]>> result, String expectedAlgorithm, byte[] expectedHash) {
String name = hasher.getName();
assertNotNull("No result for hash=" + name, result);
- assertEquals("Mismatched hash algorithms for " + name, expectedAlgorithm, result.getFirst());
+ assertEquals("Mismatched hash algorithms for " + name, expectedAlgorithm, result.getKey());
if (NumberUtils.length(expectedHash) > 0) {
- Collection<byte[]> values = result.getSecond();
+ Collection<byte[]> values = result.getValue();
assertEquals("Mismatched hash values count for " + name, 1, GenericUtils.size(values));
byte[] actualHash = values.iterator().next();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
index ebc8752..74f0471 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java
@@ -22,10 +22,10 @@ package org.apache.sshd.common.config.keys;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PublicKey;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collection;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
import org.junit.BeforeClass;
@@ -88,6 +88,6 @@ public class KeyUtilsFingerprintCaseSensitivityTest extends BaseTestSupport {
@Test
public void testCase() throws Exception {
- assertEquals("Check failed", new Pair<>(true, expected), KeyUtils.checkFingerPrint(test, key));
+ assertEquals("Check failed", new SimpleImmutableEntry<>(true, expected), KeyUtils.checkFingerPrint(test, key));
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
index c43a64f..dc37741 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java
@@ -23,15 +23,16 @@ import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.apache.sshd.common.digest.BuiltinDigests;
import org.apache.sshd.common.digest.DigestFactory;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
import org.junit.FixMethodOrder;
@@ -61,63 +62,63 @@ public class KeyUtilsFingerprintGenerationTest extends BaseTestSupport {
@Parameters(name = "key={0}, digestFactory={1}, expected={2}")
public static Collection<Object[]> parameters() throws IOException, GeneralSecurityException {
- @SuppressWarnings("cast")
- List<Pair<String, List<Pair<DigestFactory, String>>>> keyEntries = Collections.unmodifiableList(Arrays.asList(
- new Pair<>(
- // CHECKSTYLE:OFF
- "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7",
- // CHECKSTYLE:ON
- Arrays.asList(
- new Pair<>(
- BuiltinDigests.md5,
- "MD5:24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e"
- ),
- new Pair<>(
- BuiltinDigests.sha256,
- "SHA256:1wNOZO+/XgNGJMx8UUJst33V+bBMTz5EcL0B6y2iRv0"
+ List<? extends Map.Entry<String, List<? extends Map.Entry<DigestFactory, String>>>> keyEntries =
+ Collections.unmodifiableList(Arrays.asList(
+ new SimpleImmutableEntry<>(
+ // CHECKSTYLE:OFF
+ "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxr3N5fkt966xJINl0hH7Q6lLDRR1D0yMjcXCE5roE9VFut2ctGFuo90TCOxkPOMnwzwConeyScVF4ConZeWsxbG9VtRh61IeZ6R5P5ZTvE9xPdZBgIEWvU1bRfrrOfSMihqF98pODspE6NoTtND2eglwSGwxcYFmpdTAmu+8qgxgGxlEaaCjqwdiNPZhygrH81Mv2ruolNeZkn4Bj+wFFmZTD/waN1pQaMf+SO1+kEYIYFNl5+8JRGuUcr8MhHHJB+gwqMTF2BSBVITJzZUiQR0TMtkK6Vbs7yt1F9hhzDzAFDwhV+rsfNQaOHpl3zP07qH+/99A0XG1CVcEdHqVMw== lgoldstein@LGOLDSTEIN-WIN7",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.md5,
+ "MD5:24:32:3c:80:01:b3:e1:fa:7c:53:ca:e3:e8:4e:c6:8e"
+ ),
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.sha256,
+ "SHA256:1wNOZO+/XgNGJMx8UUJst33V+bBMTz5EcL0B6y2iRv0"
+ )
)
- )
- ),
- new Pair<>(
- // CHECKSTYLE:OFF
- "ssh-dss AAAAB3NzaC1kc3MAAACBAMg/IxsG5BxnF5gM7IKqqR0rftxZC+n5GlbO+J4H+iIb/KR8NBehkxG3CrBZMF96M2K1sEGYLob+3k4r71oWaPul8n5rt9kpd+JSq4iD2ygOyg6Kd1/YDBHoxneizy6I/bGsLwhAAKWcRNrXmYVKGzhrhvZWN12AJDq2mGdj3szLAAAAFQD7a2MltdUSF7FU3//SpW4WGjZbeQAAAIBf0nNsfKQL/TEMo7IpTrEMg5V0RnSigCX0+yUERS42GW/ZeCZBJw7oL2XZbuBtu63vMjDgVpnb92BdrcPgjJ7EFW6DlcyeuywStmg1ygXmDR2AQCxv0eX2CQgrdUczmRa155SDVUTvTQlO1IyKx0vwKAh1H7E3yJUfkTAJstbGYQAAAIEAtv+cdRfNevYFkp55jVqazc8zRLvfb64jzgc5oSJVc64kFs4yx+abYpGX9WxNxDlG6g2WiY8voDBB0YnUJsn0kVRjBKX9OceROxrfT4K4dVbQZsdt+SLaXWL4lGJFrFZL3LZqvySvq6xfhJfakQDDivW4hUOhFPXPHrE5/Ia3T7A= dsa-key-20130709",
- // CHECKSTYLE:ON
- Arrays.asList(
- new Pair<>(
- BuiltinDigests.md5,
- "MD5:fb:29:14:8d:94:f9:1d:cf:6b:0e:a4:35:1d:83:44:2f"
- ),
- new Pair<>(
- BuiltinDigests.sha256,
- "SHA256:grxw4KhY1cK6eOczBWs7tDVvo9V0PQw4E1wN1gJvHlw"
+ ),
+ new SimpleImmutableEntry<>(
+ // CHECKSTYLE:OFF
+ "ssh-dss AAAAB3NzaC1kc3MAAACBAMg/IxsG5BxnF5gM7IKqqR0rftxZC+n5GlbO+J4H+iIb/KR8NBehkxG3CrBZMF96M2K1sEGYLob+3k4r71oWaPul8n5rt9kpd+JSq4iD2ygOyg6Kd1/YDBHoxneizy6I/bGsLwhAAKWcRNrXmYVKGzhrhvZWN12AJDq2mGdj3szLAAAAFQD7a2MltdUSF7FU3//SpW4WGjZbeQAAAIBf0nNsfKQL/TEMo7IpTrEMg5V0RnSigCX0+yUERS42GW/ZeCZBJw7oL2XZbuBtu63vMjDgVpnb92BdrcPgjJ7EFW6DlcyeuywStmg1ygXmDR2AQCxv0eX2CQgrdUczmRa155SDVUTvTQlO1IyKx0vwKAh1H7E3yJUfkTAJstbGYQAAAIEAtv+cdRfNevYFkp55jVqazc8zRLvfb64jzgc5oSJVc64kFs4yx+abYpGX9WxNxDlG6g2WiY8voDBB0YnUJsn0kVRjBKX9OceROxrfT4K4dVbQZsdt+SLaXWL4lGJFrFZL3LZqvySvq6xfhJfakQDDivW4hUOhFPXPHrE5/Ia3T7A= dsa-key-20130709",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.md5,
+ "MD5:fb:29:14:8d:94:f9:1d:cf:6b:0e:a4:35:1d:83:44:2f"
+ ),
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.sha256,
+ "SHA256:grxw4KhY1cK6eOczBWs7tDVvo9V0PQw4E1wN1gJvHlw"
+ )
)
- )
- ),
- new Pair<>(
- // CHECKSTYLE:OFF
- "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBFImZtcTj842stlcVHLFBFxTEx7lu3jW9aZCvd0r9fUNKZ6LbRPh6l1oJ4ozArnw7XreQBUc5oNd9HB5RNJ8jl1nWXY5cXBA7McZrKZrYmk+zxNhH6UL+kMLaJkyngJHQw== root@osv-linux",
- // CHECKSTYLE:ON
- Arrays.asList(
- new Pair<>(
- BuiltinDigests.md5,
- "MD5:e6:dc:a2:4f:5b:11:b2:3c:0f:e8:f6:d8:d1:01:e9:d3"
- ),
- new Pair<>(
- BuiltinDigests.sha512,
- "SHA512:4w6ZB78tmFWhpN2J50Ok6WeMJhZp1X0xN0EKWxZmRLcYDbCWhyJDe8lgrQKWqdTCMZ5aNEBl9xQUklcC5Gt2jg"
+ ),
+ new SimpleImmutableEntry<>(
+ // CHECKSTYLE:OFF
+ "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBFImZtcTj842stlcVHLFBFxTEx7lu3jW9aZCvd0r9fUNKZ6LbRPh6l1oJ4ozArnw7XreQBUc5oNd9HB5RNJ8jl1nWXY5cXBA7McZrKZrYmk+zxNhH6UL+kMLaJkyngJHQw== root@osv-linux",
+ // CHECKSTYLE:ON
+ Arrays.asList(
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.md5,
+ "MD5:e6:dc:a2:4f:5b:11:b2:3c:0f:e8:f6:d8:d1:01:e9:d3"
+ ),
+ new SimpleImmutableEntry<>(
+ BuiltinDigests.sha512,
+ "SHA512:4w6ZB78tmFWhpN2J50Ok6WeMJhZp1X0xN0EKWxZmRLcYDbCWhyJDe8lgrQKWqdTCMZ5aNEBl9xQUklcC5Gt2jg"
+ )
)
)
- )
- ));
+ ));
List<Object[]> ret = new ArrayList<>();
- for (Pair<String, List<Pair<DigestFactory, String>>> kentry : keyEntries) {
- String keyValue = kentry.getFirst();
+ for (Map.Entry<String, ? extends Collection<? extends Map.Entry<DigestFactory, String>>> kentry : keyEntries) {
+ String keyValue = kentry.getKey();
try {
PublicKey key = PublicKeyEntry.parsePublicKeyEntry(keyValue).resolvePublicKey(PublicKeyEntryResolver.FAILING);
- for (Pair<DigestFactory, String> dentry : kentry.getSecond()) {
- DigestFactory factory = dentry.getFirst();
- String fingerprint = dentry.getSecond();
+ for (Map.Entry<DigestFactory, String> dentry : kentry.getValue()) {
+ DigestFactory factory = dentry.getKey();
+ String fingerprint = dentry.getValue();
if (!factory.isSupported()) {
System.out.println("Skip unsupported digest: " + fingerprint);
continue;
@@ -143,12 +144,12 @@ public class KeyUtilsFingerprintGenerationTest extends BaseTestSupport {
);
assertEquals(
String.format("Fingerprint check failed for digest %s", name),
- new Pair<>(true, expected),
+ new SimpleImmutableEntry<>(true, expected),
KeyUtils.checkFingerPrint(expected, digestFactory, key)
);
assertEquals(
String.format("Fingerprint check succeeded for invalid digest %s", name),
- new Pair<>(false, expected),
+ new SimpleImmutableEntry<>(false, expected),
KeyUtils.checkFingerPrint(expected + "A", digestFactory, key)
);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
index 7f2c6aa..ea2be14 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java
@@ -28,6 +28,7 @@ import java.nio.file.attribute.PosixFilePermission;
import java.security.DigestException;
import java.util.Collection;
import java.util.Date;
+import java.util.Map;
import org.apache.sshd.common.digest.BaseDigest;
import org.apache.sshd.common.digest.BuiltinDigests;
@@ -35,7 +36,6 @@ import org.apache.sshd.common.digest.Digest;
import org.apache.sshd.common.digest.DigestFactory;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
@@ -135,7 +135,7 @@ public class KeyUtilsTest extends BaseTestSupport {
if (GenericUtils.isEmpty(perms)) {
assertNull("Unexpected violation for no permissions file: " + file, KeyUtils.validateStrictKeyFilePermissions(file));
} else if (OsUtils.isUNIX()) {
- Pair<String, Object> violation = null;
+ Map.Entry<String, Object> violation = null;
for (PosixFilePermission p : KeyUtils.STRICTLY_PROHIBITED_FILE_PERMISSION) {
if (perms.contains(p)) {
violation = KeyUtils.validateStrictKeyFilePermissions(file);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java b/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
index 996c54e..a2a6436 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/io/nio2/Nio2ServiceTest.java
@@ -23,6 +23,7 @@ import java.io.Flushable;
import java.net.Socket;
import java.net.SocketOption;
import java.nio.channels.AsynchronousSocketChannel;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -36,7 +37,6 @@ import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.session.ServerSessionImpl;
import org.apache.sshd.server.session.SessionFactory;
@@ -76,7 +76,7 @@ public class Nio2ServiceTest extends BaseTestSupport {
}
Semaphore sigSem = new Semaphore(0, true);
- Map<SocketOption<?>, Pair<Object, Object>> actualOptionValues = new HashMap<>(expectedOptions.size());
+ Map<SocketOption<?>, Map.Entry<?, ?>> actualOptionValues = new HashMap<>(expectedOptions.size());
sshd.setSessionFactory(new SessionFactory(sshd) {
@Override
protected ServerSessionImpl doCreateSession(IoSession ioSession) throws Exception {
@@ -99,14 +99,14 @@ public class Nio2ServiceTest extends BaseTestSupport {
for (Map.Entry<String, ?> oe : expectedOptions.entrySet()) {
String propName = oe.getKey();
Object expValue = oe.getValue();
- Pair<SocketOption<?>, ?> optionEntry = Nio2Service.CONFIGURABLE_OPTIONS.get(propName);
+ Map.Entry<SocketOption<?>, ?> optionEntry = Nio2Service.CONFIGURABLE_OPTIONS.get(propName);
SocketOption<?> option = optionEntry.getKey();
if (!supported.contains(option)) {
continue;
}
Object actValue = socket.getOption(option);
- actualOptionValues.put(option, new Pair<>(expValue, actValue));
+ actualOptionValues.put(option, new SimpleImmutableEntry<>(expValue, actValue));
}
}
});
@@ -123,9 +123,9 @@ public class Nio2ServiceTest extends BaseTestSupport {
}
// NOTE: we do not fail the test since some O/S implementations treat the value as a recommendation - i.e., they might ignore it
- for (Map.Entry<SocketOption<?>, Pair<Object, Object>> mme : actualOptionValues.entrySet()) {
+ for (Map.Entry<SocketOption<?>, ? extends Map.Entry<?, ?>> mme : actualOptionValues.entrySet()) {
SocketOption<?> option = mme.getKey();
- Pair<?, ?> vp = mme.getValue();
+ Map.Entry<?, ?> vp = mme.getValue();
Object expValue = vp.getKey();
Object actValue = vp.getValue();
Appendable output = Objects.equals(expValue, actValue) ? System.out : System.err;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
index 861fdd6..7be4a21 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
@@ -20,16 +20,17 @@
package org.apache.sshd.common.mac;
import java.nio.charset.StandardCharsets;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.util.test.BaseTestSupport;
@@ -68,78 +69,78 @@ public class MacVectorsTest extends BaseTestSupport {
///////////////// Test Cases for HMAC-MD5 ///////////////////////
// see https://tools.ietf.org/html/rfc2202
new VectorTestData("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", false, "Hi There",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 1
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 1
"9294727a3638bb1c13f48ef8158bfc9d"))),
new VectorTestData("Jefe", "what do ya want for nothing?",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 2
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 2
"750c783e6ab0b503eaa86e310a5db738"))),
new VectorTestData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false, repeat("dd", 50), false,
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 3
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 3
"56be34521d144c88dbb8c733f0e8b3f6"))),
/* TODO see why it fails
new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 4
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 4
"697eaf0aca3a3aea3a75164746ffaa79"))),
*/
new VectorTestData("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", false, "Test With Truncation",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 5
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 5
"56461ef2342edc00f9bab995690efd4c"),
- new Pair<>(BuiltinMacs.Constants.HMAC_MD5_96,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5_96,
"56461ef2342edc00f9bab995"))),
/* TODO see why it fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 6
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 6
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"))),
*/
/* TODO see why it fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_MD5, // test case 7
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 7
"6f630fad67cda0ee1fb1f562db3aa53e"))),
*/
///////////////// Test Cases for HMAC-SHA-1 ///////////////////////
// see https://tools.ietf.org/html/rfc2202
new VectorTestData("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", false, "Hi There",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 1
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 1
"b617318655057264e28bc0b6fb378c8ef146be00"))),
new VectorTestData("Jefe", "what do ya want for nothing?",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 2
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 2
"effcdf6ae5eb2fa2d27416d5f184df9c259a7c79"))),
new VectorTestData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false, repeat("dd", 50), false,
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 3
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 3
"125d7342b9ac11cd91a39af48aa17b4f63f175d3"))),
/* TODO see why it fails
new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 4
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 4
"4c9007f4026250c6bc8414f9bf50c86c2d7235da"))),
*/
new VectorTestData("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", false, "Test With Truncation",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 5
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 5
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA1_96,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1_96,
"4c1a03424b55e07fe7f27be1"))),
/* TODO see why this fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 6
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 6
"aa4ae5e15272d00e95705637ce8a3b55ed402112"))),
*/
/* TODO see why it fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 7
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 7
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA1_96,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1_96,
"4c1a03424b55e07fe7f27be1"))),
*/
/* TODO see why it fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 8
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 8
"aa4ae5e15272d00e95705637ce8a3b55ed402112"))),
*/
/* TODO see why it fails
new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new Pair<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 9
+ Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 9
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91"))),
*/
@@ -148,47 +149,47 @@ public class MacVectorsTest extends BaseTestSupport {
new VectorTestData(repeat("0b", 20), false, "Hi There",
// test case 1
Arrays.asList(
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854"))),
new VectorTestData("Jefe", "what do ya want for nothing?",
// test case 2
Arrays.asList(
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"))),
new VectorTestData(repeat("aa", 20), false, repeat("dd", 50), false,
// test case 3
Arrays.asList(
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb"))),
new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
// test case 4
Arrays.asList(
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd"))),
/* TODO see why it fails
new VectorTestData(repeat("0c", 20), false, "Test With Truncation",
Arrays.asList( // test case 5
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"a3b6167473100ee06e0c796c2955552b"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"415fad6271580a531d4179bc891d87a6"))),
*/
/* TODO see why it fails
new VectorTestData(repeat("aa", 131), false, "Test Using Larger Than Block-Size Key - Hash Key First",
Arrays.asList( // test case 6
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598"))),
*/
@@ -198,16 +199,16 @@ public class MacVectorsTest extends BaseTestSupport {
+ " The key needs to be hashed before being used"
+ " by the HMAC algorithm",
Arrays.asList( // test case 7
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_256,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
"9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2"),
- new Pair<>(BuiltinMacs.Constants.HMAC_SHA2_512,
+ new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
"e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58")))
*/
// mark end
new VectorTestData("", false, "", false, Collections.emptyList())))) {
- for (Pair<String, String> tc : vector.getResults()) {
- ret.add(new Object[]{vector, tc.getFirst(), tc.getSecond()});
+ for (Map.Entry<String, String> tc : vector.getResults()) {
+ ret.add(new Object[]{vector, tc.getKey(), tc.getValue()});
}
}
@@ -283,24 +284,24 @@ public class MacVectorsTest extends BaseTestSupport {
}
private static class VectorTestData extends VectorSeed {
- private final Collection<Pair<String, String>> results;
+ private final Collection<Map.Entry<String, String>> results;
- VectorTestData(String key, String data, Collection<Pair<String, String>> results) {
+ VectorTestData(String key, String data, Collection<Map.Entry<String, String>> results) {
super(key, data);
this.results = results;
}
- VectorTestData(String key, boolean useKeyString, String data, Collection<Pair<String, String>> results) {
+ VectorTestData(String key, boolean useKeyString, String data, Collection<Map.Entry<String, String>> results) {
super(key, useKeyString, data);
this.results = results;
}
- VectorTestData(String key, boolean useKeyString, String data, boolean useDataString, Collection<Pair<String, String>> results) {
+ VectorTestData(String key, boolean useKeyString, String data, boolean useDataString, Collection<Map.Entry<String, String>> results) {
super(key, useKeyString, data, useDataString);
this.results = results;
}
- public Collection<Pair<String, String>> getResults() {
+ public Collection<Map.Entry<String, String>> getResults() {
return results;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
index 5e966d9..c9850c1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java
@@ -20,8 +20,10 @@
package org.apache.sshd.common.session;
import java.nio.charset.StandardCharsets;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -29,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.session.helpers.ReservedSessionMessagesHandlerAdapter;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.threads.ThreadUtils;
import org.apache.sshd.server.SshServer;
@@ -165,12 +166,12 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
StringBuilder sb = new StringBuilder(Byte.MAX_VALUE)
.append(getClass().getName()).append('#').append(getCurrentTestName()).append("-debug-");
int sbLen = sb.length();
- List<Pair<String, Boolean>> expected = new ArrayList<>();
+ List<Map.Entry<String, Boolean>> expected = new ArrayList<>();
for (int index = 1; index <= Byte.SIZE; index++) {
sb.setLength(sbLen);
sb.append(index);
- Pair<String, Boolean> entry = new Pair<>(sb.toString(), (index & 0x01) == 0);
+ Map.Entry<String, Boolean> entry = new SimpleImmutableEntry<>(sb.toString(), (index & 0x01) == 0);
expected.add(entry);
session.sendDebugMessage(entry.getValue(), entry.getKey(), null);
}
@@ -178,12 +179,12 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
assertTrue("Failed to accumulate debug messages on time",
handler.waitForDebugCount(expected.size(), TimeUnit.SECONDS, expected.size() * 2));
- List<Pair<String, Boolean>> actual = handler.getDebugMessages();
+ List<? extends Map.Entry<String, Boolean>> actual = handler.getDebugMessages();
assertEquals("Mismatched size of debug messages", expected.size(), actual.size());
for (int index = 0; index < actual.size(); index++) {
- Pair<String, Boolean> expEntry = expected.get(index);
- Pair<String, Boolean> actEntry = actual.get(index);
+ Map.Entry<String, Boolean> expEntry = expected.get(index);
+ Map.Entry<String, Boolean> actEntry = actual.get(index);
assertEquals("Mismatched debug entry at index " + index, expEntry, actEntry);
}
}
@@ -192,7 +193,7 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
private final Semaphore ignoredSignal = new Semaphore(0);
private final List<byte[]> ignoredMessages = new ArrayList<>();
private final Semaphore debugSignal = new Semaphore(0);
- private final List<Pair<String, Boolean>> debugMessages = new ArrayList<>();
+ private final List<SimpleImmutableEntry<String, Boolean>> debugMessages = new ArrayList<>();
public AccumulatingHandler() {
super();
@@ -213,7 +214,7 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
ignoredSignal.release();
}
- public List<Pair<String, Boolean>> getDebugMessages() {
+ public List<SimpleImmutableEntry<String, Boolean>> getDebugMessages() {
return debugMessages;
}
@@ -223,7 +224,7 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport {
@Override
public void handleDebugMessage(Session session, boolean display, String msg, String lang, Buffer buffer) throws Exception {
- debugMessages.add(new Pair<>(msg, display));
+ debugMessages.add(new SimpleImmutableEntry<>(msg, display));
super.handleDebugMessage(session, display, msg, lang, buffer);
debugSignal.release();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
index 7b9ce8e..6f0cb6e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
@@ -25,10 +25,10 @@ import java.security.Provider;
import java.security.PublicKey;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
+import java.util.Map;
import org.apache.sshd.common.Factory;
import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.BeforeClass;
@@ -108,9 +108,9 @@ public class SignatureRSATest extends BaseTestSupport {
assertTrue("Verifier signature size not initialized", vSize > 0);
// make sure padding is required
- Pair<String, byte[]> encoding = rsa.extractEncodedSignature(TEST_SIGNATURE);
+ Map.Entry<String, byte[]> encoding = rsa.extractEncodedSignature(TEST_SIGNATURE);
assertNotNull("Signature is not encoded", encoding);
- byte[] data = encoding.getSecond();
+ byte[] data = encoding.getValue();
assertTrue("Signature data size (" + data.length + ") not below verifier size (" + vSize + ")", data.length < vSize);
rsa.update(TEST_MSG);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java
index 4caa791..b4871bb 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java
@@ -27,10 +27,10 @@ import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Collection;
import java.util.Date;
+import java.util.Map;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.OsUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -60,7 +60,7 @@ public class ModifiableFileWatcherTest extends BaseTestSupport {
if (GenericUtils.isEmpty(perms)) {
assertNull("Unexpected violation for no permissions file: " + file, ModifiableFileWatcher.validateStrictConfigFilePermissions(file));
} else if (OsUtils.isUNIX()) {
- Pair<String, Object> violation = null;
+ Map.Entry<String, Object> violation = null;
for (PosixFilePermission p : ModifiableFileWatcher.STRICTLY_PROHIBITED_FILE_PERMISSION) {
if (perms.contains(p)) {
violation = ModifiableFileWatcher.validateStrictConfigFilePermissions(file);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
index f72e72f..4281092 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
@@ -21,6 +21,7 @@ package org.apache.sshd.deprecated;
import java.io.IOException;
import java.security.PublicKey;
import java.util.Iterator;
+import java.util.Map;
import org.apache.sshd.agent.SshAgent;
import org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyFactory;
@@ -28,7 +29,6 @@ import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.session.ClientSessionImpl;
import org.apache.sshd.common.SshConstants;
import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
@@ -39,7 +39,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
public class UserAuthAgent extends AbstractUserAuth {
private final SshAgent agent;
- private final Iterator<Pair<PublicKey, String>> keys;
+ private final Iterator<? extends Map.Entry<PublicKey, String>> keys;
public UserAuthAgent(ClientSessionImpl session, String service) throws IOException {
super(session, service);
@@ -93,7 +93,8 @@ public class UserAuthAgent extends AbstractUserAuth {
public Result next(Buffer buffer) throws IOException {
if (buffer == null) {
if (keys.hasNext()) {
- sendNextKey(keys.next().getFirst());
+ Map.Entry<PublicKey, String> nextKeyValue = keys.next();
+ sendNextKey(nextKeyValue.getKey());
return Result.Continued;
} else {
agent.close();
@@ -113,7 +114,8 @@ public class UserAuthAgent extends AbstractUserAuth {
log.debug("Received SSH_MSG_USERAUTH_FAILURE - partial={}, methods={}", partial, methods);
}
if (keys.hasNext()) {
- sendNextKey(keys.next().getFirst());
+ Map.Entry<PublicKey, String> nextKeyValue = keys.next();
+ sendNextKey(nextKeyValue.getKey());
return Result.Continued;
} else {
agent.close();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-core/src/test/java/org/apache/sshd/util/test/JUnit4SingleInstanceClassRunner.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/JUnit4SingleInstanceClassRunner.java b/sshd-core/src/test/java/org/apache/sshd/util/test/JUnit4SingleInstanceClassRunner.java
index 6b7cb7a..a8f11ce 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/JUnit4SingleInstanceClassRunner.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/JUnit4SingleInstanceClassRunner.java
@@ -18,9 +18,10 @@
*/
package org.apache.sshd.util.test;
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.sshd.common.util.Pair;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.TestClass;
@@ -30,7 +31,7 @@ import org.junit.runners.model.TestClass;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class JUnit4SingleInstanceClassRunner extends BlockJUnit4ClassRunner {
- private final AtomicReference<Pair<Class<?>, Object>> testHolder = new AtomicReference<>();
+ private final AtomicReference<Map.Entry<Class<?>, ?>> testHolder = new AtomicReference<>();
public JUnit4SingleInstanceClassRunner(Class<?> klass) throws InitializationError {
super(klass);
@@ -38,7 +39,7 @@ public class JUnit4SingleInstanceClassRunner extends BlockJUnit4ClassRunner {
@Override
protected Object createTest() throws Exception {
- Pair<Class<?>, Object> lastTest = testHolder.get();
+ Map.Entry<Class<?>, ?> lastTest = testHolder.get();
Class<?> lastTestClass = (lastTest == null) ? null : lastTest.getKey();
TestClass curTest = getTestClass();
Class<?> curTestClass = curTest.getJavaClass();
@@ -47,7 +48,7 @@ public class JUnit4SingleInstanceClassRunner extends BlockJUnit4ClassRunner {
}
Object instance = super.createTest();
- testHolder.set(new Pair<>(curTestClass, instance));
+ testHolder.set(new SimpleImmutableEntry<>(curTestClass, instance));
return instance;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
index 3d6f991..51f0884 100644
--- a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
+++ b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
@@ -20,9 +20,11 @@
package org.apache.sshd.server.auth;
import java.io.File;
+import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.Objects;
import java.util.TreeMap;
@@ -51,7 +53,6 @@ import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.Utils;
@@ -69,8 +70,8 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
super();
}
- public static String getHost(Pair<LdapServer, DirectoryService> context) {
- return getHost((context == null) ? null : context.getFirst());
+ public static String getHost(Map.Entry<LdapServer, DirectoryService> context) {
+ return getHost((context == null) ? null : context.getKey());
}
public static String getHost(LdapServer ldapServer) {
@@ -81,8 +82,8 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
return GenericUtils.isEmpty(transports) ? null : transports[0].getAddress();
}
- public static int getPort(Pair<LdapServer, DirectoryService> context) {
- return getPort((context == null) ? null : context.getFirst());
+ public static int getPort(Map.Entry<LdapServer, DirectoryService> context) {
+ return getPort((context == null) ? null : context.getKey());
}
public static int getPort(LdapServer ldapServer) {
@@ -97,7 +98,7 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
// see https://cwiki.apache.org/confluence/display/DIRxSRVx11/4.1.+Embedding+ApacheDS+into+an+application
// see http://stackoverflow.com/questions/1560230/running-apache-ds-embedded-in-my-application
@SuppressWarnings("checkstyle:avoidnestedblocks")
- public static Pair<LdapServer, DirectoryService> startApacheDs(Class<?> anchor) throws Exception {
+ public static SimpleImmutableEntry<LdapServer, DirectoryService> startApacheDs(Class<?> anchor) throws Exception {
Logger log = LoggerFactory.getLogger(anchor);
File targetFolder = Objects.requireNonNull(Utils.detectTargetFolder(anchor), "Failed to detect target folder");
File workingDirectory = assertHierarchyTargetFolderExists(Utils.deleteRecursive(Utils.resolve(targetFolder, anchor.getSimpleName(), "apacheds-work")));
@@ -172,14 +173,14 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
throw e;
}
- return new Pair<>(ldapServer, directoryService);
+ return new SimpleImmutableEntry<>(ldapServer, directoryService);
}
// see http://users.directory.apache.narkive.com/GkyqAkot/how-to-import-ldif-file-programmatically
- public static Map<String, String> populateUsers(DirectoryService service, Class<?> anchor, String credentialName) throws Exception {
+ public static NavigableMap<String, String> populateUsers(DirectoryService service, Class<?> anchor, String credentialName) throws Exception {
Logger log = LoggerFactory.getLogger(anchor);
CoreSession session = Objects.requireNonNull(service.getAdminSession(), "No core session");
- Map<String, String> usersMap = new TreeMap<>(Comparator.naturalOrder());
+ NavigableMap<String, String> usersMap = new TreeMap<>(Comparator.naturalOrder());
try (LdifReader reader = new LdifReader(Objects.requireNonNull(anchor.getResourceAsStream("/auth-users.ldif"), "No users ldif"))) {
int id = 1;
for (LdifEntry entry : reader) {
@@ -218,9 +219,9 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
return usersMap;
}
- public static void stopApacheDs(Pair<LdapServer, DirectoryService> context) throws Exception {
- stopApacheDs((context == null) ? null : context.getFirst());
- stopApacheDs((context == null) ? null : context.getSecond());
+ public static void stopApacheDs(Map.Entry<LdapServer, DirectoryService> context) throws Exception {
+ stopApacheDs((context == null) ? null : context.getKey());
+ stopApacheDs((context == null) ? null : context.getValue());
}
public static void stopApacheDs(LdapServer ldapServer) throws Exception {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
index 2dd76b4..a07c543 100644
--- a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
+++ b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
@@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.server.auth.BaseAuthenticatorTest;
import org.apache.sshd.server.session.ServerSession;
import org.junit.AfterClass;
@@ -40,7 +39,7 @@ import org.mockito.Mockito;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LdapPasswordAuthenticatorTest extends BaseAuthenticatorTest {
- private static final AtomicReference<Pair<LdapServer, DirectoryService>> LDAP_CONTEX_HOLDER = new AtomicReference<>();
+ private static final AtomicReference<Map.Entry<LdapServer, DirectoryService>> LDAP_CONTEX_HOLDER = new AtomicReference<>();
private static Map<String, String> usersMap;
public LdapPasswordAuthenticatorTest() {
@@ -50,7 +49,7 @@ public class LdapPasswordAuthenticatorTest extends BaseAuthenticatorTest {
@BeforeClass
public static void startApacheDs() throws Exception {
LDAP_CONTEX_HOLDER.set(startApacheDs(LdapPasswordAuthenticatorTest.class));
- usersMap = populateUsers(LDAP_CONTEX_HOLDER.get().getSecond(), LdapPasswordAuthenticatorTest.class, LdapPasswordAuthenticator.DEFAULT_PASSWORD_ATTR_NAME);
+ usersMap = populateUsers(LDAP_CONTEX_HOLDER.get().getValue(), LdapPasswordAuthenticatorTest.class, LdapPasswordAuthenticator.DEFAULT_PASSWORD_ATTR_NAME);
assertFalse("No users retrieved", GenericUtils.isEmpty(usersMap));
}
@@ -61,7 +60,7 @@ public class LdapPasswordAuthenticatorTest extends BaseAuthenticatorTest {
@Test // the user's password is compared with the LDAP stored one
public void testPasswordComparison() throws Exception {
- Pair<LdapServer, DirectoryService> ldapContext = LDAP_CONTEX_HOLDER.get();
+ Map.Entry<LdapServer, DirectoryService> ldapContext = LDAP_CONTEX_HOLDER.get();
LdapPasswordAuthenticator auth = new LdapPasswordAuthenticator();
auth.setHost(getHost(ldapContext));
auth.setPort(getPort(ldapContext));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/74b6918b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
index f2c7b66..b4b66dc 100644
--- a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
+++ b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
@@ -32,7 +32,6 @@ import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
import org.apache.sshd.common.config.keys.KeyUtils;
import org.apache.sshd.common.config.keys.PublicKeyEntryResolver;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.Pair;
import org.apache.sshd.server.auth.BaseAuthenticatorTest;
import org.apache.sshd.server.session.ServerSession;
import org.junit.AfterClass;
@@ -47,7 +46,7 @@ import org.mockito.Mockito;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LdapPublickeyAuthenticatorTest extends BaseAuthenticatorTest {
- private static final AtomicReference<Pair<LdapServer, DirectoryService>> LDAP_CONTEX_HOLDER = new AtomicReference<>();
+ private static final AtomicReference<Map.Entry<LdapServer, DirectoryService>> LDAP_CONTEX_HOLDER = new AtomicReference<>();
private static final Map<String, PublicKey> KEYS_MAP = new TreeMap<>(Comparator.naturalOrder());
// we use this instead of the default since the default requires some extra LDIF manipulation which we don't need
private static final String TEST_ATTR_NAME = "description";
@@ -60,7 +59,7 @@ public class LdapPublickeyAuthenticatorTest extends BaseAuthenticatorTest {
public static void startApacheDs() throws Exception {
LDAP_CONTEX_HOLDER.set(startApacheDs(LdapPublickeyAuthenticatorTest.class));
Map<String, String> credentials =
- populateUsers(LDAP_CONTEX_HOLDER.get().getSecond(), LdapPublickeyAuthenticatorTest.class, TEST_ATTR_NAME);
+ populateUsers(LDAP_CONTEX_HOLDER.get().getValue(), LdapPublickeyAuthenticatorTest.class, TEST_ATTR_NAME);
assertFalse("No keys retrieved", GenericUtils.isEmpty(credentials));
// Cannot use forEach because of the potential GeneraSecurityException being thrown
@@ -79,7 +78,7 @@ public class LdapPublickeyAuthenticatorTest extends BaseAuthenticatorTest {
@Test
public void testPublicKeyComparison() throws Exception {
- Pair<LdapServer, DirectoryService> ldapContext = LDAP_CONTEX_HOLDER.get();
+ Map.Entry<LdapServer, DirectoryService> ldapContext = LDAP_CONTEX_HOLDER.get();
LdapPublickeyAuthenticator auth = new LdapPublickeyAuthenticator();
auth.setHost(getHost(ldapContext));
auth.setPort(getPort(ldapContext));