This is an automated email from the ASF dual-hosted git repository. lgoldstein pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
The following commit(s) were added to refs/heads/master by this push: new 15f7224 [SSHD-1035] A few minor improvements in Property code + documentation updates 15f7224 is described below commit 15f7224a2d413d7f3d56941c6165aef1bf607997 Author: Lyor Goldstein <lgoldst...@apache.org> AuthorDate: Tue Aug 18 12:38:00 2020 +0300 [SSHD-1035] A few minor improvements in Property code + documentation updates --- docs/internals.md | 4 +- docs/sftp.md | 2 +- .../main/java/org/apache/sshd/common/Property.java | 47 +++++++++++++++++----- .../org/apache/sshd/core/CoreModuleProperties.java | 4 ++ .../org/apache/sshd/sftp/SftpModuleProperties.java | 3 ++ 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/docs/internals.md b/docs/internals.md index cc6136b..50a7152 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -302,6 +302,6 @@ The idea is that one can register either a `ClientProxyConnector` or `ServerProx the 1st packet being sent/received (respectively) **before** it reaches the SSHD code. This gives the programmer the capability to write a front-end that routes outgoing/incoming packets: -* `SshClient/ClientSesssion#setClientProxyConnector` - sets a proxy that intercepts the 1st packet before being sent to the server +* `SshClient/ClientSesssion#setClientProxyConnector` - sets a proxy that intercepts the 1st packet before being relayed to the server -* `SshServer/ServerSession#setServerProxyAcceptor` - sets a proxy that intercept the 1st incoming packet before being processed by the server +* `SshServer/ServerSession#setServerProxyAcceptor` - sets a proxy that intercepts the 1st incoming packet before being processed by the server diff --git a/docs/sftp.md b/docs/sftp.md index 7d1cf72..7bbfdb6 100644 --- a/docs/sftp.md +++ b/docs/sftp.md @@ -355,7 +355,7 @@ the (default) password-based one: */ KeyPair kp = ... obtain a registered key-pair... session.addPublicKeyIdentity(kp); - return sesssion.auth().verify(context.getMaxAuthTime()); + sesssion.auth().verify(context.getMaxAuthTime()); } }); diff --git a/sshd-common/src/main/java/org/apache/sshd/common/Property.java b/sshd-common/src/main/java/org/apache/sshd/common/Property.java index a1d92c0..6c3d63d 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/Property.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/Property.java @@ -20,7 +20,10 @@ package org.apache.sshd.common; import java.nio.charset.Charset; import java.time.Duration; -import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; @@ -173,7 +176,6 @@ public interface Property<T> { } class DurationProperty extends BaseProperty<Duration> { - public DurationProperty(String name) { this(name, null); } @@ -216,7 +218,6 @@ public interface Property<T> { } class StringProperty extends BaseProperty<String> { - public StringProperty(String name) { this(name, null); } @@ -232,7 +233,6 @@ public interface Property<T> { } class BooleanProperty extends BaseProperty<Boolean> { - public BooleanProperty(String name) { this(name, null); } @@ -248,7 +248,6 @@ public interface Property<T> { } class LongProperty extends BaseProperty<Long> { - public LongProperty(String name) { this(name, null); } @@ -264,7 +263,6 @@ public interface Property<T> { } class IntegerProperty extends BaseProperty<Integer> { - public IntegerProperty(String name) { this(name, null); } @@ -280,7 +278,6 @@ public interface Property<T> { } class CharsetProperty extends BaseProperty<Charset> { - public CharsetProperty(String name) { this(name, null); } @@ -296,7 +293,6 @@ public interface Property<T> { } class ObjectProperty extends BaseProperty<Object> { - public ObjectProperty(String name) { this(name, null); } @@ -312,24 +308,27 @@ public interface Property<T> { } class EnumProperty<T extends Enum<T>> extends BaseProperty<T> { + protected final Collection<T> values; + public EnumProperty(String name, Class<T> type) { this(name, type, null); } public EnumProperty(String name, Class<T> type, T def) { super(name, type, def); + values = Collections.unmodifiableSet(EnumSet.allOf(type)); } @Override protected T fromStorage(Object value) { Class<T> type = getType(); - return PropertyResolverUtils.toEnum(type, value, false, Arrays.asList(type.getEnumConstants())); + return PropertyResolverUtils.toEnum(type, value, false, values); } } class Validating<T> implements Property<T> { - private final Property<T> delegate; - private final Consumer<? super T> validator; + protected final Property<T> delegate; + protected final Consumer<? super T> validator; public Validating(Property<T> delegate, Consumer<? super T> validator) { this.delegate = delegate; @@ -382,18 +381,37 @@ public interface Property<T> { } } + /** + * @return Property name + */ String getName(); + /** + * @return Property type - <B>Note:</B> for primitive types the wrapper equivalent is returned + */ Class<T> getType(); + /** + * @return The {@link Optional} pre-defined default value + */ Optional<T> getDefault(); default T getRequiredDefault() { return getDefault().get(); } + /** + * @param resolver The {@link PropertyResolver} to query for the property value. + * @return The {@link Optional} result - if resolver contains a value then the resolver's value, otherwise + * the pre-defined {@link #getDefault() default} + */ Optional<T> get(PropertyResolver resolver); + /** + * @param resolver The {@link PropertyResolver} to query for the property value. + * @return The resolved value + * @throws NoSuchElementException if resolver contains no value and no {@link #getDefault()} defined + */ default T getRequired(PropertyResolver resolver) { return get(resolver).get(); } @@ -415,8 +433,15 @@ public interface Property<T> { */ T getOrCustomDefault(PropertyResolver resolver, T defaultValue); + /** + * @param resolver The {@link PropertyResolver} to update with the property value. + * @param value The value to set + */ void set(PropertyResolver resolver, T value); + /** + * @param resolver The {@link PropertyResolver} to remove the property from + */ default void remove(PropertyResolver resolver) { PropertyResolverUtils.updateProperty(resolver, getName(), null); } diff --git a/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java b/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java index f51f1a1..0746249 100644 --- a/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java +++ b/sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java @@ -87,6 +87,7 @@ public final class CoreModuleProperties { */ public static final Property<Integer> FORWARDER_BUFFER_SIZE = Property.integer("channel-agent-fwd-buf-size", DEFAULT_FORWARDER_BUF_SIZE); + /** * Ordered comma separated list of authentications methods. Authentications methods accepted by the server will be * tried in the given order. If not configured or {@code null}/empty, then the session's @@ -118,6 +119,7 @@ public final class CoreModuleProperties { */ public static final Property<Boolean> SEND_IMMEDIATE_IDENTIFICATION = Property.bool("send-immediate-identification", true); + /** * Whether to send {@code SSH_MSG_KEXINIT} immediately after sending the client identification string or wait until * the severer's one has been received. @@ -227,6 +229,7 @@ public final class CoreModuleProperties { public static final Property<Integer> PROP_DHGEX_CLIENT_PRF_KEY = Property.integer("dhgex-client-prf"); + /** * Key used to retrieve the value of the channel window size in the configuration properties map. */ @@ -258,6 +261,7 @@ public final class CoreModuleProperties { public static final Property<Integer> NIO_WORKERS = Property.validating(Property.integer("nio-workers", Runtime.getRuntime().availableProcessors() + 1), w -> ValidateUtils.checkTrue(w > 0, "Number of NIO workers must be positive: %d", w)); + /** * Key used to retrieve the value of the timeout after which it will close the connection if the other side has not * been authenticated - in milliseconds. diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/SftpModuleProperties.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/SftpModuleProperties.java index a83c985..a719bdf 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/SftpModuleProperties.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/SftpModuleProperties.java @@ -94,6 +94,7 @@ public final class SftpModuleProperties { */ public static final Property<Charset> NAME_DECODER_CHARSET = Property.charset("sftp-fs-name-decoder-charset", StandardCharsets.UTF_8); + /** * Property used to avoid large buffers when * {@link org.apache.sshd.sftp.client.impl.AbstractSftpClient#write(SftpClient.Handle, long, byte[], int, int)} is @@ -171,6 +172,7 @@ public final class SftpModuleProperties { public static final int MIN_FILE_HANDLE_SIZE = 4; // ~uint32 public static final int DEFAULT_FILE_HANDLE_SIZE = 16; public static final int MAX_FILE_HANDLE_SIZE = 64; // ~sha512 + /** * Size in bytes of the opaque handle value * @@ -186,6 +188,7 @@ public final class SftpModuleProperties { public static final int MIN_FILE_HANDLE_ROUNDS = 1; public static final int DEFAULT_FILE_HANDLE_ROUNDS = MIN_FILE_HANDLE_SIZE; public static final int MAX_FILE_HANDLE_ROUNDS = MAX_FILE_HANDLE_SIZE; + /** * Max. rounds to attempt to create a unique file handle - if all handles already in use after these many rounds, * then an exception is thrown