Fix codestyle
This commit is contained in:
parent
8f6319d979
commit
7330b1eead
@ -10,6 +10,7 @@ import java.util.Map;
|
||||
* Copyright 2013 Ryan Michela
|
||||
*/
|
||||
public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
||||
|
||||
private Map<String, Integer> failCounts = new HashMap<String, Integer>();
|
||||
|
||||
@Override
|
||||
|
@ -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<CharSequence> candidates) {
|
||||
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
||||
@Override
|
||||
|
@ -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());
|
||||
|
@ -54,20 +54,29 @@ public class ConsoleLogFormatter extends Formatter {
|
||||
// ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender
|
||||
final Map<ChatColor, String> 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());
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -6,11 +6,13 @@ import java.util.concurrent.ExecutionException;
|
||||
* Copyright 2013 Ryan Michela
|
||||
*/
|
||||
public abstract class Waitable<T> implements Runnable {
|
||||
|
||||
private enum Status {
|
||||
WAITING,
|
||||
RUNNING,
|
||||
FINISHED,
|
||||
}
|
||||
|
||||
Throwable t = null;
|
||||
T value = null;
|
||||
Status status = Status.WAITING;
|
||||
|
Loading…
Reference in New Issue
Block a user