Remove all files
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Console filter to replace sensitive AuthMe commands with a generic message.
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class ConsoleFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
if (record == null || record.getMessage() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (LogFilterHelper.isSensitiveAuthMeCommand(record.getMessage())) {
|
||||
String playerName = record.getMessage().split(" ")[0];
|
||||
record.setMessage(playerName + " issued an AuthMe command");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Creates and keeps track of {@link ConsoleLogger} instances.
|
||||
*/
|
||||
public final class ConsoleLoggerFactory {
|
||||
|
||||
private static final Map<String, ConsoleLogger> consoleLoggers = new ConcurrentHashMap<>();
|
||||
private static Settings settings;
|
||||
|
||||
private ConsoleLoggerFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates or returns the already existing logger associated with the given class.
|
||||
*
|
||||
* @param owningClass the class whose logger should be retrieved
|
||||
* @return logger for the given class
|
||||
*/
|
||||
public static ConsoleLogger get(Class<?> owningClass) {
|
||||
String name = owningClass.getCanonicalName();
|
||||
return consoleLoggers.computeIfAbsent(name, ConsoleLoggerFactory::createLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up all loggers according to the properties returned by the settings instance.
|
||||
*
|
||||
* @param settings the settings instance
|
||||
*/
|
||||
public static void reloadSettings(Settings settings) {
|
||||
ConsoleLoggerFactory.settings = settings;
|
||||
ConsoleLogger.initializeSharedSettings(settings);
|
||||
|
||||
consoleLoggers.values()
|
||||
.forEach(logger -> logger.initializeSettings(settings));
|
||||
}
|
||||
|
||||
public static int getTotalLoggers() {
|
||||
return consoleLoggers.size();
|
||||
}
|
||||
|
||||
private static ConsoleLogger createLogger(String name) {
|
||||
ConsoleLogger logger = new ConsoleLogger(name);
|
||||
if (settings != null) {
|
||||
logger.initializeSettings(settings);
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.apache.logging.log4j.core.filter.AbstractFilter;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
|
||||
/**
|
||||
* Implements a filter for Log4j to skip sensitive AuthMe commands.
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class Log4JFilter extends AbstractFilter {
|
||||
|
||||
private static final long serialVersionUID = -5594073755007974254L;
|
||||
|
||||
/**
|
||||
* Validates a Message instance and returns the {@link Result} value
|
||||
* depending on whether the message contains sensitive AuthMe data.
|
||||
*
|
||||
* @param message The Message object to verify
|
||||
*
|
||||
* @return The Result value
|
||||
*/
|
||||
private static Result validateMessage(Message message) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
return validateMessage(message.getFormattedMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a message and returns the {@link Result} value depending
|
||||
* on whether the message contains sensitive AuthMe data.
|
||||
*
|
||||
* @param message The message to verify
|
||||
*
|
||||
* @return The Result value
|
||||
*/
|
||||
private static Result validateMessage(String message) {
|
||||
return LogFilterHelper.isSensitiveAuthMeCommand(message)
|
||||
? Result.DENY
|
||||
: Result.NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(LogEvent event) {
|
||||
Message candidate = null;
|
||||
if (event != null) {
|
||||
candidate = event.getMessage();
|
||||
}
|
||||
return validateMessage(candidate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
|
||||
return validateMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
|
||||
return validateMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
|
||||
String candidate = null;
|
||||
if (msg != null) {
|
||||
candidate = msg.toString();
|
||||
}
|
||||
return validateMessage(candidate);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Service class for the log filters.
|
||||
*/
|
||||
final class LogFilterHelper {
|
||||
|
||||
@VisibleForTesting
|
||||
static final List<String> COMMANDS_TO_SKIP = withAndWithoutAuthMePrefix(
|
||||
"/login ", "/l ", "/log ", "/register ", "/reg ", "/unregister ", "/unreg ",
|
||||
"/changepassword ", "/cp ", "/changepass ", "/authme register ", "/authme reg ", "/authme r ",
|
||||
"/authme changepassword ", "/authme password ", "/authme changepass ", "/authme cp ", "/email setpassword ");
|
||||
|
||||
private static final String ISSUED_COMMAND_TEXT = "issued server command:";
|
||||
|
||||
private LogFilterHelper() {
|
||||
// Util class
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a message and return whether the message contains a sensitive AuthMe command.
|
||||
*
|
||||
* @param message The message to verify
|
||||
*
|
||||
* @return True if it is a sensitive AuthMe command, false otherwise
|
||||
*/
|
||||
static boolean isSensitiveAuthMeCommand(String message) {
|
||||
if (message == null) {
|
||||
return false;
|
||||
}
|
||||
String lowerMessage = message.toLowerCase(Locale.ROOT);
|
||||
return lowerMessage.contains(ISSUED_COMMAND_TEXT) && StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP);
|
||||
}
|
||||
|
||||
private static List<String> withAndWithoutAuthMePrefix(String... commands) {
|
||||
List<String> commandList = new ArrayList<>(commands.length * 2);
|
||||
for (String command : commands) {
|
||||
commandList.add(command);
|
||||
commandList.add(command.substring(0, 1) + "authme:" + command.substring(1));
|
||||
}
|
||||
return Collections.unmodifiableList(commandList);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
/**
|
||||
* Log level.
|
||||
*/
|
||||
public enum LogLevel {
|
||||
|
||||
/** Info: general messages. */
|
||||
INFO(3),
|
||||
|
||||
/** Fine: more detailed messages that may still be interesting to plugin users. */
|
||||
FINE(2),
|
||||
|
||||
/** Debug: very detailed messages for debugging. */
|
||||
DEBUG(1);
|
||||
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param value the log level; the higher the number the more "important" the level.
|
||||
* A log level enables its number and all above.
|
||||
*/
|
||||
LogLevel(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the current log level includes the given log level.
|
||||
*
|
||||
* @param level the level to process
|
||||
* @return true if the level is enabled, false otherwise
|
||||
*/
|
||||
public boolean includes(LogLevel level) {
|
||||
return value <= level.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user