Examples of JsonWebKey


Examples of org.apache.cxf.rs.security.oauth2.jwt.jwk.JsonWebKey

        Object jsonWebKey = getValue(JwtConstants.HEADER_JSON_WEB_KEY);
        if (jsonWebKey == null || jsonWebKey instanceof JsonWebKey) {
            return (JsonWebKey)jsonWebKey;
       
        Map<String, Object> map = CastUtils.cast((Map<?, ?>)jsonWebKey);
        return new JsonWebKey(map);
    }
View Full Code Here

Examples of org.apache.cxf.rs.security.oauth2.jwt.jwk.JsonWebKey

        validateSpecClaim(token.getClaims());
    }
   
    @Test
    public void testWriteJwsWithJwkSignedByMac() throws Exception {
        JsonWebKey key = new JsonWebKey();
        key.setKeyType(JsonWebKey.KEY_TYPE_OCTET);
        key.setKeyOperation(Arrays.asList(
            new String[]{JsonWebKey.KEY_OPER_SIGN, JsonWebKey.KEY_OPER_VERIFY}));
        doTestWriteJwsWithJwkSignedByMac(key);
    }
View Full Code Here

Examples of org.apache.cxf.rs.security.oauth2.jwt.jwk.JsonWebKey

        JwtToken token = jws.getJwtToken();
        JwtHeaders headers = token.getHeaders();
        assertEquals(JwtConstants.TYPE_JWT, headers.getType());
        assertEquals(Algorithm.HmacSHA256.getJwtName(), headers.getAlgorithm());
       
        JsonWebKey key = headers.getJsonWebKey();
        assertEquals(JsonWebKey.KEY_TYPE_OCTET, key.getKeyType());
        List<String> keyOps = key.getKeyOperation();
        assertEquals(2, keyOps.size());
        assertEquals(JsonWebKey.KEY_OPER_SIGN, keyOps.get(0));
        assertEquals(JsonWebKey.KEY_OPER_VERIFY, keyOps.get(1));
       
        validateSpecClaim(token.getClaims());
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

                "        adBJVoWZowDNTpKpk2RklZ7QaBO7XDv3uR7s_sf2g-bAjSYxYUGsqkNA9b3xV\n" +
                "        W53am_UZZ3tZbFTIh557JICWKHlWj5uzeJXaw\",\n" +
                "   \"e\":\"AQAB\"\n" +
                "  }";

        JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJson);

        JsonWebSignature jws = new JsonWebSignature();
        jws.setCompactSerialization(requestObject);
        jws.setKey(jwk.getKey());
        assertThat(jws.verifySignature(), is(true));
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

                "        8ojp5hkZQ39eCM2k1EdXdhbar998Q9PZTwXA1cfvuGTZbDWxEKLjMKVuKrT1Y\n" +
                "        vs-2NTXhZAW1KjFS_3UwLkDk-w4dVN-x5tDnw\",\n" +
                "   \"e\":\"AQAB\"\n" +
                "  }";

        JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJson);

        for (String idToken : new String[] {idTokenA2, idTokenA3, idTokenA4, idTokenA6})
        {
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(idToken);
            jws.setKey(jwk.getKey());
            assertThat(jws.verifySignature(), is(true));
        }
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

                "        RHE8JDb1Z4IGhEcEyzkxswVdPndUWzfvWBBWXWxtSUvQGBRkuy1BHOa4sP6F\n" +
                "        KjWEeeF7gm7UMs2Nm2QUgNZw6xvEDGaLk4KASdIxRQ\",\n" +
                "   \"e\":\"AQAB\"\n" +
                "  }";

        JsonWebKey jwk = JsonWebKey.Factory.newJwk(jwkJson);

        for (String idToken : new String[] {idTokenA2, idTokenA3, idTokenA4, idTokenA6})
        {
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(idToken);
            jws.setKey(jwk.getKey());
            assertThat(jws.verifySignature(), is(true));
        }
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

public class GetPayloadTest
{
    @Test
    public void testGetPayloadVerifiedAndUnverifiedAndSysPropOverride() throws JoseException
    {
        JsonWebKey jwk = JsonWebKey.Factory.newJwk("{\"kty\":\"oct\",\"k\":\"Y7T0ygpIvYvz9kSVRod2tcGhekjiQh4t_AF7GE-v0o8\"}");
        String cs = "eyJhbGciOiJIUzI1NiJ9." +
                "VUExNTgyIHRvIFNGTyBmb3IgYSBOQVBQUyBGMkYgd29ya3Nob3AgaW4gUGFsbyBBbHRv." +
                "YjnCNkxrv86F6GufxddTYS_4URo3kmLKrREquZSEKDo";

        String propertyName = "org.jose4j.jws.getPayload-skip-verify";
        try
        {
            System.setProperty(propertyName, "true");
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(cs);
            String payload = jws.getPayload();
            assertNotNull(payload);
        }
        finally
        {
            System.clearProperty(propertyName);
        }

        try
        {
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(cs);
            String payload = jws.getPayload();
            fail("getPayload should have failed with no key set but did return: " + payload);
        }
        catch (JoseException e)
        {
            // expected
        }

        try
        {
            System.setProperty(propertyName, "true");
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(cs);
            jws.setKey(new HmacKey(new byte[32]));
            String payload = jws.getPayload();
            assertNotNull(payload);
        }
        finally
        {
            System.clearProperty(propertyName);
        }

        try
        {
            JsonWebSignature jws = new JsonWebSignature();
            jws.setCompactSerialization(cs);
            jws.setKey(new HmacKey(new byte[32]));
            String payload = jws.getPayload();
            fail("getPayload should have failed with wrong key set but did return: " + payload);
        }
        catch (JoseException e)
        {
            // expected
        }

        JsonWebSignature jws = new JsonWebSignature();
        jws.setCompactSerialization(cs);
        String payload = jws.getUnverifiedPayload();
        assertNotNull(payload);
        jws.setKey(jwk.getKey());
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

                "           439X0M_V51gfpRLI9JYanrC4D4qAdGcopV_0ZHHzQlBjudU2QvXt4ehNYT\n" +
                "           CBr6XCLQUShb1juUO1ZdiYoFaFQT5Tw8bGUl_x_jTj3ccPDVZFD9pIuhLh\n" +
                "           BOneufuBiB4cS98l2SR_RQyGWSeWjnczT0QU91p1DhOVRuOopznQ\"\n" +
                "     }";
        Map<String, Object> parsed = JsonUtil.parseJson(jwkJson);
        JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(parsed);
        assertTrue(jsonWebKey.getKey().equals(ExampleRsaKeyFromJws.PUBLIC_KEY));
        String d = (String)parsed.get("d");
        Base64Url base64Url = new Base64Url();
        byte[] privateExp = base64Url.base64UrlDecode(d);
        assertTrue(Arrays.equals(ExampleRsaKeyFromJws.D_SIGNED_BYTES, privateExp));
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

    public void testVerifyExample() throws JoseException
    {
        JsonWebSignature jws = new JsonWebSignature();
        jws.setCompactSerialization(JWS);
        JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(JWK);
        jws.setKey(jsonWebKey.getKey());
        assertTrue("signature (HMAC) should validate", jws.verifySignature());
        assertEquals(PAYLOAD, jws.getPayload());
    }
View Full Code Here

Examples of org.jose4j.jwk.JsonWebKey

    public void testSignExample() throws JoseException
    {
        JsonWebSignature jws = new JsonWebSignature();
        jws.setPayload(PAYLOAD);

        JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(JWK);
        jws.setKey(jsonWebKey.getKey());
        jws.getHeaders().setFullHeaderAsJsonString("{\"typ\":\"JWT\",\r\n \"alg\":\"HS256\"}");

        String compactSerialization = jws.getCompactSerialization();

        assertEquals("example jws value doesn't match calculated compact serialization", JWS, compactSerialization);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.