Search in sources :

Example 1 with JsonWebToken

use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.

the class JsonParserTest method testOtherClaims.

@Test
public void testOtherClaims() throws Exception {
    String json = "{ \"floatData\" : 555.5," + "\"boolData\": true, " + "\"intData\": 1234," + "\"array\": [ \"val\", \"val2\"] }";
    JsonWebToken token = JsonSerialization.readValue(json, JsonWebToken.class);
    System.out.println(token.getOtherClaims().get("floatData").getClass().getName());
    System.out.println(token.getOtherClaims().get("boolData").getClass().getName());
    System.out.println(token.getOtherClaims().get("intData").getClass().getName());
    System.out.println(token.getOtherClaims().get("array").getClass().getName());
}
Also used : JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.Test)

Example 2 with JsonWebToken

use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.

the class JsonWebTokenTest method isActiveReturnTrueWhenBeforeTimeInPast.

@Test
public void isActiveReturnTrueWhenBeforeTimeInPast() {
    int currentTime = Time.currentTime();
    int pastTime = currentTime - 10;
    JsonWebToken jsonWebToken = new JsonWebToken();
    jsonWebToken.notBefore(pastTime);
    assertTrue(jsonWebToken.isActive());
}
Also used : JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.Test)

Example 3 with JsonWebToken

use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.

the class JsonWebTokenTest method isActiveShouldReturnFalseWhenWhenBeforeTimeInFutureOutsideTimeSkew.

@Test
public void isActiveShouldReturnFalseWhenWhenBeforeTimeInFutureOutsideTimeSkew() {
    int notBeforeTime = Time.currentTime() + 10;
    int allowedClockSkew = 5;
    JsonWebToken jsonWebToken = new JsonWebToken();
    jsonWebToken.notBefore(notBeforeTime);
    assertFalse(jsonWebToken.isActive(allowedClockSkew));
}
Also used : JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.Test)

Example 4 with JsonWebToken

use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.

the class JsonWebTokenTest method testAudArray.

@Test
public void testAudArray() throws IOException {
    String single = "{ \"aud\": [\"test\"] }";
    JsonWebToken s = JsonSerialization.readValue(single, JsonWebToken.class);
    assertArrayEquals(new String[] { "test" }, s.getAudience());
}
Also used : JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.Test)

Example 5 with JsonWebToken

use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.

the class JsonWebTokenTest method isActiveReturnFalseWhenBeforeTimeInFuture.

@Test
public void isActiveReturnFalseWhenBeforeTimeInFuture() {
    int currentTime = Time.currentTime();
    int futureTime = currentTime + 10;
    JsonWebToken jsonWebToken = new JsonWebToken();
    jsonWebToken.notBefore(futureTime);
    assertFalse(jsonWebToken.isActive());
}
Also used : JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.Test)

Aggregations

JsonWebToken (org.keycloak.representations.JsonWebToken)36 Test (org.junit.Test)12 JWSInput (org.keycloak.jose.jws.JWSInput)7 JWSBuilder (org.keycloak.jose.jws.JWSBuilder)5 KeyPair (java.security.KeyPair)4 IdentityBrokerException (org.keycloak.broker.provider.IdentityBrokerException)4 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)4 OAuthClient (org.keycloak.testsuite.util.OAuthClient)4 PublicKey (java.security.PublicKey)3 OAuthErrorException (org.keycloak.OAuthErrorException)3 JWSInputException (org.keycloak.jose.jws.JWSInputException)3 IOException (java.io.IOException)2 PrivateKey (java.security.PrivateKey)2 LinkedList (java.util.LinkedList)2 Response (javax.ws.rs.core.Response)2 NameValuePair (org.apache.http.NameValuePair)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 ClientResource (org.keycloak.admin.client.resource.ClientResource)2 BrokeredIdentityContext (org.keycloak.broker.provider.BrokeredIdentityContext)2