Search in sources :

Example 1 with AesWrapKeyEncryptionAlgorithm

use of org.apache.cxf.rs.security.jose.jwe.AesWrapKeyEncryptionAlgorithm in project cxf by apache.

the class JAXRSJweJwsTest method testJweAesCbcHmac.

@Test
public void testJweAesCbcHmac() throws Exception {
    String address = "https://localhost:" + PORT + "/jweaescbchmac";
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);
    bean.setServiceClass(BookStore.class);
    bean.setAddress(address);
    List<Object> providers = new LinkedList<Object>();
    // writer
    JweWriterInterceptor jweWriter = new JweWriterInterceptor();
    jweWriter.setUseJweOutputStream(true);
    final String cekEncryptionKey = "GawgguFyGrWKav7AX4VKUg";
    AesWrapKeyEncryptionAlgorithm keyEncryption = new AesWrapKeyEncryptionAlgorithm(cekEncryptionKey, KeyAlgorithm.A128KW);
    jweWriter.setEncryptionProvider(new AesCbcHmacJweEncryption(ContentAlgorithm.A128CBC_HS256, keyEncryption));
    // reader
    JweClientResponseFilter jweReader = new JweClientResponseFilter();
    jweReader.setDecryptionProvider(new AesCbcHmacJweDecryption(new AesWrapKeyDecryptionAlgorithm(cekEncryptionKey)));
    providers.add(jweWriter);
    providers.add(jweReader);
    bean.setProviders(providers);
    BookStore bs = bean.create(BookStore.class);
    String text = bs.echoText("book");
    assertEquals("book", text);
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.jose.BookStore) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JweWriterInterceptor(org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor) AesCbcHmacJweDecryption(org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweDecryption) AesWrapKeyEncryptionAlgorithm(org.apache.cxf.rs.security.jose.jwe.AesWrapKeyEncryptionAlgorithm) AesWrapKeyDecryptionAlgorithm(org.apache.cxf.rs.security.jose.jwe.AesWrapKeyDecryptionAlgorithm) URL(java.net.URL) LinkedList(java.util.LinkedList) AesCbcHmacJweEncryption(org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweEncryption) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JweClientResponseFilter(org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter) Test(org.junit.Test)

Aggregations

URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 JweClientResponseFilter (org.apache.cxf.rs.security.jose.jaxrs.JweClientResponseFilter)1 JweWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor)1 AesCbcHmacJweDecryption (org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweDecryption)1 AesCbcHmacJweEncryption (org.apache.cxf.rs.security.jose.jwe.AesCbcHmacJweEncryption)1 AesWrapKeyDecryptionAlgorithm (org.apache.cxf.rs.security.jose.jwe.AesWrapKeyDecryptionAlgorithm)1 AesWrapKeyEncryptionAlgorithm (org.apache.cxf.rs.security.jose.jwe.AesWrapKeyEncryptionAlgorithm)1 BookStore (org.apache.cxf.systest.jaxrs.security.jose.BookStore)1 Test (org.junit.Test)1