diff --git a/src/main/java/com/ryanmichela/sshd/ConfigPasswordAuthenticator.java b/src/main/java/com/ryanmichela/sshd/ConfigPasswordAuthenticator.java index aa3954c..4f850c2 100644 --- a/src/main/java/com/ryanmichela/sshd/ConfigPasswordAuthenticator.java +++ b/src/main/java/com/ryanmichela/sshd/ConfigPasswordAuthenticator.java @@ -10,6 +10,7 @@ import java.util.Map; * Copyright 2013 Ryan Michela */ public class ConfigPasswordAuthenticator implements PasswordAuthenticator { + private Map failCounts = new HashMap(); @Override diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleCommandCompleter.java b/src/main/java/com/ryanmichela/sshd/ConsoleCommandCompleter.java index 975d37f..182a235 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleCommandCompleter.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleCommandCompleter.java @@ -4,15 +4,16 @@ package com.ryanmichela.sshd; * Copyright 2013 Ryan Michela */ +import jline.console.completer.Completer; import org.bukkit.Bukkit; import org.bukkit.command.CommandMap; -import jline.console.completer.Completer; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.logging.Level; public class ConsoleCommandCompleter implements Completer { + public int complete(final String buffer, final int cursor, final List candidates) { Waitable> waitable = new Waitable>() { @Override diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java index 20bd31f..11ea4da 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleCommandFactory.java @@ -14,12 +14,14 @@ import java.io.OutputStream; * Copyright 2013 Ryan Michela */ public class ConsoleCommandFactory implements CommandFactory { + @Override public Command createCommand(String command) { return new ConsoleCommand(command); } public class ConsoleCommand implements Command { + private String command; private InputStream in; @@ -50,7 +52,8 @@ public class ConsoleCommandFactory implements CommandFactory { @Override public void start(Environment environment) throws IOException { try { - SshdPlugin.instance.getLogger().info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); + SshdPlugin.instance.getLogger() + .info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } catch (Exception e) { SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage()); diff --git a/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java b/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java index 051ce9f..4df1697 100644 --- a/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java +++ b/src/main/java/com/ryanmichela/sshd/ConsoleLogFormatter.java @@ -54,20 +54,29 @@ public class ConsoleLogFormatter extends Formatter { // ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender final Map replacements = new EnumMap<>(ChatColor.class); - replacements.put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()); - replacements.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()); - replacements.put(ChatColor.DARK_GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()); - replacements.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()); - replacements.put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()); - replacements.put(ChatColor.DARK_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()); - replacements.put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()); + replacements + .put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()); + replacements + .put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()); + replacements.put(ChatColor.DARK_GREEN, + Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()); + replacements + .put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()); + replacements + .put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()); + replacements.put(ChatColor.DARK_PURPLE, + Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()); + replacements + .put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()); replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString()); - replacements.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()); + replacements + .put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()); replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString()); replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString()); replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString()); replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString()); - replacements.put(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()); + replacements.put(ChatColor.LIGHT_PURPLE, + Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()); replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString()); replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString()); replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString()); diff --git a/src/main/java/com/ryanmichela/sshd/FlushyStreamHandler.java b/src/main/java/com/ryanmichela/sshd/FlushyStreamHandler.java index 79aad4c..10c042c 100644 --- a/src/main/java/com/ryanmichela/sshd/FlushyStreamHandler.java +++ b/src/main/java/com/ryanmichela/sshd/FlushyStreamHandler.java @@ -1,8 +1,7 @@ package com.ryanmichela.sshd; -import org.apache.sshd.common.SshException; import jline.console.ConsoleReader; - +import org.apache.sshd.common.SshException; import java.io.IOException; import java.io.OutputStream; @@ -12,6 +11,7 @@ import java.util.logging.*; * Copyright 2013 Ryan Michela */ public class FlushyStreamHandler extends StreamHandler { + private ConsoleReader reader; public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader) { diff --git a/src/main/java/com/ryanmichela/sshd/PemDecoder.java b/src/main/java/com/ryanmichela/sshd/PemDecoder.java index 8051119..26d0a0a 100644 --- a/src/main/java/com/ryanmichela/sshd/PemDecoder.java +++ b/src/main/java/com/ryanmichela/sshd/PemDecoder.java @@ -13,6 +13,7 @@ import java.security.spec.RSAPublicKeySpec; * Copyright 2013 Ryan Michela */ public class PemDecoder extends java.io.BufferedReader { + private static final String BEGIN = "^-+\\s*BEGIN.+"; private static final String END = "^-+\\s*END.+"; private static final String COMMENT = "Comment:"; @@ -29,7 +30,7 @@ public class PemDecoder extends java.io.BufferedReader { return null; } - for(line = readLine(); line != null; line = readLine()) { + for (line = readLine(); line != null; line = readLine()) { if (!line.matches(END) && !line.startsWith(COMMENT)) { b64.append(line.trim()); } @@ -84,7 +85,7 @@ public class PemDecoder extends java.io.BufferedReader { private int decodeInt() { return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16) - | ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF); + | ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF); } private BigInteger decodeBigInt() { diff --git a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java index 5e50dbe..a7c34d6 100644 --- a/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java +++ b/src/main/java/com/ryanmichela/sshd/PublicKeyAuthenticator.java @@ -12,6 +12,7 @@ import java.security.PublicKey; * Copyright 2013 Ryan Michela */ public class PublicKeyAuthenticator implements PublickeyAuthenticator { + private File authorizedKeysDir; public PublicKeyAuthenticator(File authorizedKeysDir) { @@ -39,10 +40,13 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator { SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath()); } } catch (Exception e) { - SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage()); + SshdPlugin.instance.getLogger() + .severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage()); } } else { - SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username + ". Make sure the user's key is named the same as their user name without a file extension."); + SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username + + ". Make sure the user's key is named the same as their user name " + + "without a file extension."); } return false; diff --git a/src/main/java/com/ryanmichela/sshd/ReflectionUtil.java b/src/main/java/com/ryanmichela/sshd/ReflectionUtil.java index 971e28d..3d8d2d1 100644 --- a/src/main/java/com/ryanmichela/sshd/ReflectionUtil.java +++ b/src/main/java/com/ryanmichela/sshd/ReflectionUtil.java @@ -8,6 +8,7 @@ import java.lang.reflect.Modifier; * Copyright 2013 Ryan Michela */ public class ReflectionUtil { + public static void setProtectedValue(Object o, String field, Object newValue) { setProtectedValue(o.getClass(), o, field, newValue); } @@ -36,9 +37,9 @@ public class ReflectionUtil { public static T getProtectedValue(Object obj, String fieldName) { try { Class c = obj.getClass(); - while(c != Object.class) { + while (c != Object.class) { Field[] fields = c.getDeclaredFields(); - for(Field f : fields) { + for (Field f : fields) { if (f.getName() == fieldName) { f.setAccessible(true); return (T) f.get(obj); @@ -76,7 +77,7 @@ public class ReflectionUtil { public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) { try { Class[] pTypes = new Class[args.length]; - for(int i = 0; i < args.length; i++) { + for (int i = 0; i < args.length; i++) { if (args[i] instanceof Integer) { pTypes[i] = int.class; } else { @@ -87,8 +88,7 @@ public class ReflectionUtil { Method m = c.getDeclaredMethod(method, pTypes); m.setAccessible(true); return m.invoke(o, args); - } - catch (Exception ex) { + } catch (Exception ex) { System.out.println("*** " + c.getName() + "." + method + "(): " + ex); return null; } diff --git a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java index 599258a..401d7ad 100644 --- a/src/main/java/com/ryanmichela/sshd/SshdPlugin.java +++ b/src/main/java/com/ryanmichela/sshd/SshdPlugin.java @@ -16,6 +16,7 @@ import java.util.logging.Level; * Copyright 2013 Ryan Michela */ public class SshdPlugin extends JavaPlugin { + private SshServer sshd; public static SshdPlugin instance; diff --git a/src/main/java/com/ryanmichela/sshd/StreamHandlerAppender.java b/src/main/java/com/ryanmichela/sshd/StreamHandlerAppender.java index a08b676..1af7efe 100644 --- a/src/main/java/com/ryanmichela/sshd/StreamHandlerAppender.java +++ b/src/main/java/com/ryanmichela/sshd/StreamHandlerAppender.java @@ -14,6 +14,7 @@ import java.util.logging.StreamHandler; * Copyright 2014 Ryan Michela */ public class StreamHandlerAppender implements Appender { + private StreamHandler streamHandler; private UUID uuid; @@ -26,13 +27,13 @@ public class StreamHandlerAppender implements Appender { public void append(LogEvent logEvent) { java.util.logging.Level level; - if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG)) { + if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG)) { level = java.util.logging.Level.FINE; - } else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO)) { + } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO)) { level = java.util.logging.Level.INFO; - } else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN)) { + } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN)) { level = java.util.logging.Level.WARNING; - } else if(logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR)) { + } else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR)) { level = java.util.logging.Level.SEVERE; } else { level = java.util.logging.Level.INFO; diff --git a/src/main/java/com/ryanmichela/sshd/Waitable.java b/src/main/java/com/ryanmichela/sshd/Waitable.java index 64f0cc3..f34444e 100644 --- a/src/main/java/com/ryanmichela/sshd/Waitable.java +++ b/src/main/java/com/ryanmichela/sshd/Waitable.java @@ -6,11 +6,13 @@ import java.util.concurrent.ExecutionException; * Copyright 2013 Ryan Michela */ public abstract class Waitable implements Runnable { + private enum Status { WAITING, RUNNING, FINISHED, } + Throwable t = null; T value = null; Status status = Status.WAITING;