Search in sources :

Example 6 with MacSigner

use of org.springframework.security.jwt.crypto.sign.MacSigner in project faf-java-server by FAForever.

the class CustomIceServersProviderTest method getIceServerList.

@Test
@SuppressWarnings("unchecked")
public void getIceServerList() throws Exception {
    String claim = "{\"expiresAt\": \"ff\"}";
    when(objectMapper.writeValueAsString(any())).thenReturn(claim);
    properties.getIce().setServers(Arrays.asList(new Server().setUrl("http://localhost:1234"), new Server().setUrl("http://localhost:2345")));
    IceServerList result = instance.getIceServerList();
    ArgumentCaptor<Map<String, Object>> captor = ArgumentCaptor.forClass((Class) Map.class);
    verify(objectMapper, times(2)).writeValueAsString(captor.capture());
    Map<String, Object> map = captor.getValue();
    assertThat(map.get("expiresAt"), is(notNullValue()));
    List<IceServer> servers = result.getServers();
    assertThat(servers, hasSize(2));
    assertThat(servers.get(0).getUrl(), is(URI.create("http://localhost:1234")));
    assertThat(servers.get(0).getCredential(), is(notNullValue()));
    assertThat(servers.get(0).getUsername(), is(notNullValue()));
    assertThat(servers.get(1).getUrl(), is(URI.create("http://localhost:2345")));
    assertThat(servers.get(1).getCredential(), is(notNullValue()));
    assertThat(servers.get(1).getUsername(), is(notNullValue()));
    MacSigner macSigner = new MacSigner(properties.getJwt().getSecret());
    Jwt jwt = JwtHelper.decodeAndVerify(servers.get(0).getCredential(), macSigner);
    assertThat(jwt.getClaims(), is(claim));
}
Also used : MacSigner(org.springframework.security.jwt.crypto.sign.MacSigner) Server(com.faforever.server.config.ServerProperties.Ice.Server) Jwt(org.springframework.security.jwt.Jwt) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MacSigner (org.springframework.security.jwt.crypto.sign.MacSigner)6 IOException (java.io.IOException)2 Jwt (org.springframework.security.jwt.Jwt)2 RsaSigner (org.springframework.security.jwt.crypto.sign.RsaSigner)2 RsaVerifier (org.springframework.security.jwt.crypto.sign.RsaVerifier)2 SignatureVerifier (org.springframework.security.jwt.crypto.sign.SignatureVerifier)2 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)2 Server (com.faforever.server.config.ServerProperties.Ice.Server)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ValidationException (javax.validation.ValidationException)1 Test (org.junit.Test)1 InvalidSignatureException (org.springframework.security.jwt.crypto.sign.InvalidSignatureException)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1