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));
}
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()))));
}
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");
}
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);
};
}
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;
}
Aggregations