http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuth.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuth.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuth.java index 73176cf..8ee4e1d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuth.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuth.java @@ -35,11 +35,11 @@ public interface UserAuth { * throw an exception. If the authentication is still ongoing, a null value should * be returned. * - * @param session the current ssh session + * @param session the current ssh session * @param username the user trying to log in - * @param buffer the request buffer containing parameters specific to this request + * @param buffer the request buffer containing parameters specific to this request * @return <code>true</code> if the authentication succeeded, <code>false</code> if the authentication - * failed and {@code null} if not finished yet + * failed and {@code null} if not finished yet * @throws Exception if the authentication fails */ Boolean auth(ServerSession session, String username, String service, Buffer buffer) throws Exception; @@ -47,9 +47,9 @@ public interface UserAuth { /** * Handle another step in the authentication process. * - * @param buffer the request buffer containing parameters specific to this request + * @param buffer the request buffer containing parameters specific to this request * @return <code>true</code> if the authentication succeeded, <code>false</code> if the authentication - * failed and {@code null} if not finished yet + * failed and {@code null} if not finished yet * @throws Exception if the authentication fails */ Boolean next(Buffer buffer) throws Exception;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthFactory.java index 642c107..ef214f9 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthFactory.java @@ -20,18 +20,11 @@ package org.apache.sshd.server.auth; import org.apache.sshd.common.NamedFactory; -import org.apache.sshd.common.util.Transformer; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ +// CHECKSTYLE:OFF public interface UserAuthFactory extends NamedFactory<UserAuth> { - // required because of generics issues - Transformer<UserAuthFactory,NamedFactory<UserAuth>> FAC2NAMED=new Transformer<UserAuthFactory,NamedFactory<UserAuth>>() { - @Override - public NamedFactory<UserAuth> transform(UserAuthFactory input) { - return input; - } - }; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java index d38df50..bd6f469 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthKeyboardInteractive.java @@ -30,20 +30,21 @@ import org.apache.sshd.server.session.ServerSession; /** * Issue a "keyboard-interactive" command according to <A HREF="https://www.ietf.org/rfc/rfc4256.txt">RFC4256</A> + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class UserAuthKeyboardInteractive extends AbstractUserAuth { // configuration parameters on the FactoryManager to configure the message values public static final String KB_INTERACTIVE_NAME_PROP = "kb-interactive-name"; - public static final String DEFAULT_KB_INTERACTIVE_NAME = "Password authentication"; + public static final String DEFAULT_KB_INTERACTIVE_NAME = "Password authentication"; public static final String KB_INTERACTIVE_INSTRUCTION_PROP = "kb-interactive-instruction"; - public static final String DEFAULT_KB_INTERACTIVE_INSTRUCTION = ""; + public static final String DEFAULT_KB_INTERACTIVE_INSTRUCTION = ""; public static final String KB_INTERACTIVE_LANG_PROP = "kb-interactive-language"; - public static final String DEFAULT_KB_INTERACTIVE_LANG = "en-US"; + public static final String DEFAULT_KB_INTERACTIVE_LANG = "en-US"; public static final String KB_INTERACTIVE_PROMPT_PROP = "kb-interactive-prompt"; - public static final String DEFAULT_KB_INTERACTIVE_PROMPT = "Password: "; + public static final String DEFAULT_KB_INTERACTIVE_PROMPT = "Password: "; public static final String KB_INTERACTIVE_ECHO_PROMPT_PROP = "kb-interactive-echo-prompt"; - public static final boolean DEFAULT_KB_INTERACTIVE_ECHO_PROMPT = false; + public static final boolean DEFAULT_KB_INTERACTIVE_ECHO_PROMPT = false; public UserAuthKeyboardInteractive() { super(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNoneFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNoneFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNoneFactory.java index e869a17..8272a2e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNoneFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthNoneFactory.java @@ -32,6 +32,7 @@ public class UserAuthNoneFactory implements UserAuthFactory { public String getName() { return "none"; } + @Override public UserAuth create() { return new UserAuthNone(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java index 8f658da..a7923a2 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPassword.java @@ -18,7 +18,6 @@ */ package org.apache.sshd.server.auth; -import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.server.ServerFactoryManager; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPasswordFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPasswordFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPasswordFactory.java index 2eedbc4..11a1018 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPasswordFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPasswordFactory.java @@ -23,7 +23,7 @@ package org.apache.sshd.server.auth; */ public class UserAuthPasswordFactory implements UserAuthFactory { public static final UserAuthPasswordFactory INSTANCE = new UserAuthPasswordFactory(); - + public UserAuthPasswordFactory() { super(); } @@ -32,6 +32,7 @@ public class UserAuthPasswordFactory implements UserAuthFactory { public String getName() { return "password"; } + @Override public UserAuth create() { return new UserAuthPassword(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java index 87cd80c..bdd1efb 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java @@ -23,7 +23,6 @@ import java.security.PublicKey; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.signature.Signature; -import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.buffer.ByteArrayBuffer; @@ -62,7 +61,7 @@ public class UserAuthPublicKey extends AbstractUserAuth { byte[] sig = hasSig ? buffer.getBytes() : null; - PublickeyAuthenticator authenticator = + PublickeyAuthenticator authenticator = ValidateUtils.checkNotNull(manager.getPublickeyAuthenticator(), "No PublickeyAuthenticator configured"); if (!authenticator.authenticate(username, key, session)) { return Boolean.FALSE; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKeyFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKeyFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKeyFactory.java index 70a14c0..ed90358 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKeyFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKeyFactory.java @@ -34,6 +34,7 @@ public class UserAuthPublicKeyFactory implements UserAuthFactory { public String getName() { return NAME; } + @Override public UserAuth create() { return new UserAuthPublicKey(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java index 46933f2..369c23b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java @@ -22,7 +22,6 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.HashMap; import java.util.Map; - import javax.security.auth.Subject; import javax.security.auth.login.AppConfigurationEntry; import javax.security.auth.login.Configuration; @@ -38,7 +37,11 @@ import org.ietf.jgss.GSSManager; * with non-Sun JREs. */ -public class CredentialHelper { +public final class CredentialHelper { + + private CredentialHelper() { + throw new UnsupportedOperationException("No instance"); + } @SuppressWarnings("synthetic-access") public static GSSCredential creds(GSSManager mgr, String spn, String keytab) throws LoginException, GSSException { @@ -58,7 +61,7 @@ public class CredentialHelper { * @author Richard Evans */ - private static class FixedLoginConfiguration extends Configuration { + private static final class FixedLoginConfiguration extends Configuration { private AppConfigurationEntry entry; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java index 015483e..f1a39a3 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/GSSAuthenticator.java @@ -20,7 +20,6 @@ package org.apache.sshd.server.auth.gss; import java.net.InetAddress; import java.net.UnknownHostException; - import javax.security.auth.login.LoginException; import org.apache.sshd.server.session.ServerSession; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java index d0e5bab..95e8c15 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java @@ -20,7 +20,6 @@ package org.apache.sshd.server.auth.gss; import org.apache.sshd.common.SshConstants; import org.apache.sshd.common.SshException; -import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.buffer.ByteArrayBuffer; @@ -37,7 +36,7 @@ import org.ietf.jgss.Oid; /** * <p>Prototype user authentication handling gssapi-with-mic. Implements <code>HandshakingUserAuth</code> because * the process involves several steps.</p> - * + * <p/> * <p>Several methods are available for overriding in specific circumstances.</p> */ public class UserAuthGSS extends AbstractUserAuth { @@ -101,12 +100,10 @@ public class UserAuthGSS extends AbstractUserAuth { // No matching mechanism found return Boolean.FALSE; - } - else - { + } else { int msg = buffer.getUByte(); if (!((msg == SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE) - || (msg == SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC) && context.isEstablished())) { + || (msg == SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC) && context.isEstablished())) { throw new SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Packet not supported by user authentication method: " + msg); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSSFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSSFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSSFactory.java index bf7e252..43e705e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSSFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSSFactory.java @@ -26,7 +26,7 @@ import org.apache.sshd.server.auth.UserAuthFactory; */ public class UserAuthGSSFactory implements UserAuthFactory { public static final UserAuthGSSFactory INSTANCE = new UserAuthGSSFactory(); - + public UserAuthGSSFactory() { super(); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java index 20bdef6..54e5f89 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/PasswordAuthenticator.java @@ -22,14 +22,16 @@ import org.apache.sshd.server.session.ServerSession; /** * Used to authenticate users based on a password. + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public interface PasswordAuthenticator { /** * Check the validity of a password. + * * @param username The username credential * @param password The provided password - * @param session The {@link ServerSession} attempting the authentication + * @param session The {@link ServerSession} attempting the authentication * @return {@code true} indicating if authentication succeeded */ boolean authenticate(String username, String password, ServerSession session); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/password/StaticPasswordAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/StaticPasswordAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/StaticPasswordAuthenticator.java index 1633187..30ad31e 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/password/StaticPasswordAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/password/StaticPasswordAuthenticator.java @@ -25,7 +25,7 @@ import org.apache.sshd.server.session.ServerSession; * Returns the same constant result {@code true/false} regardless */ public class StaticPasswordAuthenticator extends AbstractLoggingBean implements PasswordAuthenticator { - private final boolean acceptance; + private final boolean acceptance; public StaticPasswordAuthenticator(boolean acceptance) { this.acceptance = acceptance; @@ -41,7 +41,7 @@ public class StaticPasswordAuthenticator extends AbstractLoggingBean implements if (log.isDebugEnabled()) { log.debug("authenticate({}[{}]: {}", username, session, accepted); } - + return accepted; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/KeySetPublickeyAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/KeySetPublickeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/KeySetPublickeyAuthenticator.java index d818978..50b160c 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/KeySetPublickeyAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/KeySetPublickeyAuthenticator.java @@ -45,18 +45,18 @@ public class KeySetPublickeyAuthenticator extends AbstractLoggingBean implements public boolean authenticate(String username, PublicKey key, ServerSession session) { return authenticate(username, key, session, getKeySet()); } - + public boolean authenticate(String username, PublicKey key, ServerSession session, Collection<? extends PublicKey> keys) { if (GenericUtils.isEmpty(keys)) { if (log.isDebugEnabled()) { log.debug("authenticate(" + username + ")[" + session + "] no keys"); } - + return false; } - + PublicKey matchKey = KeyUtils.findMatchingKey(key, keys); - boolean matchFound = (matchKey != null); + boolean matchFound = matchKey != null; if (log.isDebugEnabled()) { log.debug("authenticate(" + username + ")[" + session + "] match found=" + matchFound); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java index 739f1a8..4c15161 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/PublickeyAuthenticator.java @@ -32,9 +32,10 @@ public interface PublickeyAuthenticator { /** * Check the validity of a public key. + * * @param username the username - * @param key the key - * @param session the server session + * @param key the key + * @param session the server session * @return a boolean indicating if authentication succeeded or not */ boolean authenticate(String username, PublicKey key, ServerSession session); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/StaticPublickeyAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/StaticPublickeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/StaticPublickeyAuthenticator.java index 970aadb..d760f1d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/StaticPublickeyAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/StaticPublickeyAuthenticator.java @@ -28,7 +28,7 @@ import org.apache.sshd.server.session.ServerSession; * Returns the same constant result {@code true/false} regardless */ public abstract class StaticPublickeyAuthenticator extends AbstractLoggingBean implements PublickeyAuthenticator { - private final boolean acceptance; + private final boolean acceptance; protected StaticPublickeyAuthenticator(boolean acceptance) { this.acceptance = acceptance; @@ -43,7 +43,7 @@ public abstract class StaticPublickeyAuthenticator extends AbstractLoggingBean i boolean accepted = isAccepted(); if (log.isDebugEnabled()) { log.debug("authenticate({}[{}][{}][{}]: {}", - username, session, key.getAlgorithm(), KeyUtils.getFingerPrint(key), accepted); + username, session, key.getAlgorithm(), KeyUtils.getFingerPrint(key), accepted); } return accepted; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java index 218e76a..f87c4ea 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/AbstractServerChannel.java @@ -73,7 +73,7 @@ public abstract class AbstractServerChannel extends AbstractChannel { if (log.isDebugEnabled()) { log.debug("Send SSH_MSG_CHANNEL_REQUEST exit-status on channel {}", Integer.valueOf(id)); } - + Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST); buffer.putInt(recipient); buffer.putString("exit-status"); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java index 67e709f..79f4e15 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelDataReceiver.java @@ -20,38 +20,34 @@ package org.apache.sshd.server.channel; import java.io.Closeable; import java.io.IOException; -import java.io.InputStream; - -import org.apache.sshd.server.ChannelSessionAware; -import org.apache.sshd.server.Command; /** * Receiving end of the data stream from the client. - * - * <p> + * <p/> + * <p/> * Sequence of bytes that SSH client sends to the server is eventually sent to this interface * to be passed on to the final consumer. * By default {@link ChannelSession} spools this in a buffer so that you can read it from - * the input stream you get from {@link Command#setInputStream(InputStream)}, but if command + * the input stream you get from {@link org.apache.sshd.server.Command#setInputStream(java.io.InputStream)}, but if command * wants to do a callback-driven I/O for the data it receives from the client, it can * call {@link ChannelSession#setDataReceiver(ChannelDataReceiver)} to do so. - * (And to grab a reference to {@link ChannelSession}, a {@link Command} should implement - * {@link ChannelSessionAware}.) + * (And to grab a reference to {@link ChannelSession}, a {@link org.apache.sshd.server.Command} should implement + * {@link org.apache.sshd.server.ChannelSessionAware}.) * * @see ChannelSession#setDataReceiver(ChannelDataReceiver) - * @see ChannelSessionAware + * @see org.apache.sshd.server.ChannelSessionAware */ public interface ChannelDataReceiver extends Closeable { /** * Called when the server receives additional bytes from the client. - * - * <p> + * <p/> + * <p/> * SSH channels use the windowing mechanism to perform flow control, much like TCP does. * The server gives the client the initial window size, which represents the number of * bytes the client can send to the server. As the server receives data, it can * send a message to the client to allow it to send more data. - * - * <p> + * <p/> + * <p/> * The return value from this method is used to control this behaviour. * Intuitively speaking, the callee returns the number of bytes consumed by this method, * by the time this method returns. Picture a one-way long bridge (for example Golden Gate Bridge) @@ -60,50 +56,45 @@ public interface ChannelDataReceiver extends Closeable { * count the number of cars as it leaves the bridge, and if enough of them left, * we'll signal the sending end that they can let in more cars. The return value of this * method counts the number of cars that are leaving in this batch. - * - * <p> + * <p/> + * <p/> * In simple cases, where the callee has consumed the bytes before it returns, * the return value must be the same value as the 'len' parameter given. - * - * <p> + * <p/> + * <p/> * On the other hand, if the callee is queueing up the received bytes somewhere * to be consumed later (for example by another thread), then this method should * return 0, for the bytes aren't really consumed yet. And when at some later point * the bytes are actually used, then you'll invoke {@code channel.getLocalWindow().consumeAndCheck(len)} * to let the channel know that bytes are consumed. - * - * <p> + * <p/> + * <p/> * This behaviour will result in a better flow control, as the server will not * allow the SSH client to overflow its buffer. If instead you always return the value * passed in the 'len' parameter, the place where you are queueing up bytes may overflow. - * - * <p> + * <p/> + * <p/> * In either case, the callee must account for every bytes it receives in this method. * Returning 0 and failing to call back {@code channel.getLocalWindow().consumeAndCheck(len)} later * will dry up the window size, and eventually the client will stop sending you any data. - * - * <p> + * <p/> + * <p/> * In the SSH protocol, this method invocation is triggered by a <tt>SSH_MSG_CHANNEL_DATA</tt> message. * - * @param channel - * The caller to which this {@link ChannelDataReceiver} is assigned. Never null. - * @param buf - * Holds the bytes received. This buffer belongs to the caller, and it might get reused - * by the caller as soon as this method returns. - * @param start - * buf[start] is the first byte that received from the client. - * @param len - * the length of the bytes received. Can be zero. - * @return - * The number of bytes consumed, for the purpose of the flow control. - * For a simple use case, you return the value given by the 'len' parameter. - * See the method javadoc for more details. + * @param channel The caller to which this {@link ChannelDataReceiver} is assigned. Never null. + * @param buf Holds the bytes received. This buffer belongs to the caller, and it might get reused + * by the caller as soon as this method returns. + * @param start buf[start] is the first byte that received from the client. + * @param len the length of the bytes received. Can be zero. + * @return The number of bytes consumed, for the purpose of the flow control. + * For a simple use case, you return the value given by the 'len' parameter. + * See the method javadoc for more details. */ int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException; /** * Called to indicate EOF. - * + * <p/> * The client will no longer send us any more data. */ @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java index 60b61c0..ec28980 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java @@ -19,7 +19,6 @@ package org.apache.sshd.server.channel; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.Collection; @@ -96,7 +95,7 @@ public class ChannelSession extends AbstractServerChannel { if (signals == null) { throw new IllegalArgumentException("signals may not be null"); } - + addSignalListener(listener, Arrays.asList(signals)); } @@ -160,7 +159,8 @@ public class ChannelSession extends AbstractServerChannel { /** * adds a variable to the environment. This method is called <code>set</code> * according to the name of the appropriate posix command <code>set</code> - * @param key environment variable name + * + * @param key environment variable name * @param value environment variable value */ public void set(String key, String value) { @@ -221,10 +221,12 @@ public class ChannelSession extends AbstractServerChannel { public boolean isClosed() { return commandExitFuture.isClosed(); } + @Override public boolean isClosing() { return isClosed(); } + @Override public CloseFuture close(boolean immediately) { if (immediately || command == null) { @@ -298,12 +300,12 @@ public class ChannelSession extends AbstractServerChannel { } /** - * @param type The request type + * @param type The request type * @param buffer The {@link Buffer} containing extra request-specific content * @return A {@link Boolean} representing the success/failure of handling * the request - {@code null} if unknown request received * @throws IOException If request requires some extra response and failed - * to generate it + * to generate it */ public Boolean handleRequest(String type, Buffer buffer) throws IOException { switch (type) { @@ -342,8 +344,9 @@ public class ChannelSession extends AbstractServerChannel { return handleAgentForwarding(buffer); case "x11-req": return handleX11Forwarding(buffer); + default: + return null; } - return null; } protected boolean handleEnv(Buffer buffer) throws IOException { @@ -376,10 +379,10 @@ public class ChannelSession extends AbstractServerChannel { log.warn("Unknown pty opcode value: " + opcode); break; } - int val = ((modes[i++] << 24) & 0xff000000) | - ((modes[i++] << 16) & 0x00ff0000) | - ((modes[i++] << 8) & 0x0000ff00) | - ((modes[i++]) & 0x000000ff); + int val = ((modes[i++] << 24) & 0xff000000) + | ((modes[i++] << 16) & 0x00ff0000) + | ((modes[i++] << 8) & 0x0000ff00) + | ((modes[i++]) & 0x000000ff); ptyModes.put(mode, val); } if (log.isDebugEnabled()) { @@ -443,15 +446,16 @@ public class ChannelSession extends AbstractServerChannel { log.debug("handleShell - closing"); return false; } - + ServerFactoryManager manager = ((ServerSession) session).getFactoryManager(); Factory<Command> factory = manager.getShellFactory(); if (factory == null) { log.debug("handleShell - no shell factory"); return false; } - - if ((command = factory.create()) == null) { + + command = factory.create(); + if (command == null) { log.debug("handleShell - no shell command"); return false; } @@ -501,7 +505,8 @@ public class ChannelSession extends AbstractServerChannel { return false; } - if ((command = NamedFactory.Utils.create(factories, subsystem)) == null) { + command = NamedFactory.Utils.create(factories, subsystem); + if (command == null) { log.warn("Unsupported subsystem: {}", subsystem); return false; } @@ -514,10 +519,10 @@ public class ChannelSession extends AbstractServerChannel { /** * For {@link Command} to install {@link ChannelDataReceiver}. - * When you do this, {@link Command#setInputStream(InputStream)} or + * When you do this, {@link Command#setInputStream(java.io.InputStream)} or * {@link org.apache.sshd.server.AsyncCommand#setIoInputStream(org.apache.sshd.common.io.IoInputStream)} * will no longer be invoked. If you call this method from {@link Command#start(Environment)}, - * the input stream you received in {@link Command#setInputStream(InputStream)} will + * the input stream you received in {@link Command#setInputStream(java.io.InputStream)} will * not read any data. */ public void setDataReceiver(ChannelDataReceiver receiver) { @@ -556,7 +561,7 @@ public class ChannelSession extends AbstractServerChannel { command.setOutputStream(out); command.setErrorStream(err); } - if (this.receiver==null) { + if (this.receiver == null) { // if the command hasn't installed any ChannelDataReceiver, install the default // and give the command an InputStream if (command instanceof AsyncCommand) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java index c1edd49..b2a38d1 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSessionFactory.java @@ -25,7 +25,7 @@ import org.apache.sshd.common.channel.ChannelFactory; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class ChannelSessionFactory implements ChannelFactory { - public static final ChannelSessionFactory INSTANCE = new ChannelSessionFactory(); + public static final ChannelSessionFactory INSTANCE = new ChannelSessionFactory(); public ChannelSessionFactory() { super(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/OpenChannelException.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/OpenChannelException.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/OpenChannelException.java index 84d6677..8b80d4f 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/OpenChannelException.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/OpenChannelException.java @@ -18,8 +18,6 @@ */ package org.apache.sshd.server.channel; -import org.apache.sshd.common.SshConstants; - /** * Documents failure of a channel to open as expected. * @@ -41,10 +39,10 @@ public class OpenChannelException extends Exception { /** * The reason code as specified by RFC 4254. * <ul> - * <li>{@link SshConstants#SSH_OPEN_ADMINISTRATIVELY_PROHIBITED} - * <li>{@link SshConstants#SSH_OPEN_CONNECT_FAILED} - * <li>{@link SshConstants#SSH_OPEN_UNKNOWN_CHANNEL_TYPE} - * <li>{@link SshConstants#SSH_OPEN_RESOURCE_SHORTAGE} + * <li>{@link org.apache.sshd.common.SshConstants#SSH_OPEN_ADMINISTRATIVELY_PROHIBITED} + * <li>{@link org.apache.sshd.common.SshConstants#SSH_OPEN_CONNECT_FAILED} + * <li>{@link org.apache.sshd.common.SshConstants#SSH_OPEN_UNKNOWN_CHANNEL_TYPE} + * <li>{@link org.apache.sshd.common.SshConstants#SSH_OPEN_RESOURCE_SHORTAGE} * </ul> * * @return reason code; 0 if no standardized reason code is given. http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java index 20b8255..ea9e81b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/PuttyRequestHandler.java @@ -39,7 +39,7 @@ public class PuttyRequestHandler extends AbstractLoggingBean implements ChannelR public Result process(Channel channel, String request, boolean wantReply, Buffer buffer) throws Exception { // make sure proper suffix if ((GenericUtils.length(request) <= REQUEST_SUFFIX.length()) - || (!request.endsWith(REQUEST_SUFFIX))) { + || (!request.endsWith(REQUEST_SUFFIX))) { return Result.Unsupported; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java index e3660a1..6444713 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommand.java @@ -84,32 +84,39 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable public ScpCommand(String command, ExecutorService executorService, boolean shutdownOnExit, int sendSize, int receiveSize, ScpTransferEventListener eventListener) { name = command; - if ((executors = executorService) == null) { + if (executorService == null) { String poolName = command.replace(' ', '_').replace('/', ':'); executors = ThreadUtils.newSingleThreadExecutor(poolName); shutdownExecutor = true; // we always close the ad-hoc executor service } else { + executors = executorService; shutdownExecutor = shutdownOnExit; } - if ((sendBufferSize = sendSize) < ScpHelper.MIN_SEND_BUFFER_SIZE) { - throw new IllegalArgumentException("<ScpCommmand>(" + command + ") send buffer size (" + sendSize + ") below minimum required (" + ScpHelper.MIN_SEND_BUFFER_SIZE + ")"); + if (sendSize < ScpHelper.MIN_SEND_BUFFER_SIZE) { + throw new IllegalArgumentException("<ScpCommmand>(" + command + ") send buffer size " + + "(" + sendSize + ") below minimum required " + + "(" + ScpHelper.MIN_SEND_BUFFER_SIZE + ")"); } + sendBufferSize = sendSize; - if ((receiveBufferSize = receiveSize) < ScpHelper.MIN_RECEIVE_BUFFER_SIZE) { - throw new IllegalArgumentException("<ScpCommmand>(" + command + ") receive buffer size (" + sendSize + ") below minimum required (" + ScpHelper.MIN_RECEIVE_BUFFER_SIZE + ")"); + if (receiveSize < ScpHelper.MIN_RECEIVE_BUFFER_SIZE) { + throw new IllegalArgumentException("<ScpCommmand>(" + command + ") receive buffer size " + + "(" + sendSize + ") below minimum required " + + "(" + ScpHelper.MIN_RECEIVE_BUFFER_SIZE + ")"); } + receiveBufferSize = receiveSize; listener = (eventListener == null) ? ScpTransferEventListener.EMPTY : eventListener; log.debug("Executing command {}", command); String[] args = command.split(" "); for (int i = 1; i < args.length; i++) { - String argVal=args[i]; + String argVal = args[i]; if (argVal.charAt(0) == '-') { for (int j = 1; j < argVal.length(); j++) { - char option=argVal.charAt(j); - switch(option) { + char option = argVal.charAt(j); + switch (option) { case 'f': optF = true; break; @@ -125,13 +132,13 @@ public class ScpCommand extends AbstractLoggingBean implements Command, Runnable case 'd': optD = true; break; - default: // ignored + default: // ignored // error = new IOException("Unsupported option: " + args[i].charAt(j)); // return; } } } else { - String prevArg=args[i - 1]; + String prevArg = args[i - 1]; path = command.substring(command.indexOf(prevArg) + prevArg.length() + 1); if (path.startsWith("\"") && path.endsWith("\"") || path.startsWith("'") && path.endsWith("'")) { path = path.substring(1, path.length() - 1); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommandFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommandFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommandFactory.java index 6f30a17..72c9686 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommandFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/command/ScpCommandFactory.java @@ -35,9 +35,8 @@ import org.apache.sshd.server.CommandFactory; * or can be used to augment another <code>CommandFactory</code> and provides * <code>SCP</code> support. * - * @see ScpCommand - * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> + * @see ScpCommand */ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorServiceConfigurer { /** @@ -144,8 +143,8 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer } /** - * @param shutdown If {@code true} the {@link ExecutorService#shutdownNow()} - * will be called when command terminates - unless it is the ad-hoc + * @param shutdown If {@code true} the {@link ExecutorService#shutdownNow()} + * will be called when command terminates - unless it is the ad-hoc * service, which will be shutdown regardless */ @Override @@ -158,13 +157,15 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer } /** - * @param sendSize Size (in bytes) of buffer to use when sending files + * @param sendSize Size (in bytes) of buffer to use when sending files * @see ScpHelper#MIN_SEND_BUFFER_SIZE */ public void setSendBufferSize(int sendSize) { - if ((sendBufferSize = sendSize) < ScpHelper.MIN_SEND_BUFFER_SIZE) { - throw new IllegalArgumentException("<ScpCommandFactory>() send buffer size (" + sendSize + ") below minimum required (" + ScpHelper.MIN_SEND_BUFFER_SIZE + ")"); + if (sendSize < ScpHelper.MIN_SEND_BUFFER_SIZE) { + throw new IllegalArgumentException("<ScpCommandFactory>() send buffer size " + + "(" + sendSize + ") below minimum required (" + ScpHelper.MIN_SEND_BUFFER_SIZE + ")"); } + sendBufferSize = sendSize; } public int getReceiveBufferSize() { @@ -172,13 +173,15 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer } /** - * @param receiveSize Size (in bytes) of buffer to use when receiving files + * @param receiveSize Size (in bytes) of buffer to use when receiving files * @see ScpHelper#MIN_RECEIVE_BUFFER_SIZE */ public void setReceiveBufferSize(int receiveSize) { - if ((receiveBufferSize = receiveSize) < ScpHelper.MIN_RECEIVE_BUFFER_SIZE) { - throw new IllegalArgumentException("<ScpCommandFactory>() receive buffer size (" + receiveSize + ") below minimum required (" + ScpHelper.MIN_RECEIVE_BUFFER_SIZE + ")"); + if (receiveSize < ScpHelper.MIN_RECEIVE_BUFFER_SIZE) { + throw new IllegalArgumentException("<ScpCommandFactory>() receive buffer size " + + "(" + receiveSize + ") below minimum required (" + ScpHelper.MIN_RECEIVE_BUFFER_SIZE + ")"); } + receiveBufferSize = receiveSize; } /** @@ -214,10 +217,10 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer * correct. If parsing fails the responsibility is delegated to * the configured {@link CommandFactory} instance; if one exist. * - * @param command command to parse + * @param command command to parse * @return configured {@link Command} instance * @throws IllegalArgumentException if not an SCP command and no - * delegate command factory is available + * delegate command factory is available * @see ScpHelper#SCP_COMMAND_PREFIX */ @Override @@ -240,12 +243,11 @@ public class ScpCommandFactory implements CommandFactory, Cloneable, ExecutorSer ScpCommandFactory other = getClass().cast(super.clone()); // clone the listeners set as well other.listeners = this.listeners.isEmpty() - ? new CopyOnWriteArraySet<ScpTransferEventListener>() - : new CopyOnWriteArraySet<>(this.listeners) - ; + ? new CopyOnWriteArraySet<ScpTransferEventListener>() + : new CopyOnWriteArraySet<>(this.listeners); other.listenerProxy = EventListenerUtils.proxyWrapper(ScpTransferEventListener.class, getClass().getClassLoader(), other.listeners); return other; - } catch(CloneNotSupportedException e) { + } catch (CloneNotSupportedException e) { throw new RuntimeException(e); // un-expected... } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java index 846c428..f8909ca 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeyEntry.java @@ -57,14 +57,21 @@ import org.apache.sshd.server.auth.pubkey.RejectAllPublickeyAuthenticator; * to the <A HREF="http://en.wikibooks.org/wiki/OpenSSH/Client_Configuration_Files#.7E.2F.ssh.2Fauthorized_keys">OpenSSH format</A>. * <B>Note:</B> {@code equals/hashCode} check only the key type and data - the * comment and/or login options are not considered part of equality + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class AuthorizedKeyEntry extends PublicKeyEntry { + + /** + * Standard OpenSSH authorized keys file name + */ + public static final String STD_AUTHORIZED_KEYS_FILENAME = "authorized_keys"; + private static final long serialVersionUID = -9007505285002809156L; - private String comment; + private String comment; // for options that have no value, "true" is used - private Map<String,String> loginOptions=Collections.emptyMap(); + private Map<String, String> loginOptions = Collections.emptyMap(); public AuthorizedKeyEntry() { super(); @@ -78,23 +85,26 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { this.comment = value; } - public Map<String,String> getLoginOptions() { + public Map<String, String> getLoginOptions() { return loginOptions; } - public void setLoginOptions(Map<String,String> value) { - if ((this.loginOptions=value) == null) { + public void setLoginOptions(Map<String, String> value) { + if (value == null) { this.loginOptions = Collections.emptyMap(); + } else { + this.loginOptions = value; } } @Override public PublicKey appendPublicKey(Appendable sb) throws IOException, GeneralSecurityException { - Map<String,String> options=getLoginOptions(); + Map<String, String> options = getLoginOptions(); if (!GenericUtils.isEmpty(options)) { int index = 0; - for (Map.Entry<String,String> oe : options.entrySet()) { - String key = oe.getKey(), value = oe.getValue(); + for (Map.Entry<String, String> oe : options.entrySet()) { + String key = oe.getKey(); + String value = oe.getValue(); if (index > 0) { sb.append(','); } @@ -117,31 +127,30 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { if (!GenericUtils.isEmpty(kc)) { sb.append(' ').append(kc); } - + return key; } @Override public String toString() { - String entry = super.toString(); - String kc = getComment(); - Map<?,?> ko=getLoginOptions(); + String entry = super.toString(); + String kc = getComment(); + Map<?, ?> ko = getLoginOptions(); return (GenericUtils.isEmpty(ko) ? "" : ko.toString() + " ") + entry - + (GenericUtils.isEmpty(kc) ? "" : " " + kc) - ; + + (GenericUtils.isEmpty(kc) ? "" : " " + kc); } - - public static PublickeyAuthenticator fromAuthorizedEntries(Collection<? extends AuthorizedKeyEntry> entries) throws IOException, GeneralSecurityException { - Collection<PublicKey> keys = resolveAuthorizedKeys(entries); + + public static PublickeyAuthenticator fromAuthorizedEntries(Collection<? extends AuthorizedKeyEntry> entries) throws IOException, GeneralSecurityException { + Collection<PublicKey> keys = resolveAuthorizedKeys(entries); if (GenericUtils.isEmpty(keys)) { return RejectAllPublickeyAuthenticator.INSTANCE; } else { return new KeySetPublickeyAuthenticator(keys); } } - - public static List<PublicKey> resolveAuthorizedKeys(Collection<? extends AuthorizedKeyEntry> entries) throws IOException, GeneralSecurityException { + + public static List<PublicKey> resolveAuthorizedKeys(Collection<? extends AuthorizedKeyEntry> entries) throws IOException, GeneralSecurityException { if (GenericUtils.isEmpty(entries)) { return Collections.emptyList(); } @@ -151,16 +160,12 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { PublicKey k = e.resolvePublicKey(); keys.add(k); } - + return keys; } - /** - * Standard OpenSSH authorized keys file name - */ - public static final String STD_AUTHORIZED_KEYS_FILENAME="authorized_keys"; private static final class LazyDefaultAuthorizedKeysFileHolder { - private static final File keysFile=new File(PublicKeyEntry.getDefaultKeysFolder(), STD_AUTHORIZED_KEYS_FILENAME); + private static final File KEYS_FILE = new File(PublicKeyEntry.getDefaultKeysFolder(), STD_AUTHORIZED_KEYS_FILENAME); } /** @@ -168,16 +173,18 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { */ @SuppressWarnings("synthetic-access") public static File getDefaultAuthorizedKeysFile() { - return LazyDefaultAuthorizedKeysFileHolder.keysFile; + return LazyDefaultAuthorizedKeysFileHolder.KEYS_FILE; } + /** * Reads read the contents of the default OpenSSH <code>authorized_keys</code> file + * * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there - * or empty if file does not exist * @throws IOException If failed to read keys from file */ public static Collection<AuthorizedKeyEntry> readDefaultAuthorizedKeys() throws IOException { - File keysFile=getDefaultAuthorizedKeysFile(); + File keysFile = getDefaultAuthorizedKeysFile(); if (keysFile.exists()) { return readAuthorizedKeys(keysFile); } else { @@ -187,6 +194,7 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { /** * Reads read the contents of an <code>authorized_keys</code> file + * * @param url The {@link URL} to read from * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries @@ -198,6 +206,7 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { /** * Reads read the contents of an <code>authorized_keys</code> file + * * @param file The {@link File} to read from * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries @@ -209,20 +218,22 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { /** * Reads read the contents of an <code>authorized_keys</code> file - * @param path {@link Path} to read from + * + * @param path {@link Path} to read from * @param options The {@link OpenOption}s to use - if unspecified then appropriate - * defaults assumed + * defaults assumed * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries * @see #readAuthorizedKeys(InputStream, boolean) * @see Files#newInputStream(Path, OpenOption...) */ - public static Collection<AuthorizedKeyEntry> readAuthorizedKeys(Path path, OpenOption ... options) throws IOException { + public static Collection<AuthorizedKeyEntry> readAuthorizedKeys(Path path, OpenOption... options) throws IOException { return readAuthorizedKeys(Files.newInputStream(path, options), true); } /** * Reads read the contents of an <code>authorized_keys</code> file + * * @param filePath The file path to read from * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries @@ -234,51 +245,54 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { /** * Reads read the contents of an <code>authorized_keys</code> file - * @param in The {@link InputStream} + * + * @param in The {@link InputStream} * @param okToClose <code>true</code> if method may close the input stream - * regardless of whether successful or failed + * regardless of whether successful or failed * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries * @see #readAuthorizedKeys(Reader, boolean) */ public static Collection<AuthorizedKeyEntry> readAuthorizedKeys(InputStream in, boolean okToClose) throws IOException { - try(Reader rdr=new InputStreamReader(NoCloseInputStream.resolveInputStream(in, okToClose), StandardCharsets.UTF_8)) { + try (Reader rdr = new InputStreamReader(NoCloseInputStream.resolveInputStream(in, okToClose), StandardCharsets.UTF_8)) { return readAuthorizedKeys(rdr, true); } } /** * Reads read the contents of an <code>authorized_keys</code> file - * @param rdr The {@link Reader} + * + * @param rdr The {@link Reader} * @param okToClose <code>true</code> if method may close the input stream - * regardless of whether successful or failed + * regardless of whether successful or failed * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries * @see #readAuthorizedKeys(BufferedReader) */ public static Collection<AuthorizedKeyEntry> readAuthorizedKeys(Reader rdr, boolean okToClose) throws IOException { - try(BufferedReader buf=new BufferedReader(NoCloseReader.resolveReader(rdr, okToClose))) { + try (BufferedReader buf = new BufferedReader(NoCloseReader.resolveReader(rdr, okToClose))) { return readAuthorizedKeys(buf); } } /** * @param rdr The {@link BufferedReader} to use to read the contents of - * an <code>authorized_keys</code> file + * an <code>authorized_keys</code> file * @return A {@link Collection} of all the {@link AuthorizedKeyEntry}-ies found there * @throws IOException If failed to read or parse the entries * @see #parseAuthorizedKeyEntry(String) */ public static Collection<AuthorizedKeyEntry> readAuthorizedKeys(BufferedReader rdr) throws IOException { - Collection<AuthorizedKeyEntry> entries=null; + Collection<AuthorizedKeyEntry> entries = null; - for (String line=rdr.readLine(); line != null; line=rdr.readLine()) { - final AuthorizedKeyEntry entry; + for (String line = rdr.readLine(); line != null; line = rdr.readLine()) { + final AuthorizedKeyEntry entry; try { - if ((entry=parseAuthorizedKeyEntry(line.trim())) == null) { + entry = parseAuthorizedKeyEntry(line.trim()); + if (entry == null) { continue; } - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { throw new StreamCorruptedException(e.getMessage()); } @@ -308,21 +322,22 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { return null; } - int startPos=line.indexOf(' '); + int startPos = line.indexOf(' '); if (startPos <= 0) { throw new IllegalArgumentException("Bad format (no key data delimiter): " + line); } - int endPos=line.indexOf(' ', startPos + 1); + int endPos = line.indexOf(' ', startPos + 1); if (endPos <= startPos) { endPos = line.length(); } String keyType = line.substring(0, startPos); - PublicKeyEntryDecoder<?,?> decoder = KeyUtils.getPublicKeyEntryDecoder(keyType); - final AuthorizedKeyEntry entry; + PublicKeyEntryDecoder<?, ?> decoder = KeyUtils.getPublicKeyEntryDecoder(keyType); + final AuthorizedKeyEntry entry; if (decoder == null) { // assume this is due to the fact that it starts with login options - if ((entry=parseAuthorizedKeyEntry(line.substring(startPos + 1).trim())) == null) { + entry = parseAuthorizedKeyEntry(line.substring(startPos + 1).trim()); + if (entry == null) { throw new IllegalArgumentException("Bad format (no key data after login options): " + line); } @@ -336,35 +351,35 @@ public class AuthorizedKeyEntry extends PublicKeyEntry { return entry; } - - public static Map<String,String> parseLoginOptions(String options) { + + public static Map<String, String> parseLoginOptions(String options) { // TODO add support if quoted values contain ',' - String[] pairs=GenericUtils.split(options, ','); + String[] pairs = GenericUtils.split(options, ','); if (GenericUtils.isEmpty(pairs)) { return Collections.emptyMap(); } - - Map<String,String> optsMap=new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + Map<String, String> optsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (String p : pairs) { p = GenericUtils.trimToEmpty(p); if (GenericUtils.isEmpty(p)) { continue; } - - int pos=p.indexOf('='); - String name=(pos < 0) ? p : GenericUtils.trimToEmpty(p.substring(0, pos)); - CharSequence value=(pos < 0) ? null : GenericUtils.trimToEmpty(p.substring(pos + 1)); + + int pos = p.indexOf('='); + String name = (pos < 0) ? p : GenericUtils.trimToEmpty(p.substring(0, pos)); + CharSequence value = (pos < 0) ? null : GenericUtils.trimToEmpty(p.substring(pos + 1)); value = GenericUtils.stripQuotes(value); if (value == null) { value = Boolean.TRUE.toString(); } - - String prev=optsMap.put(name, value.toString()); + + String prev = optsMap.put(name, value.toString()); if (prev != null) { throw new IllegalArgumentException("Multiple values for key=" + name + ": old=" + prev + ", new=" + value); } } - + return optsMap; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java index d34b758..1d7a177 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticator.java @@ -42,6 +42,7 @@ import org.apache.sshd.server.session.ServerSession; * new authentication request is received. <B>Note:</B> by default, the only * validation of the username is that it is not {@code null}/empty - see * {@link #isValidUsername(String, ServerSession)} + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class AuthorizedKeysAuthenticator extends ModifiableFileWatcher implements PublickeyAuthenticator { @@ -76,25 +77,21 @@ public class AuthorizedKeysAuthenticator extends ModifiableFileWatcher implement if (log.isDebugEnabled()) { log.debug("authenticate(" + username + ")[" + session + "][" + key.getAlgorithm() + "] accepted " + accepted + " from " + getPath()); } - + return accepted; - } catch(Exception e) { + } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("authenticate(" + username + ")[" + session + "][" + getPath() + "]" + " failed (" + e.getClass().getSimpleName() + ")" + " to resolve delegate: " + e.getMessage()); } - + return false; } } protected boolean isValidUsername(String username, ServerSession session) { - if (GenericUtils.isEmpty(username)) { - return false; - } else { - return true; - } + return !GenericUtils.isEmpty(username); } protected PublickeyAuthenticator resolvePublickeyAuthenticator(String username, ServerSession session) @@ -115,10 +112,10 @@ public class AuthorizedKeysAuthenticator extends ModifiableFileWatcher implement log.info("resolvePublickeyAuthenticator(" + username + ")[" + session + "] no authorized keys file at " + path); } } - + return delegateHolder.get(); } - + protected Collection<AuthorizedKeyEntry> reloadAuthorizedKeys(Path path, String username, ServerSession session) throws IOException { Collection<AuthorizedKeyEntry> entries = AuthorizedKeyEntry.readAuthorizedKeys(path, options); log.info("reloadAuthorizedKeys(" + username + ")[" + session + "] loaded " + GenericUtils.size(entries) + " keys from " + path); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 9989219..ec8fd6f 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 @@ -28,7 +28,6 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.Collection; import org.apache.sshd.common.config.keys.KeyUtils; -import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.io.IoUtils; import org.apache.sshd.server.session.ServerSession; @@ -38,6 +37,7 @@ import org.apache.sshd.server.session.ServerSession; * the server, re-loading it if necessary. It also (optionally) enforces the same * permissions regime as {@code OpenSSH} does for the file permissions. By default * also compares the current username with the authenticated one. + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthenticator { @@ -52,8 +52,8 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica /** * @param strict If {@code true} then makes sure that the containing folder - * has 0700 access and the file 0600. <B>Note:</B> for <I>Windows</I> it - * does not check these permissions + * has 0700 access and the file 0600. <B>Note:</B> for <I>Windows</I> it + * does not check these permissions */ public DefaultAuthorizedKeysAuthenticator(boolean strict) { this(System.getProperty("user.name"), strict); @@ -71,11 +71,11 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica this(user, ValidateUtils.checkNotNull(file, "No file provided").toPath(), strict, IoUtils.getLinkOptions(false)); } - public DefaultAuthorizedKeysAuthenticator(Path path, boolean strict, LinkOption ... options) { + public DefaultAuthorizedKeysAuthenticator(Path path, boolean strict, LinkOption... options) { this(System.getProperty("user.name"), path, strict, options); } - public DefaultAuthorizedKeysAuthenticator(String user, Path path, boolean strict, LinkOption ... options) { + public DefaultAuthorizedKeysAuthenticator(String user, Path path, boolean strict, LinkOption... options) { super(path, options); this.user = ValidateUtils.checkNotNullAndNotEmpty(user, "No username provided"); this.strict = strict; @@ -94,13 +94,9 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica if (!super.isValidUsername(username, session)) { return false; } - + String expected = getUsername(); - if (username.equals(expected)) { - return true; - } else { - return false; // debug breakpoint - } + return username.equals(expected); } @Override @@ -115,10 +111,10 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica return super.reloadAuthorizedKeys(path, username, session); } - + /** - * @param path The {@link Path} to be validated - * @param perms The current {@link PosixFilePermission}s + * @param path The {@link Path} to be validated + * @param perms The current {@link PosixFilePermission}s * @param excluded The permissions <U>not</U> allowed to exist * @return The original path * @throws IOException If an excluded permission appears in the current ones @@ -129,7 +125,7 @@ public class DefaultAuthorizedKeysAuthenticator extends AuthorizedKeysAuthentica String filePath = path.toString(); throw new FileSystemException(filePath, filePath, "File not allowed to have " + p + " permission: " + filePath); } - + return path; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java index bc9f536..f1d424d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/config/keys/ServerIdentity.java @@ -32,11 +32,9 @@ import java.util.Properties; import java.util.TreeMap; import org.apache.sshd.common.NamedResource; -import org.apache.sshd.common.config.SshConfigFileReader; import org.apache.sshd.common.config.keys.IdentityUtils; import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.SecurityUtils; import org.apache.sshd.common.util.Transformer; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.io.IoUtils; @@ -44,37 +42,42 @@ import org.apache.sshd.server.SshServer; /** * Loads server identity key files - e.g., {@code /etc/ssh/ssh_host_rsa_key} + * * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - * @see SecurityUtils#isBouncyCastleRegistered() + * @see org.apache.sshd.common.util.SecurityUtils#isBouncyCastleRegistered() */ public final class ServerIdentity { - public static final String ID_FILE_PREFIX = "ssh_host_", ID_FILE_SUFFIX = "_key"; + + public static final String ID_FILE_PREFIX = "ssh_host_"; + public static final String ID_FILE_SUFFIX = "_key"; + /** * The server's keys configuration multi-value */ - public static final String HOST_KEY_CONFIG_PROP="HostKey"; + public static final String HOST_KEY_CONFIG_PROP = "HostKey"; + + public static final Transformer<String, String> ID_GENERATOR = + new Transformer<String, String>() { + @Override + public String transform(String input) { + return getIdentityFileName(input); + } + }; private ServerIdentity() { throw new UnsupportedOperationException("No instance"); } - public static final Transformer<String,String> ID_GENERATOR = - new Transformer<String,String>() { - @Override - public String transform(String input) { - return getIdentityFileName(input); - } - }; - /** * Sets the server's {@link KeyPairProvider} with the loaded identities - if any - * @param server The {@link SshServer} to configure - * @param props The {@link Properties} holding the server's configuration - ignored - * if {@code null}/empty + * + * @param server The {@link SshServer} to configure + * @param props The {@link Properties} holding the server's configuration - ignored + * if {@code null}/empty * @param supportedOnly If {@code true} then ignore identities that are not - * supported internally + * supported internally * @return The updated server - * @throws IOException If failed to access the file system + * @throws IOException If failed to access the file system * @throws GeneralSecurityException If failed to load the keys * @see #loadKeyPairProvider(Properties, boolean, LinkOption...) */ @@ -84,48 +87,48 @@ public final class ServerIdentity { if (provider != null) { server.setKeyPairProvider(provider); } - + return server; } /** - * @param props The {@link Properties} holding the server's configuration - ignored - * if {@code null}/empty + * @param props The {@link Properties} holding the server's configuration - ignored + * if {@code null}/empty * @param supportedOnly If {@code true} then ignore identities that are not - * supported internally - * @param options The {@link LinkOption}s to use when checking files existence + * supported internally + * @param options The {@link LinkOption}s to use when checking files existence * @return A {@link KeyPair} for the identities - {@code null} if no identities * available (e.g., after filtering unsupported ones) - * @throws IOException If failed to access the file system + * @throws IOException If failed to access the file system * @throws GeneralSecurityException If failed to load the keys * @see #loadIdentities(Properties, LinkOption...) * @see IdentityUtils#createKeyPairProvider(Map, boolean) */ - public static KeyPairProvider loadKeyPairProvider(Properties props, boolean supportedOnly, LinkOption ... options) + public static KeyPairProvider loadKeyPairProvider(Properties props, boolean supportedOnly, LinkOption... options) throws IOException, GeneralSecurityException { - Map<String,KeyPair> ids = loadIdentities(props, options); + Map<String, KeyPair> ids = loadIdentities(props, options); return IdentityUtils.createKeyPairProvider(ids, supportedOnly); } /** - * @param props The {@link Properties} holding the server's configuration - ignored - * if {@code null}/empty + * @param props The {@link Properties} holding the server's configuration - ignored + * if {@code null}/empty * @param options The {@link LinkOption}s to use when checking files existence * @return A {@link Map} of the identities where key=identity type (case * <U>insensitive</U>), value=the {@link KeyPair} of the identity - * @throws IOException If failed to access the file system + * @throws IOException If failed to access the file system * @throws GeneralSecurityException If failed to load the keys * @see #findIdentities(Properties, LinkOption...) * @see IdentityUtils#loadIdentities(Map, org.apache.sshd.common.config.keys.FilePasswordProvider, java.nio.file.OpenOption...) */ - public static Map<String,KeyPair> loadIdentities(Properties props, LinkOption ... options) throws IOException, GeneralSecurityException { - Map<String,Path> ids = findIdentities(props, options); + public static Map<String, KeyPair> loadIdentities(Properties props, LinkOption... options) throws IOException, GeneralSecurityException { + Map<String, Path> ids = findIdentities(props, options); return IdentityUtils.loadIdentities(ids, null /* server key files are never encrypted */, IoUtils.EMPTY_OPEN_OPTIONS); } /** - * @param props The {@link Properties} holding the server's configuration - ignored - * if {@code null}/empty + * @param props The {@link Properties} holding the server's configuration - ignored + * if {@code null}/empty * @param options The {@link LinkOption}s to use when checking files existence * @return A {@link Map} of the found identities where key=the identity type * (case <U>insensitive</I>) and value=the {@link Path} of the file holding @@ -133,27 +136,27 @@ public final class ServerIdentity { * @throws IOException If failed to access the file system * @see #getIdentityType(String) * @see #HOST_KEY_CONFIG_PROP - * @see SshConfigFileReader#readConfigFile(File) + * @see org.apache.sshd.common.config.SshConfigFileReader#readConfigFile(File) */ - public static Map<String,Path> findIdentities(Properties props, LinkOption ... options) throws IOException { + public static Map<String, Path> findIdentities(Properties props, LinkOption... options) throws IOException { if (GenericUtils.isEmpty(props)) { return Collections.emptyMap(); } - + String keyList = props.getProperty(HOST_KEY_CONFIG_PROP); String[] paths = GenericUtils.split(keyList, ','); if (GenericUtils.isEmpty(paths)) { return Collections.emptyMap(); } - - Map<String,Path> ids = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + Map<String, Path> ids = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (String p : paths) { File file = new File(p); Path path = file.toPath(); if (!Files.exists(path, options)) { continue; } - + String type = getIdentityType(path.getFileName().toString()); if (GenericUtils.isEmpty(type)) { type = p; // just in case the file name does not adhere to the standard naming convention @@ -161,7 +164,7 @@ public final class ServerIdentity { Path prev = ids.put(type, path); ValidateUtils.checkTrue(prev == null, "Multiple mappings for type=%s", type); } - + return ids; } @@ -172,9 +175,9 @@ public final class ServerIdentity { */ public static String getIdentityType(String name) { if (GenericUtils.isEmpty(name) - || (name.length() <= (ID_FILE_PREFIX.length() + ID_FILE_SUFFIX.length())) - || (!name.startsWith(ID_FILE_PREFIX)) - || (!name.endsWith(ID_FILE_SUFFIX))) { + || (name.length() <= (ID_FILE_PREFIX.length() + ID_FILE_SUFFIX.length())) + || (!name.startsWith(ID_FILE_PREFIX)) + || (!name.endsWith(ID_FILE_SUFFIX))) { return null; } else { return name.substring(ID_FILE_PREFIX.length(), name.length() - ID_FILE_SUFFIX.length()); @@ -187,7 +190,7 @@ public final class ServerIdentity { /** * @param type The identity type - e.g., {@code rsa} - ignored - * if {@code null}/empty + * if {@code null}/empty * @return The matching file name for the identity - {@code null} * if no name * @see #ID_FILE_PREFIX http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/forward/DirectTcpipFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/DirectTcpipFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/DirectTcpipFactory.java index 1d88231..8cd66e9 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/forward/DirectTcpipFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/DirectTcpipFactory.java @@ -24,7 +24,7 @@ import org.apache.sshd.server.forward.TcpipServerChannel.TcpipFactory; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public class DirectTcpipFactory extends TcpipFactory { - public static final DirectTcpipFactory INSTANCE = new DirectTcpipFactory(); + public static final DirectTcpipFactory INSTANCE = new DirectTcpipFactory(); public DirectTcpipFactory() { super(ForwardingFilter.Type.Direct); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardedTcpipFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardedTcpipFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardedTcpipFactory.java index efc0744..018e6f4 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardedTcpipFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardedTcpipFactory.java @@ -25,7 +25,7 @@ import org.apache.sshd.server.forward.TcpipServerChannel.TcpipFactory; */ public class ForwardedTcpipFactory extends TcpipFactory { public static final ForwardedTcpipFactory INSTANCE = new ForwardedTcpipFactory(); - + public ForwardedTcpipFactory() { super(ForwardingFilter.Type.Forwarded); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java index 8e6f8b4..9bea393 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/forward/ForwardingFilter.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.Set; -import org.apache.sshd.agent.SshAgent; import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.SshdSocketAddress; import org.apache.sshd.common.session.Session; @@ -36,9 +35,9 @@ import org.apache.sshd.common.util.GenericUtils; public interface ForwardingFilter { /** * Determine if the session may arrange for agent forwarding. - * <p> + * <p/> * This server process will open a new listen socket locally and export - * the address in the {@link SshAgent#SSH_AUTHSOCKET_ENV_NAME} environment + * the address in the {@link org.apache.sshd.agent.SshAgent#SSH_AUTHSOCKET_ENV_NAME} environment * variable. * * @param session session requesting permission to forward the agent. @@ -48,7 +47,7 @@ public interface ForwardingFilter { /** * Determine if the session may arrange for X11 forwarding. - * <p> + * <p/> * This server process will open a new listen socket locally and export * the address in the environment so X11 clients can be tunneled to the * user's X11 display server. @@ -60,7 +59,7 @@ public interface ForwardingFilter { /** * Determine if the session may listen for inbound connections. - * <p> + * <p/> * This server process will open a new listen socket on the address given * by the client (usually 127.0.0.1 but may be any address). Any inbound * connections to this socket will be tunneled over the session to the @@ -68,7 +67,7 @@ public interface ForwardingFilter { * host on the client's side of the network. * * @param address address the client has requested this server listen - * for inbound connections on, and relay them through the client. + * for inbound connections on, and relay them through the client. * @param session session requesting permission to listen for connections. * @return true if the socket is permitted; false if it must be denied. */ @@ -78,24 +77,24 @@ public interface ForwardingFilter { * The type of requested connection forwarding. The type's {@link #getName()} * method returns the SSH request type */ - enum Type implements NamedResource { + enum Type implements NamedResource { Direct("direct-tcpip"), Forwarded("forwarded-tcpip"); - + + public static final Set<Type> VALUES = + Collections.unmodifiableSet(EnumSet.allOf(Type.class)); + private final String name; + Type(String name) { + this.name = name; + } + @Override public final String getName() { return name; } - Type(String name) { - this.name = name; - } - - public static final Set<Type> VALUES = - Collections.unmodifiableSet(EnumSet.allOf(Type.class)); - /** * @param name Either the enum name or the request - ignored if {@code null}/empty * @return The matching {@link Type} value - case <U>insensitive</U>, @@ -107,7 +106,7 @@ public interface ForwardingFilter { if (GenericUtils.isEmpty(name)) { return null; } - + Type t = fromName(name); if (t == null) { t = fromEnumName(name); @@ -124,7 +123,7 @@ public interface ForwardingFilter { public static Type fromName(String name) { return NamedResource.Utils.findByName(name, String.CASE_INSENSITIVE_ORDER, VALUES); } - + /** * @param name The enum value name - ignored if {@code null}/empty * @return The matching {@link Type} value - case <U>insensitive</U>, @@ -134,28 +133,28 @@ public interface ForwardingFilter { if (GenericUtils.isEmpty(name)) { return null; } - + for (Type t : VALUES) { if (name.equalsIgnoreCase(t.name())) { return t; } } - + return null; } } /** * Determine if the session may create an outbound connection. - * <p> + * <p/> * This server process will connect to another server listening on the * address specified by the client. Usually this is to another port on * the same host (127.0.0.1) but may be to any other system this server * can reach on the server's side of the network. * - * @param type The {@link Type} of requested connection forwarding + * @param type The {@link Type} of requested connection forwarding * @param address address the client has requested this server listen - * for inbound connections on, and relay them through the client. + * for inbound connections on, and relay them through the client. * @param session session requesting permission to listen for connections. * @return true if the socket is permitted; false if it must be denied. */
