Java Code Examples for org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm#HS256

The following examples show how to use org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm#HS256 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuthUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static SignatureAlgorithm getClientSecretSignatureAlgorithm(Properties sigProps) {

        String clientSecretSigProp = sigProps.getProperty(OAuthConstants.CLIENT_SECRET_SIGNATURE_ALGORITHM);
        if (clientSecretSigProp == null) {
            String sigProp = sigProps.getProperty(JoseConstants.RSSEC_SIGNATURE_ALGORITHM);
            if (AlgorithmUtils.isHmacSign(sigProp)) {
                clientSecretSigProp = sigProp;
            }
        }
        SignatureAlgorithm sigAlgo = SignatureAlgorithm.getAlgorithm(clientSecretSigProp);
        sigAlgo = sigAlgo != null ? sigAlgo : SignatureAlgorithm.HS256;
        if (!AlgorithmUtils.isHmacSign(sigAlgo)) {
            // Must be HS-based for the symmetric signature
            throw new OAuthServiceException(OAuthConstants.SERVER_ERROR);
        }
        return sigAlgo;
    }
 
Example 2
Source File: JAXRSJweJwsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJweRsaJwsPlainTextHMac() throws Exception {
    String address = "https://localhost:" + PORT + "/jwejwshmac";
    HmacJwsSignatureProvider hmacProvider =
        new HmacJwsSignatureProvider(ENCODED_MAC_KEY, SignatureAlgorithm.HS256);
    BookStore bs = createJweJwsBookStore(address, hmacProvider, null);
    String text = bs.echoText("book");
    assertEquals("book", text);
}
 
Example 3
Source File: JAXRSJweJwsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJweRsaJwsBookHMac() throws Exception {
    String address = "https://localhost:" + PORT + "/jwejwshmac";
    HmacJwsSignatureProvider hmacProvider =
        new HmacJwsSignatureProvider(ENCODED_MAC_KEY, SignatureAlgorithm.HS256);
    BookStore bs = createJweJwsBookStore(address, hmacProvider,
                                         Collections.singletonList(new JacksonJsonProvider()));
    Book book = bs.echoBook(new Book("book", 123L));
    assertEquals("book", book.getName());
    assertEquals(123L, book.getId());
}
 
Example 4
Source File: JwsUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static SignatureAlgorithm getDefaultKeyAlgorithm(JsonWebKey jwk) {
    KeyType keyType = jwk.getKeyType();
    if (KeyType.OCTET == keyType) {
        return SignatureAlgorithm.HS256;
    } else if (KeyType.EC == keyType) {
        return SignatureAlgorithm.ES256;
    } else {
        return SignatureAlgorithm.RS256;
    }
}
 
Example 5
Source File: JwsCompactReaderWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadJwsUnencodedPayload() throws Exception {
    JwsHeaders headers = new JwsHeaders(SignatureAlgorithm.HS256);
    headers.setPayloadEncodingStatus(false);
    JwsCompactProducer producer = new JwsCompactProducer(headers,
                                                         UNSIGNED_PLAIN_DOCUMENT,
                                                         true);
    producer.signWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY, SignatureAlgorithm.HS256));
    assertEquals(TOKEN_WITH_DETACHED_UNENCODED_PAYLOAD, producer.getSignedEncodedJws());
    JwsCompactConsumer consumer =
        new JwsCompactConsumer(TOKEN_WITH_DETACHED_UNENCODED_PAYLOAD, UNSIGNED_PLAIN_DOCUMENT);

    assertTrue(consumer.verifySignatureWith(
        new HmacJwsSignatureVerifier(ENCODED_MAC_KEY, SignatureAlgorithm.HS256)));
}
 
Example 6
Source File: HmacJwsSignatureVerifier.java    From cxf with Apache License 2.0 4 votes vote down vote up
public HmacJwsSignatureVerifier(String encodedKey) {
    this(JoseUtils.decode(encodedKey), SignatureAlgorithm.HS256);
}