Search in sources :

Example 1 with JWSBuilder

use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.

the class RSAVerifierTest method testExpirationBad.

@Test
public void testExpirationBad() {
    token.expiration(Time.currentTime() - 100);
    String encoded = new JWSBuilder().jsonContent(token).rsa256(idpPair.getPrivate());
    AccessToken v = null;
    try {
        v = verifySkeletonKeyToken(encoded);
        Assert.fail();
    } catch (VerificationException ignored) {
    }
}
Also used : AccessToken(org.keycloak.representations.AccessToken) VerificationException(org.keycloak.common.VerificationException) JWSBuilder(org.keycloak.jose.jws.JWSBuilder) Test(org.junit.Test)

Example 2 with JWSBuilder

use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.

the class RSAVerifierTest method testNotBeforeBad.

@Test
public void testNotBeforeBad() {
    token.notBefore(Time.currentTime() + 100);
    String encoded = new JWSBuilder().jsonContent(token).rsa256(idpPair.getPrivate());
    AccessToken v = null;
    try {
        v = verifySkeletonKeyToken(encoded);
        Assert.fail();
    } catch (VerificationException ignored) {
        System.out.println(ignored.getMessage());
    }
}
Also used : AccessToken(org.keycloak.representations.AccessToken) VerificationException(org.keycloak.common.VerificationException) JWSBuilder(org.keycloak.jose.jws.JWSBuilder) Test(org.junit.Test)

Example 3 with JWSBuilder

use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.

the class RSAVerifierTest method testExpirationGood.

@Test
public void testExpirationGood() throws Exception {
    token.expiration(Time.currentTime() + 100);
    String encoded = new JWSBuilder().jsonContent(token).rsa256(idpPair.getPrivate());
    AccessToken v = null;
    try {
        v = verifySkeletonKeyToken(encoded);
    } catch (VerificationException ignored) {
        throw ignored;
    }
}
Also used : AccessToken(org.keycloak.representations.AccessToken) VerificationException(org.keycloak.common.VerificationException) JWSBuilder(org.keycloak.jose.jws.JWSBuilder) Test(org.junit.Test)

Example 4 with JWSBuilder

use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.

the class RSAVerifierTest method testTokenAuth.

@Test
public void testTokenAuth() {
    token = new AccessToken();
    token.subject("CN=Client").issuer("http://localhost:8080/auth/realms/demo").addAccess("service").addRole("admin").verifyCaller(true);
    token.setEmail("bill@jboss.org");
    String encoded = new JWSBuilder().jsonContent(token).rsa256(idpPair.getPrivate());
    System.out.println("token size: " + encoded.length());
    AccessToken v = null;
    try {
        v = verifySkeletonKeyToken(encoded);
        Assert.fail();
    } catch (VerificationException ignored) {
    }
}
Also used : AccessToken(org.keycloak.representations.AccessToken) VerificationException(org.keycloak.common.VerificationException) JWSBuilder(org.keycloak.jose.jws.JWSBuilder) Test(org.junit.Test)

Example 5 with JWSBuilder

use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.

the class RSAVerifierTest method testSimpleVerification.

@Test
public void testSimpleVerification() throws Exception {
    String encoded = new JWSBuilder().jsonContent(token).rsa256(idpPair.getPrivate());
    System.out.print("encoded size: " + encoded.length());
    AccessToken token = verifySkeletonKeyToken(encoded);
    Assert.assertTrue(token.getResourceAccess("service").getRoles().contains("admin"));
    Assert.assertEquals("CN=Client", token.getSubject());
}
Also used : AccessToken(org.keycloak.representations.AccessToken) JWSBuilder(org.keycloak.jose.jws.JWSBuilder) Test(org.junit.Test)

Aggregations

JWSBuilder (org.keycloak.jose.jws.JWSBuilder)27 Test (org.junit.Test)15 AccessToken (org.keycloak.representations.AccessToken)11 VerificationException (org.keycloak.common.VerificationException)8 SignatureSignerContext (org.keycloak.crypto.SignatureSignerContext)6 KeyPair (java.security.KeyPair)5 RealmModel (org.keycloak.models.RealmModel)4 JsonWebToken (org.keycloak.representations.JsonWebToken)4 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)4 SecretKey (javax.crypto.SecretKey)3 Response (javax.ws.rs.core.Response)3 JWSInput (org.keycloak.jose.jws.JWSInput)3 AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)3 KeyManager (org.keycloak.models.KeyManager)3 KeycloakSession (org.keycloak.models.KeycloakSession)3 UserSessionModel (org.keycloak.models.UserSessionModel)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ObjectInputStream (java.io.ObjectInputStream)2