Merge branches 'master' and 'passwd_recovery_process' of https://github.com/AuthMe/AuthMeReloaded into passwd_recovery_process
# Conflicts: # docs/config.md # src/main/resources/messages/messages_bg.yml # src/main/resources/messages/messages_es.yml # src/main/resources/messages/messages_pt.yml # src/main/resources/messages/messages_zhcn.yml
This commit is contained in:
@@ -13,7 +13,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@@ -172,7 +171,7 @@ public class BukkitService implements SettingsDependent {
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @see BukkitScheduler#runTaskTimer(Plugin, Runnable, long, long)
|
||||
* @see BukkitScheduler#runTaskTimer(org.bukkit.plugin.Plugin, Runnable, long, long)
|
||||
*/
|
||||
public BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period) {
|
||||
return task.runTaskTimer(authMe, delay, period);
|
||||
|
||||
@@ -65,16 +65,6 @@ public class CommonService {
|
||||
messages.send(sender, key, replacements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a message.
|
||||
*
|
||||
* @param key the key of the message
|
||||
* @return the message, split by line
|
||||
*/
|
||||
public String[] retrieveMessage(MessageKey key) {
|
||||
return messages.retrieve(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a message in one piece.
|
||||
*
|
||||
@@ -102,6 +92,7 @@ public class CommonService {
|
||||
* @param player the player to process
|
||||
* @param group the group to add the player to
|
||||
*/
|
||||
// TODO ljacqu 20170304: Move this out of CommonService
|
||||
public void setGroup(Player player, AuthGroupType group) {
|
||||
authGroupHandler.setGroup(player, group);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.security.crypts.SHA256;
|
||||
import fr.xephi.authme.security.crypts.Sha256;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
|
||||
@@ -20,14 +20,14 @@ public final class MigrationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash all passwords to SHA256 and updated the setting if the password hash is set to the deprecated PLAINTEXT.
|
||||
* Hash all passwords to Sha256 and updated the setting if the password hash is set to the deprecated PLAINTEXT.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
* @param dataSource The data source
|
||||
* @param authmeSha256 Instance to the AuthMe SHA256 encryption method implementation
|
||||
* @param authmeSha256 Instance to the AuthMe Sha256 encryption method implementation
|
||||
*/
|
||||
public static void changePlainTextToSha256(Settings settings, DataSource dataSource,
|
||||
SHA256 authmeSha256) {
|
||||
Sha256 authmeSha256) {
|
||||
if (HashAlgorithm.PLAINTEXT == settings.getProperty(SecuritySettings.PASSWORD_HASH)) {
|
||||
ConsoleLogger.warning("Your HashAlgorithm has been detected as plaintext and is now deprecated;"
|
||||
+ " it will be changed and hashed now to the AuthMe default hashing method");
|
||||
|
||||
@@ -99,19 +99,19 @@ public class TeleportationService implements Reloadable {
|
||||
*
|
||||
* @param player the player
|
||||
* @param auth corresponding PlayerAuth object
|
||||
* @param limbo corresponding PlayerData object
|
||||
* @param limbo corresponding LimboPlayer object
|
||||
*/
|
||||
public void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo) {
|
||||
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// #856: If PlayerData comes from a persisted file, the Location might be null
|
||||
// #856: If LimboPlayer comes from a persisted file, the Location might be null
|
||||
String worldName = (limbo != null && limbo.getLocation() != null)
|
||||
? limbo.getLocation().getWorld().getName()
|
||||
: null;
|
||||
|
||||
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
||||
// The world in LimboPlayer is from where the player comes, before any teleportation by AuthMe
|
||||
if (mustForceSpawnAfterLogin(worldName)) {
|
||||
teleportToSpawn(player, true);
|
||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||
@@ -148,7 +148,7 @@ public class TeleportationService implements Reloadable {
|
||||
|
||||
/**
|
||||
* Emits the teleportation event and performs teleportation according to it (potentially modified
|
||||
* by external listeners). Note that not teleportation is performed if the event's location is empty.
|
||||
* by external listeners). Note that no teleportation is performed if the event's location is empty.
|
||||
*
|
||||
* @param player the player to teleport
|
||||
* @param event the event to emit and according to which to teleport
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
@@ -11,8 +14,10 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
@@ -22,6 +27,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static fr.xephi.authme.util.StringUtils.isInsideString;
|
||||
|
||||
/**
|
||||
* Validation service.
|
||||
*/
|
||||
@@ -38,6 +45,7 @@ public class ValidationService implements Reloadable {
|
||||
|
||||
private Pattern passwordRegex;
|
||||
private Set<String> unrestrictedNames;
|
||||
private Multimap<String, String> restrictedNames;
|
||||
|
||||
ValidationService() {
|
||||
}
|
||||
@@ -48,6 +56,9 @@ public class ValidationService implements Reloadable {
|
||||
passwordRegex = Utils.safePatternCompile(settings.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX));
|
||||
// Use Set for more efficient contains() lookup
|
||||
unrestrictedNames = new HashSet<>(settings.getProperty(RestrictionSettings.UNRESTRICTED_NAMES));
|
||||
restrictedNames = settings.getProperty(RestrictionSettings.ENABLE_RESTRICTED_USERS)
|
||||
? loadNameRestrictions(settings.getProperty(RestrictionSettings.RESTRICTED_USERS))
|
||||
: HashMultimap.create();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,9 +126,10 @@ public class ValidationService implements Reloadable {
|
||||
}
|
||||
|
||||
String countryCode = geoIpService.getCountryCode(hostAddress);
|
||||
return validateWhitelistAndBlacklist(countryCode,
|
||||
ProtectionSettings.COUNTRIES_WHITELIST,
|
||||
ProtectionSettings.COUNTRIES_BLACKLIST);
|
||||
boolean isCountryAllowed = validateWhitelistAndBlacklist(countryCode,
|
||||
ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST);
|
||||
ConsoleLogger.debug("Country code `{0}` for `{1}` is allowed: {2}", countryCode, hostAddress, isCountryAllowed);
|
||||
return isCountryAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,6 +142,24 @@ public class ValidationService implements Reloadable {
|
||||
return unrestrictedNames.contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the player meets any name restriction if present (IP/domain-based).
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return true if the player may join, false if the player does not satisfy the name restrictions
|
||||
*/
|
||||
public boolean fulfillsNameRestrictions(Player player) {
|
||||
Collection<String> restrictions = restrictedNames.get(player.getName().toLowerCase());
|
||||
if (Utils.isCollectionEmpty(restrictions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String ip = PlayerUtils.getPlayerIp(player);
|
||||
String domain = player.getAddress().getHostName();
|
||||
return restrictions.stream()
|
||||
.anyMatch(restriction -> ip.equals(restriction) || domain.equalsIgnoreCase(restriction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether the given value is allowed according to the given whitelist and blacklist settings.
|
||||
* Whitelist has precedence over blacklist: if a whitelist is set, the value is rejected if not present
|
||||
@@ -159,6 +189,26 @@ public class ValidationService implements Reloadable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the configured name restrictions into a Multimap by player name (all-lowercase).
|
||||
*
|
||||
* @param configuredRestrictions the restriction rules to convert to a map
|
||||
* @return map of allowed IPs/domain names by player name
|
||||
*/
|
||||
private Multimap<String, String> loadNameRestrictions(List<String> configuredRestrictions) {
|
||||
Multimap<String, String> restrictions = HashMultimap.create();
|
||||
for (String restriction : configuredRestrictions) {
|
||||
if (isInsideString(';', restriction)) {
|
||||
String[] data = restriction.split(";");
|
||||
restrictions.put(data[0].toLowerCase(), data[1]);
|
||||
} else {
|
||||
ConsoleLogger.warning("Restricted user rule must have a ';' separating name from restriction,"
|
||||
+ " but found: '" + restriction + "'");
|
||||
}
|
||||
}
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
public static final class ValidationResult {
|
||||
private final MessageKey messageKey;
|
||||
private final String[] args;
|
||||
@@ -194,6 +244,7 @@ public class ValidationService implements Reloadable {
|
||||
public MessageKey getMessageKey() {
|
||||
return messageKey;
|
||||
}
|
||||
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user