Search in sources :

Example 1 with GroupAssociation

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

the class FafUserDetailsTest method userWithGroup1IsAdmin.

@Test
public void userWithGroup1IsAdmin() throws Exception {
    User user = (User) new User().setGroupAssociation(new GroupAssociation().setGroup(Group.ADMIN)).setPassword(TEST_PASSWORD).setLogin(TEST_USERNAME);
    FafUserDetails fafUserDetails = new FafUserDetails(user);
    assertThat(fafUserDetails.getAuthorities(), CoreMatchers.hasItems(new SimpleGrantedAuthority("ROLE_USER"), new SimpleGrantedAuthority("ROLE_ADMIN")));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Test(org.junit.Test)

Example 2 with GroupAssociation

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

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

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

the class ChatServiceTest method testJoinChannels.

@SuppressWarnings("unchecked")
private void testJoinChannels(Group group, String... expectedChannels) {
    User user = (User) new User().setPassword("pw").setGroupAssociation(group == null ? null : new GroupAssociation().setGroup(group)).setLogin("junit");
    Player player = new Player().setUser(user).setClanMemberships(Collections.singletonList(new ClanMembership().setClan(new Clan().setTag("junit"))));
    instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player));
    ArgumentCaptor<Set<String>> captor = ArgumentCaptor.forClass((Class) Set.class);
    verify(clientService).sendChatChannels(captor.capture(), any());
    Set<String> channels = captor.getValue();
    assertThat(channels, containsInAnyOrder(expectedChannels));
}
Also used : Player(com.faforever.server.entity.Player) User(com.faforever.server.entity.User) GroupAssociation(com.faforever.server.entity.GroupAssociation) Set(java.util.Set) Clan(com.faforever.server.entity.Clan) ClanMembership(com.faforever.server.entity.ClanMembership) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent)

Aggregations

GroupAssociation (com.faforever.server.entity.GroupAssociation)4 User (com.faforever.server.entity.User)4 PlayerOnlineEvent (com.faforever.server.player.PlayerOnlineEvent)2 Set (java.util.Set)2 Test (org.junit.Test)2 ClientService (com.faforever.server.client.ClientService)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 Player (com.faforever.server.entity.Player)1 ProgrammingError (com.faforever.server.error.ProgrammingError)1 Hashing (com.google.common.hash.Hashing)1 StandardCharsets (java.nio.charset.StandardCharsets)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EventListener (org.springframework.context.event.EventListener)1 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1