Search in sources :

Example 1 with HashedPassword

use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() {
    final Map<String, String> response = new HashMap<>();
    response.put(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString());
    assertNull(generateChallenge(null).apply(challenge -> response));
    // create a user, verify we can't login with a username that already exists
    // we should not be able to login now
    assertNotNull(generateChallenge(new HashedPassword(md5Crypt("foo"))).apply(challenge -> response));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) HashMap(java.util.HashMap) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Test(org.junit.jupiter.api.Test)

Example 2 with HashedPassword

use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method testAnonymousLoginBadName.

@Test
public void testAnonymousLoginBadName() {
    final String name = "bitCh" + Util.createUniqueTimeStamp();
    try {
        new BadWordController().addBadWord("bitCh");
    } catch (final Exception ignore) {
    // this is probably a duplicate insertion error, we can ignore that as it only means we already added the bad
    // word previously
    }
    assertEquals(LobbyLoginValidator.ErrorMessages.THATS_NOT_A_NICE_NAME, generateChallenge(name, new HashedPassword(md5Crypt("foo"))).apply(challenge -> new HashMap<>(Collections.singletonMap(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString()))));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) HashMap(java.util.HashMap) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Test(org.junit.jupiter.api.Test)

Example 3 with HashedPassword

use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method testLogin.

@Test
public void testLogin() {
    final String user = Util.createUniqueTimeStamp();
    final String password = "foo";
    final Map<String, String> response = new HashMap<>();
    assertNull(generateChallenge(user, new HashedPassword(BCrypt.hashpw(hashPasswordWithSalt(password), BCrypt.gensalt()))).apply(challenge -> {
        response.putAll(RsaAuthenticator.newResponse(challenge, password));
        return response;
    }));
    // with a bad password
    assertError(generateChallenge(user, null).apply(challenge -> new HashMap<>(RsaAuthenticator.newResponse(challenge, "wrong"))), "password");
    // with a non existent user
    assertError(generateChallenge(null).apply(challenge -> response), "user");
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) HashMap(java.util.HashMap) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Test(org.junit.jupiter.api.Test)

Example 4 with HashedPassword

use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.

the class LobbyLoginValidatorIntegrationTest method generateChallenge.

private ChallengeResultFunction generateChallenge(final String name, final HashedPassword password) {
    final SocketAddress address = new InetSocketAddress(5000);
    final String mac = MacFinder.getHashedMacAddress();
    final String email = "none@none.none";
    if (password != null) {
        createUser(name, email, password);
    }
    final Map<String, String> challenge = loginValidator.getChallengeProperties(name, address);
    return responseGetter -> {
        final Map<String, String> response = responseGetter.apply(challenge);
        response.putIfAbsent(LobbyLoginValidator.EMAIL_KEY, email);
        response.putIfAbsent(LobbyLoginValidator.LOBBY_VERSION, LobbyServer.LOBBY_VERSION.toString());
        return loginValidator.verifyConnection(challenge, response, name, mac, address);
    };
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) SocketAddress(java.net.SocketAddress) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Integration(games.strategy.test.Integration) HashMap(java.util.HashMap) Function(java.util.function.Function) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Matchers.containsStringIgnoringCase(org.hamcrest.Matchers.containsStringIgnoringCase) Map(java.util.Map) RsaAuthenticator.hashPasswordWithSalt(games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BCrypt(org.mindrot.jbcrypt.BCrypt) Nullable(javax.annotation.Nullable) UserController(games.strategy.engine.lobby.server.db.UserController) ILoginValidator(games.strategy.net.ILoginValidator) InetSocketAddress(java.net.InetSocketAddress) Util(games.strategy.util.Util) Test(org.junit.jupiter.api.Test) Md5Crypt(games.strategy.util.Md5Crypt) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BadWordController(games.strategy.engine.lobby.server.db.BadWordController) Collections(java.util.Collections) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with HashedPassword

use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.

the class UserManager method updateUser.

@Override
public String updateUser(final String userName, final String emailAddress, final String hashedPassword) {
    final INode remote = MessageContext.getSender();
    if (!userName.equals(remote.getName())) {
        logger.severe("Tried to update user permission, but not correct user, userName:" + userName + " node:" + remote);
        return "Sorry, but I can't let you do that";
    }
    final DBUser user = new DBUser(new DBUser.UserName(userName), new DBUser.UserEmail(emailAddress));
    if (!user.isValid()) {
        return user.getValidationErrorMessage();
    }
    final HashedPassword password = new HashedPassword(hashedPassword);
    try {
        new UserController().updateUser(user, password.isHashedWithSalt() ? password : new HashedPassword(BCrypt.hashpw(hashedPassword, BCrypt.gensalt())));
    } catch (final IllegalStateException e) {
        return e.getMessage();
    }
    return null;
}
Also used : INode(games.strategy.net.INode) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) UserController(games.strategy.engine.lobby.server.db.UserController) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword)

Aggregations

HashedPassword (games.strategy.engine.lobby.server.db.HashedPassword)8 DBUser (games.strategy.engine.lobby.server.userDB.DBUser)7 UserController (games.strategy.engine.lobby.server.db.UserController)6 Nullable (javax.annotation.Nullable)6 LobbyServer (games.strategy.engine.lobby.server.LobbyServer)4 BadWordController (games.strategy.engine.lobby.server.db.BadWordController)4 RsaAuthenticator.hashPasswordWithSalt (games.strategy.engine.lobby.server.login.RsaAuthenticator.hashPasswordWithSalt)4 ILoginValidator (games.strategy.net.ILoginValidator)4 MacFinder (games.strategy.net.MacFinder)4 Integration (games.strategy.test.Integration)4 Md5Crypt (games.strategy.util.Md5Crypt)4 Util (games.strategy.util.Util)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketAddress (java.net.SocketAddress)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Function (java.util.function.Function)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4