Search in sources :

Example 11 with FafUserDetails

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

the class LegacyServicesActivators method loginRequest.

@ServiceActivator(inputChannel = ChannelNames.LEGACY_LOGIN_REQUEST)
@Transactional
public void loginRequest(LegacyLoginRequest loginRequest, @Header(CLIENT_CONNECTION) ClientConnection clientConnection) {
    // TODO this method shouldn't do anything but call a service
    Requests.verify(!playerService.isPlayerOnline(loginRequest.getLogin()), ErrorCode.USER_ALREADY_CONNECTED, loginRequest.getLogin());
    log.debug("Processing login request from user: {}", loginRequest.getLogin());
    try {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(loginRequest.getLogin(), loginRequest.getPassword());
        Authentication authentication = authenticationManager.authenticate(token);
        FafUserDetails userDetails = (FafUserDetails) authentication.getPrincipal();
        clientConnection.setAuthentication(authentication);
        Player player = userDetails.getPlayer();
        player.setClientConnection(clientConnection);
        geoIpService.lookupCountryCode(clientConnection.getClientAddress()).ifPresent(player::setCountry);
        uniqueIdService.verify(player, loginRequest.getUniqueId());
        chatService.updateIrcPassword(userDetails.getUsername(), loginRequest.getPassword());
        playerService.setPlayerOnline(player);
    } catch (BadCredentialsException e) {
        throw new RequestException(e, ErrorCode.INVALID_LOGIN);
    }
}
Also used : Player(com.faforever.server.entity.Player) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) FafUserDetails(com.faforever.server.security.FafUserDetails) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) RequestException(com.faforever.server.error.RequestException) ServiceActivator(org.springframework.integration.annotation.ServiceActivator) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with FafUserDetails

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

the class GameServiceTest method onAuthenticationSuccess.

@Test
@SuppressWarnings("unchecked")
public void onAuthenticationSuccess() throws Exception {
    player1.setCurrentGame(null);
    instance.createGame("Test game", FAF_TECHNICAL_NAME, MAP_NAME, null, GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1);
    TestingAuthenticationToken authentication = new TestingAuthenticationToken("JUnit", "foo");
    authentication.setDetails(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null));
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player2));
    ArgumentCaptor<GameResponses> captor = ArgumentCaptor.forClass((Class) Collection.class);
    verify(clientService).sendGameList(captor.capture(), eq(player2));
    GameResponses games = captor.getValue();
    assertThat(games.getResponses(), hasSize(1));
    assertThat(games.getResponses().iterator().next().getTitle(), is("Test game"));
}
Also used : User(com.faforever.server.entity.User) Collection(java.util.Collection) FafUserDetails(com.faforever.server.security.FafUserDetails) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) GameResponses(com.faforever.server.client.GameResponses) Test(org.junit.Test)

Example 13 with FafUserDetails

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

the class IceServiceActivatorsTest method setUp.

@Before
public void setUp() throws Exception {
    player = new Player();
    player.setClientConnection(clientConnection);
    clientConnection = new ClientConnection("1", Protocol.V1_LEGACY_UTF_16, mock(InetAddress.class)).setAuthentication(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player).setPassword("pw").setLogin("JUnit")), null));
    instance = new IceServiceActivators(iceService);
}
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) InetAddress(java.net.InetAddress) Before(org.junit.Before)

Example 14 with FafUserDetails

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

the class MatchMakerServiceActivatorTest 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 MatchMakerServiceActivator(matchmakerService, matchMakerMapper);
}
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 15 with FafUserDetails

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

the class SocialServiceTest method onAuthenticationSuccess.

@Test
public void onAuthenticationSuccess() throws Exception {
    User user = (User) new User().setPlayer(new Player().setSocialRelations(Arrays.asList(new SocialRelation(1, null, 10, SocialRelationStatus.FRIEND), new SocialRelation(2, null, 11, SocialRelationStatus.FOE)))).setPassword("pw").setLogin("junit");
    FafUserDetails userDetails = new FafUserDetails(user);
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, userDetails.getPlayer()));
    ArgumentCaptor<SocialRelationListResponse> captor = ArgumentCaptor.forClass(SocialRelationListResponse.class);
    verify(clientService).sendSocialRelations(captor.capture(), any());
    SocialRelationListResponse response = captor.getValue();
    assertThat(response, instanceOf(SocialRelationListResponse.class));
    assertThat(response.getSocialRelations(), hasSize(2));
    assertThat(response.getSocialRelations().get(0), is(new SocialRelationResponse(10, RelationType.FRIEND)));
    assertThat(response.getSocialRelations().get(1), is(new SocialRelationResponse(11, RelationType.FOE)));
}
Also used : SocialRelation(com.faforever.server.entity.SocialRelation) Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) FafUserDetails(com.faforever.server.security.FafUserDetails) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) SocialRelationResponse(com.faforever.server.social.SocialRelationListResponse.SocialRelationResponse) Test(org.junit.Test)

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