Search in sources :

Example 6 with FafUserDetails

use of com.faforever.server.security.FafUserDetails in project faf-java-server by FAForever.

the class GameServiceTest method restoreGameSessionOpenGame.

@Test
public void restoreGameSessionOpenGame() throws Exception {
    Game game = hostGame(player1);
    assertThat(player2.getCurrentGame(), is(nullValue()));
    instance.joinGame(game.getId(), game.getPassword(), player2);
    assertThat(player2.getCurrentGame(), is(game));
    assertThat(player2.getGameState(), is(PlayerGameState.INITIALIZING));
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player2);
    assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
    ClientConnection clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
    player2.setClientConnection(clientConnection);
    instance.removePlayer(player2);
    assertThat(player2.getCurrentGame(), is(nullValue()));
    assertThat(player2.getGameState(), is(PlayerGameState.NONE));
    instance.restoreGameSession(player2, game.getId());
    assertThat(player2.getCurrentGame(), is(game));
    assertThat(player2.getGameState(), is(PlayerGameState.LOBBY));
}
Also used : Game(com.faforever.server.entity.Game) User(com.faforever.server.entity.User) ClientConnection(com.faforever.server.client.ClientConnection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 7 with FafUserDetails

use of com.faforever.server.security.FafUserDetails in project faf-java-server by FAForever.

the class GameServiceTest method restoreGameSessionPlayingGame.

@Test
public void restoreGameSessionPlayingGame() throws Exception {
    Game game = hostGame(player1);
    instance.joinGame(game.getId(), game.getPassword(), player2);
    assertThat(player2.getCurrentGame(), is(game));
    instance.updatePlayerGameState(PlayerGameState.LOBBY, player2);
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player2);
    assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
    instance.updatePlayerGameState(PlayerGameState.LAUNCHING, player1);
    ClientConnection clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
    player2.setClientConnection(clientConnection);
    instance.removePlayer(player2);
    assertThat(player2.getCurrentGame(), is(nullValue()));
    assertThat(player2.getGameState(), is(PlayerGameState.NONE));
    instance.restoreGameSession(player2, game.getId());
    assertThat(player2.getCurrentGame(), is(game));
    assertThat(player2.getGameState(), is(PlayerGameState.LAUNCHING));
}
Also used : Game(com.faforever.server.entity.Game) User(com.faforever.server.entity.User) ClientConnection(com.faforever.server.client.ClientConnection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 8 with FafUserDetails

use of com.faforever.server.security.FafUserDetails in project faf-java-server by FAForever.

the class LegacyServicesActivatorsTest method createAuthentication.

private void createAuthentication(Player player) {
    FafUserDetails fafUserDetails = new FafUserDetails((User) new User().setPlayer(player).setPassword("password").setLogin("JUnit"));
    TestingAuthenticationToken token = new TestingAuthenticationToken(fafUserDetails, "password");
    when(authenticationManager.authenticate(any())).thenReturn(token);
}
Also used : User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 9 with FafUserDetails

use of com.faforever.server.security.FafUserDetails in project faf-java-server by FAForever.

the class AvatarServiceActivatorTest method setUp.

@Before
public void setUp() throws Exception {
    player = new Player();
    authentication = new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player).setPassword("pw").setLogin("JUnit")), null);
    instance = new AvatarServiceActivator(avatarService);
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 10 with FafUserDetails

use of com.faforever.server.security.FafUserDetails in project faf-java-server by FAForever.

the class GameServiceActivatorsTest method setUp.

@Before
public void setUp() throws Exception {
    clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class));
    player = new Player();
    User user = (User) new User().setPlayer(player).setPassword("password").setLogin("JUnit");
    clientConnection.setAuthentication(new TestingAuthenticationToken(new FafUserDetails(user), null));
    instance = new GameServiceActivators(gameService);
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) ClientConnection(com.faforever.server.client.ClientConnection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Aggregations

FafUserDetails (com.faforever.server.security.FafUserDetails)15 User (com.faforever.server.entity.User)12 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)9 Player (com.faforever.server.entity.Player)8 Test (org.junit.Test)7 ClientConnection (com.faforever.server.client.ClientConnection)6 Before (org.junit.Before)5 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)3 InetAddress (java.net.InetAddress)3 Game (com.faforever.server.entity.Game)2 GameResponses (com.faforever.server.client.GameResponses)1 SocialRelation (com.faforever.server.entity.SocialRelation)1 RequestException (com.faforever.server.error.RequestException)1 SocialRelationResponse (com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse)1 Collection (java.util.Collection)1 ServiceActivator (org.springframework.integration.annotation.ServiceActivator)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 Transactional (org.springframework.transaction.annotation.Transactional)1