Skip to content

Commit 0718879

Browse files
committed
Added pgpexamples
1 parent 2a55802 commit 0718879

File tree

11 files changed

+331
-0
lines changed

11 files changed

+331
-0
lines changed

pgpexamples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PGP Example
2+
===========
3+
4+
This project shows how to use the Mule PGP Module.
5+
6+
In this project I used Mule ESB CE 3.5.0
7+
(http://www.mulesoft.org/download-mule-esb-community-edition)
8+

pgpexamples/mule-project.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<mule-project xmlns="http://www.mulesoft.com/tooling/project" runtimeId="org.mule.tooling.server.3.5.CE">
3+
<name>PGP Example</name>
4+
<description>This project shows howto use the Mule PGP Module.</description>
5+
</mule-project>

pgpexamples/pom.xml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.ullgren.pontus.demo</groupId>
5+
<artifactId>pgpexample</artifactId>
6+
<version>1.0.0</version>
7+
<packaging>mule</packaging>
8+
<name>Mule ESB template</name>
9+
<description>
10+
This is a Mule ESB template project that can be used when you create a new project.
11+
It contains some sane default for dependencies for Mule ESB CE.
12+
</description>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16+
<mule.version>3.5.0</mule.version>
17+
<slf4j.version>1.6.1</slf4j.version>
18+
<eclipsePluginVersion>2.8</eclipsePluginVersion>
19+
<junit.version>4.9</junit.version>
20+
<mockobjects.version>0.09</mockobjects.version>
21+
<java.version>1.6</java.version>
22+
</properties>
23+
<repositories>
24+
<repository>
25+
<id>mulesoft-releases</id>
26+
<name>MuleSoft Repository</name>
27+
<url>https://repository-master.mulesoft.org/releases/</url>
28+
<layout>default</layout>
29+
</repository>
30+
<!--
31+
<repository>
32+
<id>mulesoft-snapshots</id>
33+
<name>MuleSoft Snapshot Repository</name>
34+
<url>https://repository-master.mulesoft.org/snapshots/</url>
35+
<layout>default</layout>
36+
</repository>
37+
-->
38+
</repositories>
39+
<dependencies>
40+
<!-- Mule Dependencies -->
41+
<dependency>
42+
<groupId>org.mule</groupId>
43+
<artifactId>mule-core</artifactId>
44+
<version>${mule.version}</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
<!-- Xml configuration -->
48+
<dependency>
49+
<groupId>org.mule.modules</groupId>
50+
<artifactId>mule-module-spring-config</artifactId>
51+
<version>${mule.version}</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
<!-- Mule Transports -->
55+
<dependency>
56+
<groupId>org.mule.transports</groupId>
57+
<artifactId>mule-transport-vm</artifactId>
58+
<version>${mule.version}</version>
59+
<scope>provided</scope>
60+
</dependency>
61+
<!-- Mule Modules -->
62+
<dependency>
63+
<groupId>org.mule.modules</groupId>
64+
<artifactId>mule-module-pgp</artifactId>
65+
<version>${mule.version}</version>
66+
<scope>provided</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.mule.modules</groupId>
70+
<artifactId>mule-module-client</artifactId>
71+
<version>${mule.version}</version>
72+
<scope>provided</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.mule.modules</groupId>
76+
<artifactId>mule-module-management</artifactId>
77+
<version>${mule.version}</version>
78+
<scope>provided</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.mule.modules</groupId>
82+
<artifactId>mule-module-scripting</artifactId>
83+
<version>${mule.version}</version>
84+
<scope>provided</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.mule.modules</groupId>
88+
<artifactId>mule-module-xml</artifactId>
89+
<version>${mule.version}</version>
90+
<scope>provided</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.mule.modules</groupId>
94+
<artifactId>mule-module-cxf</artifactId>
95+
<version>${mule.version}</version>
96+
<scope>provided</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.slf4j</groupId>
100+
<artifactId>slf4j-api</artifactId>
101+
<version>${slf4j.version}</version>
102+
<scope>provided</scope>
103+
</dependency>
104+
<!-- for testing -->
105+
<dependency>
106+
<groupId>org.mule.tests</groupId>
107+
<artifactId>mule-tests-functional</artifactId>
108+
<version>${mule.version}</version>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>mockobjects</groupId>
113+
<artifactId>mockobjects-core</artifactId>
114+
<version>${mockobjects.version}</version>
115+
<scope>test</scope>
116+
</dependency>
117+
<dependency>
118+
<groupId>junit</groupId>
119+
<artifactId>junit</artifactId>
120+
<version>${junit.version}</version>
121+
<scope>test</scope>
122+
</dependency>
123+
</dependencies>
124+
<build>
125+
<plugins>
126+
<plugin>
127+
<artifactId>maven-compiler-plugin</artifactId>
128+
<configuration>
129+
<source>${java.version}</source>
130+
<target>${java.version}</target>
131+
</configuration>
132+
</plugin>
133+
<plugin>
134+
<groupId>org.mule.tools</groupId>
135+
<artifactId>maven-mule-plugin</artifactId>
136+
<version>1.7</version>
137+
<extensions>true</extensions>
138+
</plugin>
139+
<plugin>
140+
<groupId>org.mule.tools</groupId>
141+
<artifactId>studio-maven-plugin</artifactId>
142+
<version>${mule.version}</version>
143+
</plugin>
144+
</plugins>
145+
</build>
146+
<!-- Added to get studio-maven-plugin to be able to use in mule studio -->
147+
<pluginRepositories>
148+
<pluginRepository>
149+
<id>mulesoft-release</id>
150+
<name>mulesoft release repository</name>
151+
<layout>default</layout>
152+
<url>http://repository.mulesoft.org/releases/</url>
153+
<snapshots>
154+
<enabled>false</enabled>
155+
</snapshots>
156+
</pluginRepository>
157+
</pluginRepositories>
158+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#** GENERATED CONTENT ** Mule Custom Properties file.
2+
#Wed Mar 27 21:58:15 CET 2013
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
4+
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
5+
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.4.0"
6+
xmlns:pgp="http://www.mulesoft.org/schema/mule/pgp"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
9+
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
10+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
11+
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
12+
http://www.mulesoft.org/schema/mule/pgp http://www.mulesoft.org/schema/mule/pgp/current/mule-pgp.xsd">
13+
14+
<spring:beans>
15+
<spring:bean id="pgpKeyManager" class="org.mule.module.pgp.PGPKeyRingImpl" init-method="initialise">
16+
<spring:property name="publicKeyRingFileName" value="pubring.gpg"/>
17+
<spring:property name="secretKeyRingFileName" value="secring.gpg"/>
18+
<spring:property name="secretAliasId" value="-3465398204868877747"/>
19+
<!-- <spring:property name="secretAliasId" value="7487042026319332280"/> -->
20+
<spring:property name="secretPassphrase" value="changeme"/>
21+
</spring:bean>
22+
<spring:bean id="pgpKeyManager2" class="org.mule.module.pgp.PGPKeyRingImpl" init-method="initialise">
23+
<spring:property name="publicKeyRingFileName" value="pubring.gpg"/>
24+
<spring:property name="secretKeyRingFileName" value="secring.gpg"/>
25+
<!-- <spring:property name="secretAliasId" value="-3465398204868877747"/> -->
26+
<spring:property name="secretAliasId" value="7487042026319332280"/>
27+
<spring:property name="secretPassphrase" value="changeme"/>
28+
</spring:bean>
29+
<spring:bean id="credentialAccessor" class="org.mule.security.MuleHeaderCredentialsAccessor"/>
30+
</spring:beans>
31+
32+
<pgp:security-manager>
33+
<pgp:security-provider name="pgpSecurityProvider" keyManager-ref="pgpKeyManager"/>
34+
<pgp:keybased-encryption-strategy
35+
name="keyBasedEncryptionStrategy"
36+
keyManager-ref="pgpKeyManager"
37+
credentialsAccessor-ref="credentialAccessor"/>
38+
</pgp:security-manager>
39+
40+
<!-- A simple Flows for examples -->
41+
42+
<flow name="EncryptPayload" doc:name="Encrypt message payload">
43+
<vm:inbound-endpoint exchange-pattern="request-response" path="Test1" doc:name="VM"/>
44+
<encrypt-transformer name="pgpEncrypt" strategy-ref="keyBasedEncryptionStrategy" />
45+
<logger message="Encrypted message payload is #[payload]. " doc:name="Log payload" level="INFO"/>
46+
</flow>
47+
48+
<flow name="DecryptPayload" doc:name="Decrypt message payload">
49+
<vm:inbound-endpoint exchange-pattern="request-response" path="Test2" doc:name="VM"/>
50+
<decrypt-transformer name="pgpDecrypt" strategy-ref="keyBasedEncryptionStrategy" />
51+
<logger message="Decrypted message payload is #[payload]. " doc:name="Log payload" level="INFO"/>
52+
</flow>
53+
54+
<flow name="ThereAndBackAgain" doc:name="Encrypt and then decrypt message payload">
55+
<vm:inbound-endpoint exchange-pattern="request-response" path="Test3" doc:name="VM"/>
56+
<encrypt-transformer name="pgpEncrypt2" strategy-ref="keyBasedEncryptionStrategy" />
57+
<decrypt-transformer name="pgpDecrypt2" strategy-ref="keyBasedEncryptionStrategy" />
58+
<logger message="Encrypted and decrypted message payload is #[payload]. " doc:name="Log payload" level="INFO"/>
59+
</flow>
60+
</mule>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#** GENERATED CONTENT ** Mule Application Deployment Descriptor
2+
#Wed Mar 27 21:58:15 CET 2013
3+
redeployment.enabled=true
4+
encoding=UTF-8
5+
config.resources=
6+
domain=default
1.22 KB
Binary file not shown.
2.57 KB
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.ullgren.pontus.demo;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.apache.axiom.attachments.utils.IOUtils;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
import org.mule.api.MuleMessage;
10+
import org.mule.module.client.MuleClient;
11+
import org.mule.tck.junit4.FunctionalTestCase;
12+
13+
public class SimpleIntegtationTest extends FunctionalTestCase {
14+
15+
@Override
16+
protected String getConfigResources() {
17+
return "src/main/app/mule-config.xml";
18+
}
19+
20+
@Test
21+
public void testEncryptPayload() throws Exception
22+
{
23+
MuleClient client = new MuleClient(muleContext);
24+
String payload = "Hello World!";
25+
// String expectedPayload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("encryptedmessage.asc"));
26+
27+
Map<String, Object> properties = new HashMap<String, Object>();
28+
properties.put("MULE_USER", "Test Testsson (This is just a test key please do not trust it.) <[email protected]>");
29+
MuleMessage result = client.send("vm://Test1", payload, properties);
30+
31+
Assert.assertTrue("Payload does not start with expected PGP header", result.getPayloadAsString().startsWith("-----BEGIN PGP MESSAGE-----"));
32+
// Uncomment to write the encrypted message to file so that we can validate it using "gpg -d < output.txt"
33+
// IOUtils.write(result.getPayloadAsString(), new FileOutputStream("output.txt"));
34+
}
35+
36+
// @Test
37+
public void testDecryptPayload() throws Exception
38+
{
39+
MuleClient client = new MuleClient(muleContext);
40+
String expectedPayload = "Hello World!";
41+
String payload = new String(IOUtils.getStreamAsByteArray(ClassLoader.getSystemResourceAsStream("encryptedmessage.asc")), "UTF-8");
42+
43+
Map<String, Object> properties = new HashMap<String, Object>();
44+
properties.put("MULE_USER", "Test Testsson (This is just a test key please do not trust it.) <[email protected]>");
45+
MuleMessage result = client.send("vm://Test2", payload, properties);
46+
Assert.assertEquals(expectedPayload, result.getPayloadAsString());
47+
}
48+
49+
// @Test
50+
public void testThereAndBackAgain() throws Exception
51+
{
52+
MuleClient client = new MuleClient(muleContext);
53+
String payload = "Hello World!";
54+
55+
Map<String, Object> properties = new HashMap<String, Object>();
56+
properties.put("MULE_USER", "Test Testsson (This is just a test key please do not trust it.) <[email protected]>");
57+
MuleMessage result = client.send("vm://Test3", payload, properties);
58+
59+
Assert.assertEquals(payload, result.getPayloadAsString());
60+
}
61+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN PGP MESSAGE-----
2+
Version: GnuPG v1.4.11 (GNU/Linux)
3+
4+
hQEMA2fnUQ4NL0O4AQf/fVXImrAnkx3qljIh+wz/Gf/SpGchaohVCWsdt3mI6rS3
5+
cHQ8igIImNFMlF3jqYTSvHMZTZfKsO+VRgSv7B6KLj/hFAhvE/64SfEFqAW+fdWy
6+
gIqUfv7/taiLy27gFS1j9gdspX8JhylnUOExUKtGvBWafuSlqeC7d5cE2dMgYwth
7+
kwOvgNfEtvWHybyRWTysrn9R7RDa+D9TwHUkwi8RMp26b9LIAYYcDrjPw3Ah/spP
8+
IhYq8vXfUu1ddWd13GqzqFmCawdHIj4NPbRSi3HNARzLM4YEXD9aiQ3bDGHtuWq4
9+
HkApts7g6X0clr+oM6M2wSYXgk50UL9BEJJCpKhW8tJIAfaJz3pDOiyXKJOpMBkk
10+
uVYHYQCkDmDZP4BeU4ddXnEDkEeTKjsCcfMVpe6t1hJp3YOrUlzlsIN7ySeKKvGy
11+
Qa7TkPtWKW2D
12+
=Xu1z
13+
-----END PGP MESSAGE-----

0 commit comments

Comments
 (0)