Search in sources :

Example 66 with PlayerAuth

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

the class AbstractDataSourceIntegrationTest method shouldGetAuth.

@Test
public void shouldGetAuth() {
    // given
    DataSource dataSource = getDataSource();
    // when
    PlayerAuth invalidAuth = dataSource.getAuth("notInDB");
    PlayerAuth bobbyAuth = dataSource.getAuth("Bobby");
    PlayerAuth userAuth = dataSource.getAuth("user");
    // then
    assertThat(invalidAuth, nullValue());
    assertThat(bobbyAuth, hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89"));
    assertThat(bobbyAuth, hasAuthLocation(1.05, 2.1, 4.2, "world", -0.44f, 2.77f));
    assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
    assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
    assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
    assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether", 0.23f, 4.88f));
    assertThat(userAuth.getLastLogin(), equalTo(1453242857L));
    assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 67 with PlayerAuth

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

the class PlayerAuthViewer method execute.

@Override
public void execute(CommandSender sender, List<String> arguments) {
    if (arguments.isEmpty()) {
        sender.sendMessage("Enter player name to view his data in the database.");
        sender.sendMessage("Example: /authme debug db Bobby");
        return;
    }
    PlayerAuth auth = dataSource.getAuth(arguments.get(0));
    if (auth == null) {
        sender.sendMessage("No record exists for '" + arguments.get(0) + "'");
    } else {
        displayAuthToSender(auth, sender);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 68 with PlayerAuth

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

the class FlatFile method updatePassword.

@Override
public // Note ljacqu 20151230: This does not persist the salt; it is not supported in flat file.
boolean updatePassword(String user, HashedPassword password) {
    user = user.toLowerCase();
    if (!isAuthAvailable(user)) {
        return false;
    }
    PlayerAuth newAuth = null;
    try (BufferedReader br = new BufferedReader(new FileReader(source))) {
        String line;
        while ((line = br.readLine()) != null) {
            String[] args = line.split(":");
            if (args[0].equals(user)) {
                newAuth = buildAuthFromArray(args);
                if (newAuth != null) {
                    newAuth.setPassword(password);
                }
                break;
            }
        }
    } catch (IOException ex) {
        ConsoleLogger.warning(ex.getMessage());
        return false;
    }
    if (newAuth != null) {
        removeAuth(user);
        saveAuth(newAuth);
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 69 with PlayerAuth

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

the class FlatFile method updateEmail.

@Override
public boolean updateEmail(PlayerAuth auth) {
    if (!isAuthAvailable(auth.getNickname())) {
        return false;
    }
    PlayerAuth newAuth = null;
    try (BufferedReader br = new BufferedReader(new FileReader(source))) {
        String line;
        while ((line = br.readLine()) != null) {
            String[] args = line.split(":");
            if (args[0].equals(auth.getNickname())) {
                newAuth = buildAuthFromArray(args);
                if (newAuth != null) {
                    newAuth.setEmail(auth.getEmail());
                }
                break;
            }
        }
    } catch (IOException ex) {
        ConsoleLogger.warning(ex.getMessage());
        return false;
    }
    if (newAuth != null) {
        removeAuth(auth.getNickname());
        saveAuth(newAuth);
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 70 with PlayerAuth

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

the class FlatFile method getAllAuths.

@Override
public List<PlayerAuth> getAllAuths() {
    List<PlayerAuth> auths = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader(source))) {
        String line;
        while ((line = br.readLine()) != null) {
            String[] args = line.split(":");
            PlayerAuth auth = buildAuthFromArray(args);
            if (auth != null) {
                auths.add(auth);
            }
        }
    } catch (IOException ex) {
        ConsoleLogger.logException("Error while getting auths from flatfile:", ex);
    }
    return auths;
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

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