Search in sources :

Example 6 with URIParcel

use of com.disney.uriparcel.URIParcel in project groovity by disney.

the class TestJsonParcels method testSerializedHttpCustomClass.

@Test
public void testSerializedHttpCustomClass() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    GarbageTruck gt = new GarbageTruck();
    gt.setCapacity(120);
    gt.setUsage(90);
    oos.writeObject(gt);
    oos.flush();
    byte[] content = baos.toByteArray();
    String lmod = wiremock.org.apache.http.client.utils.DateUtils.formatDate(new Date());
    stubFor(get(urlEqualTo("/sample.ser")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(content)));
    URIParcel<GarbageTruck> myDoc = new URIParcel<GarbageTruck>(GarbageTruck.class, new URI("http://localhost:28187/sample.ser"));
    GarbageTruck received = myDoc.call();
    Assert.assertEquals(gt.getCapacity(), received.getCapacity());
    Assert.assertEquals(gt.getUsage(), received.getUsage());
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 7 with URIParcel

use of com.disney.uriparcel.URIParcel in project groovity by disney.

the class TestJsonParcels method testJsonHttpCustomClass.

@Test
public void testJsonHttpCustomClass() throws Exception {
    Gson gson = new Gson();
    GarbageTruck gt = new GarbageTruck();
    gt.setCapacity(100);
    gt.setUsage(50);
    String doc = gson.toJson(gt);
    String lmod = wiremock.org.apache.http.client.utils.DateUtils.formatDate(new Date());
    stubFor(get(urlEqualTo("/sample.json")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(doc)));
    URIParcel<GarbageTruck> myDoc = new URIParcel<GarbageTruck>(GarbageTruck.class, new URI("http://localhost:28187/sample.json"));
    GarbageTruck received = myDoc.call();
    Assert.assertEquals(gt.getCapacity(), received.getCapacity());
    Assert.assertEquals(gt.getUsage(), received.getUsage());
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) Gson(com.google.gson.Gson) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 8 with URIParcel

use of com.disney.uriparcel.URIParcel in project groovity by disney.

the class TestKeys method testCertificate.

@Test
public void testCertificate() throws Exception {
    URI keyLoc = new URI("mem:myCertificate");
    KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
    generator.initialize(2048);
    KeyPair keyPair = generator.generateKeyPair();
    X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(new X500Name("CN=Some authority, OU=DATG, O=Disney, C=US"), new BigInteger(64, new SecureRandom()), // yesterday
    new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000), // 10 years
    new Date(System.currentTimeMillis() + 10 * 365 * 24 * 60 * 60 * 1000), new X500Name("DN=mySubject"), SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
    JcaContentSignerBuilder builder = new JcaContentSignerBuilder("SHA256withRSA");
    ContentSigner signer = builder.build(keyPair.getPrivate());
    byte[] certBytes = certBuilder.build(signer).getEncoded();
    Certificate cert = CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(certBytes));
    URIParcel<Certificate> certParcel = new URIParcel<Certificate>(Certificate.class, keyLoc);
    certParcel.put(cert);
    byte[] rawBytes = URIParcel.get(keyLoc, byte[].class);
    Assert.assertTrue("Expected X509 certificate", new String(rawBytes).startsWith("-----BEGIN CERTIFICATE-----"));
    Certificate rc = URIParcel.get(keyLoc, Certificate.class);
    Assert.assertEquals(keyPair.getPublic(), rc.getPublicKey());
}
Also used : KeyPair(java.security.KeyPair) URIParcel(com.disney.uriparcel.URIParcel) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) ContentSigner(org.bouncycastle.operator.ContentSigner) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator) X500Name(org.bouncycastle.asn1.x500.X500Name) URI(java.net.URI) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) X509v3CertificateBuilder(org.bouncycastle.cert.X509v3CertificateBuilder) BigInteger(java.math.BigInteger) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 9 with URIParcel

use of com.disney.uriparcel.URIParcel in project groovity by disney.

the class TestKeys method testPublicKey.

@Test
public void testPublicKey() throws Exception {
    URI keyLoc = new URI("mem:myPublicKey");
    KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
    generator.initialize(2048);
    KeyPair keyPair = generator.generateKeyPair();
    URIParcel<PublicKey> myParcel = new URIParcel<PublicKey>(PublicKey.class, keyLoc);
    myParcel.put(keyPair.getPublic());
    URIParcel<byte[]> rawParcel = new URIParcel<byte[]>(byte[].class, keyLoc);
    Assert.assertTrue("Expected PKCS8 public key file", new String(rawParcel.call()).startsWith("-----BEGIN PUBLIC KEY-----"));
    myParcel = new URIParcel<PublicKey>(PublicKey.class, keyLoc);
    PublicKey copy = myParcel.call();
    Assert.assertEquals(keyPair.getPublic(), copy);
}
Also used : KeyPair(java.security.KeyPair) URIParcel(com.disney.uriparcel.URIParcel) PublicKey(java.security.PublicKey) KeyPairGenerator(java.security.KeyPairGenerator) URI(java.net.URI) Test(org.junit.Test)

Example 10 with URIParcel

use of com.disney.uriparcel.URIParcel in project groovity by disney.

the class TestKeyStoreKeyLoader method setupKeyLoader.

private KeyChainKeyLoader setupKeyLoader(String keystorePassword) {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(KeyStoreValueHandler.KEYSTORE_PASSWORD, keystorePassword);
    config.put(KeyStoreValueHandler.KEYSTORE_TYPE, "JCEKS");
    URIParcel<KeyStore> parcel = new URIParcel<KeyStore>(KeyStore.class, new File("src/test/resources/testKey.store").toURI(), config);
    KeyChain chain = new KeyStoreKeyChainImpl(parcel, "".toCharArray());
    KeyChainKeyLoader loader = new KeyChainKeyLoader(chain);
    return loader;
}
Also used : KeyStoreKeyChainImpl(com.disney.http.auth.keychain.KeyStoreKeyChainImpl) HashMap(java.util.HashMap) URIParcel(com.disney.uriparcel.URIParcel) KeyChainKeyLoader(com.disney.http.auth.client.keyloader.KeyChainKeyLoader) KeyChain(com.disney.http.auth.keychain.KeyChain) KeyStore(java.security.KeyStore) File(java.io.File)

Aggregations

URIParcel (com.disney.uriparcel.URIParcel)24 URI (java.net.URI)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)11 File (java.io.File)8 KeyStore (java.security.KeyStore)8 KeyStoreKeyChainImpl (com.disney.http.auth.keychain.KeyStoreKeyChainImpl)7 KeyChainKeyLoader (com.disney.http.auth.client.keyloader.KeyChainKeyLoader)5 KeyPair (java.security.KeyPair)5 Date (java.util.Date)5 KeyChain (com.disney.http.auth.keychain.KeyChain)4 Key (java.security.Key)4 KeyPairGenerator (java.security.KeyPairGenerator)4 KeyObjectKeyLoader (com.disney.http.auth.client.keyloader.KeyObjectKeyLoader)3 HttpSignatureSigner (com.disney.http.auth.client.signer.HttpSignatureSigner)3 URL (java.net.URL)3 PublicKey (java.security.PublicKey)3 Map (java.util.Map)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 MemoryPayload (com.disney.uriparcel.MemoryPayload)2