Search in sources :

Example 11 with User

use of com.faforever.server.entity.User 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)

Example 12 with User

use of com.faforever.server.entity.User in project faf-java-server by FAForever.

the class ChatService method onPlayerOnlineEvent.

@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
    Chat chat = properties.getChat();
    Set<String> channels = new HashSet<>(3, 1);
    channels.addAll(chat.getDefaultChannels());
    Optional.ofNullable(event.getPlayer().getClan()).map(clan -> (String.format(chat.getClanChannelFormat(), clan.getTag()))).ifPresent(channels::add);
    User user = event.getPlayer().getUser();
    GroupAssociation groupAssociation = user.getGroupAssociation();
    if (groupAssociation != null) {
        switch(groupAssociation.getGroup()) {
            case ADMIN:
                channels.addAll(chat.getAdminChannels());
                break;
            case MODERATOR:
                channels.addAll(chat.getModeratorChannels());
                break;
            default:
                throw new ProgrammingError("Uncovered group: " + groupAssociation.getGroup());
        }
    }
    clientService.sendChatChannels(channels, event.getPlayer());
}
Also used : Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) User(com.faforever.server.entity.User) EventListener(org.springframework.context.event.EventListener) Set(java.util.Set) Hashing(com.google.common.hash.Hashing) GroupAssociation(com.faforever.server.entity.GroupAssociation) BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) StandardCharsets(java.nio.charset.StandardCharsets) HashSet(java.util.HashSet) Slf4j(lombok.extern.slf4j.Slf4j) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) Optional(java.util.Optional) ClientService(com.faforever.server.client.ClientService) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Chat(com.faforever.server.config.ServerProperties.Chat) ProgrammingError(com.faforever.server.error.ProgrammingError) HashSet(java.util.HashSet) EventListener(org.springframework.context.event.EventListener)

Example 13 with User

use of com.faforever.server.entity.User in project faf-java-server by FAForever.

the class FafUserDetailsTest method userWithoutGroup1IsNotAdmin.

@Test
public void userWithoutGroup1IsNotAdmin() throws Exception {
    User user = (User) new User().setGroupAssociation(new GroupAssociation().setGroup(Group.MODERATOR)).setPassword(TEST_PASSWORD).setLogin(TEST_USERNAME);
    FafUserDetails fafUserDetails = new FafUserDetails(user);
    assertThat(fafUserDetails.getAuthorities(), hasSize(1));
    assertThat(fafUserDetails.getAuthorities().iterator().next().getAuthority(), is("ROLE_USER"));
}
Also used : User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Test(org.junit.Test)

Example 14 with User

use of com.faforever.server.entity.User 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 15 with User

use of com.faforever.server.entity.User 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)

Aggregations

User (com.faforever.server.entity.User)21 FafUserDetails (com.faforever.server.security.FafUserDetails)12 Test (org.junit.Test)12 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)10 Player (com.faforever.server.entity.Player)9 ClientConnection (com.faforever.server.client.ClientConnection)6 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)5 Before (org.junit.Before)5 GroupAssociation (com.faforever.server.entity.GroupAssociation)4 InetAddress (java.net.InetAddress)4 BanDetails (com.faforever.server.entity.BanDetails)2 Game (com.faforever.server.entity.Game)2 Set (java.util.Set)2 ClientService (com.faforever.server.client.ClientService)1 GameResponses (com.faforever.server.client.GameResponses)1 ServerProperties (com.faforever.server.config.ServerProperties)1 Chat (com.faforever.server.config.ServerProperties.Chat)1 Clan (com.faforever.server.entity.Clan)1 ClanMembership (com.faforever.server.entity.ClanMembership)1 SocialRelation (com.faforever.server.entity.SocialRelation)1