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