Search in sources :

Example 81 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncAddEmailTest method shouldNotAddMailIfAlreadyUsed.

@Test
public void shouldNotAddMailIfAlreadyUsed() {
    // given
    String email = "player@mail.tld";
    given(player.getName()).willReturn("TestName");
    given(playerCache.isAuthenticated("testname")).willReturn(true);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(auth.getEmail()).willReturn(null);
    given(playerCache.getAuth("testname")).willReturn(auth);
    given(validationService.validateEmail(email)).willReturn(true);
    given(validationService.isEmailFreeForRegistration(email, player)).willReturn(false);
    // when
    asyncAddEmail.addEmail(player, email);
    // then
    verify(service).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
    verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 82 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class RakamakConverter method execute.

@Override
public // TODO ljacqu 20151229: Restructure this into smaller portions
void execute(CommandSender sender) {
    boolean useIp = settings.getProperty(ConverterSettings.RAKAMAK_USE_IP);
    String fileName = settings.getProperty(ConverterSettings.RAKAMAK_FILE_NAME);
    String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
    File source = new File(pluginFolder, fileName);
    File ipFiles = new File(pluginFolder, ipFileName);
    Map<String, String> playerIp = new HashMap<>();
    Map<String, HashedPassword> playerPassword = new HashMap<>();
    try {
        BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
        String line;
        if (useIp) {
            String tempLine;
            while ((tempLine = ipFile.readLine()) != null) {
                if (tempLine.contains("=")) {
                    String[] args = tempLine.split("=");
                    playerIp.put(args[0], args[1]);
                }
            }
        }
        ipFile.close();
        BufferedReader users = new BufferedReader(new FileReader(source));
        while ((line = users.readLine()) != null) {
            if (line.contains("=")) {
                String[] arguments = line.split("=");
                HashedPassword hashedPassword = passwordSecurity.computeHash(arguments[1], arguments[0]);
                playerPassword.put(arguments[0], hashedPassword);
            }
        }
        users.close();
        for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
            String playerName = m.getKey();
            HashedPassword psw = playerPassword.get(playerName);
            String ip = useIp ? playerIp.get(playerName) : "127.0.0.1";
            PlayerAuth auth = PlayerAuth.builder().name(playerName).realName(playerName).ip(ip).password(psw).lastLogin(0).build();
            database.saveAuth(auth);
        }
        Utils.logAndSendMessage(sender, "Rakamak database has been imported correctly");
    } catch (IOException ex) {
        ConsoleLogger.logException("Can't open the rakamak database file! Does it exist?", ex);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) File(java.io.File) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Example 83 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class VAuthConverter method execute.

@Override
public void execute(CommandSender sender) {
    try (Scanner scanner = new Scanner(vAuthPasswordsFile)) {
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            String name = line.split(": ")[0];
            String password = line.split(": ")[1];
            PlayerAuth auth;
            if (isUuidInstance(password)) {
                String pname;
                try {
                    pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
                } catch (Exception | NoSuchMethodError e) {
                    pname = getName(UUID.fromString(name));
                }
                if (pname == null) {
                    continue;
                }
                auth = PlayerAuth.builder().name(pname.toLowerCase()).realName(pname).password(password, null).build();
            } else {
                auth = PlayerAuth.builder().name(name.toLowerCase()).realName(name).password(password, null).build();
            }
            dataSource.saveAuth(auth);
        }
    } catch (IOException e) {
        ConsoleLogger.logException("Error while trying to import some vAuth data", e);
    }
}
Also used : Scanner(java.util.Scanner) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) IOException(java.io.IOException)

Example 84 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class XAuthConverter method convert.

private void convert(CommandSender sender) {
    if (pluginManager.getPlugin("xAuth") == null) {
        sender.sendMessage("[AuthMe] xAuth plugin not found");
        return;
    }
    // TODO ljacqu 20160702: xAuthDb is not used except for the existence check -- is this intended?
    File xAuthDb = new File(dataFolder.getParent(), makePath("xAuth", "xAuth.h2.db"));
    if (!xAuthDb.exists()) {
        sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
    }
    List<Integer> players = getXAuthPlayers();
    if (Utils.isCollectionEmpty(players)) {
        sender.sendMessage("[AuthMe] Error while importing xAuthPlayers: did not find any players");
        return;
    }
    sender.sendMessage("[AuthMe] Starting import...");
    for (int id : players) {
        String pl = getIdPlayer(id);
        String psw = getPassword(id);
        if (psw != null && !psw.isEmpty() && pl != null) {
            PlayerAuth auth = PlayerAuth.builder().name(pl.toLowerCase()).realName(pl).password(psw, null).build();
            database.saveAuth(auth);
        }
    }
    sender.sendMessage("[AuthMe] Successfully converted from xAuth database");
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) File(java.io.File)

Example 85 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsyncChangePassword method changePassword.

public void changePassword(final Player player, String oldPassword, String newPassword) {
    final String name = player.getName().toLowerCase();
    PlayerAuth auth = playerCache.getAuth(name);
    if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
        HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
        auth.setPassword(hashedPassword);
        if (!dataSource.updatePassword(auth)) {
            commonService.send(player, MessageKey.ERROR);
            return;
        }
        playerCache.updatePlayer(auth);
        commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
        ConsoleLogger.info(player.getName() + " changed his password");
    } else {
        commonService.send(player, MessageKey.WRONG_PASSWORD);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3