Search in sources :

Example 1 with KeyOperation

use of org.apache.cxf.rs.security.jose.jwk.KeyOperation in project cxf by apache.

the class JwsCompactReaderWriterTest method testReadJwsWithJwkSignedByMac.

@Test
public void testReadJwsWithJwkSignedByMac() throws Exception {
    JwsJwtCompactConsumer jws = new JwsJwtCompactConsumer(ENCODED_TOKEN_WITH_JSON_KEY_SIGNED_BY_MAC);
    assertTrue(jws.verifySignatureWith(new HmacJwsSignatureVerifier(ENCODED_MAC_KEY, SignatureAlgorithm.HS256)));
    JwtToken token = jws.getJwtToken();
    JwsHeaders headers = new JwsHeaders(token.getJwsHeaders());
    assertEquals(JoseType.JWT, headers.getType());
    assertEquals(SignatureAlgorithm.HS256, headers.getSignatureAlgorithm());
    JsonWebKey key = headers.getJsonWebKey();
    assertEquals(KeyType.OCTET, key.getKeyType());
    List<KeyOperation> keyOps = key.getKeyOperation();
    assertEquals(2, keyOps.size());
    assertEquals(KeyOperation.SIGN, keyOps.get(0));
    assertEquals(KeyOperation.VERIFY, keyOps.get(1));
    validateSpecClaim(token.getClaims());
}
Also used : JwtToken(org.apache.cxf.rs.security.jose.jwt.JwtToken) KeyOperation(org.apache.cxf.rs.security.jose.jwk.KeyOperation) JsonWebKey(org.apache.cxf.rs.security.jose.jwk.JsonWebKey) Test(org.junit.Test)

Example 2 with KeyOperation

use of org.apache.cxf.rs.security.jose.jwk.KeyOperation in project cxf by apache.

the class JwsCompactReaderWriterTest method testWriteJwsWithJwkSignedByMac.

@Test
public void testWriteJwsWithJwkSignedByMac() throws Exception {
    JsonWebKey key = new JsonWebKey();
    key.setKeyType(KeyType.OCTET);
    key.setKeyOperation(Arrays.asList(new KeyOperation[] { KeyOperation.SIGN, KeyOperation.VERIFY }));
    doTestWriteJwsWithJwkSignedByMac(key);
}
Also used : KeyOperation(org.apache.cxf.rs.security.jose.jwk.KeyOperation) JsonWebKey(org.apache.cxf.rs.security.jose.jwk.JsonWebKey) Test(org.junit.Test)

Aggregations

JsonWebKey (org.apache.cxf.rs.security.jose.jwk.JsonWebKey)2 KeyOperation (org.apache.cxf.rs.security.jose.jwk.KeyOperation)2 Test (org.junit.Test)2 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)1