Skip to content

Commit ae4346d

Browse files
Automatically create Keystore with Maven
Let Maven automatically create a keystore if missing. Credentials and dname can be configured in the pom.xml. Use the Maven properties for application.yml.
1 parent 9a82378 commit ae4346d

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

sample-spring-boot/pom.xml

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>com.sap.hcp.cf.logging</groupId>
1111
<artifactId>cf-java-logging-support-parent</artifactId>
12-
<version>3.2.1</version>
12+
<version>3.3.0</version>
1313
<relativePath>../pom.xml</relativePath>
1414
</parent>
1515

@@ -19,6 +19,15 @@
1919
<maven.compiler.source>11</maven.compiler.source>
2020
<maven.compiler.target>11</maven.compiler.target>
2121
<spring.boot.version>2.3.4.RELEASE</spring.boot.version>
22+
<keytool.plugin.version>1.5</keytool.plugin.version>
23+
<keystore.token.store_password>0bzhBRNUXBR5
24+
</keystore.token.store_password>
25+
<keystore.token.key_password>0bzhBRNUXBR5
26+
</keystore.token.key_password>
27+
<keystore.token.key_alias>jwt-token</keystore.token.key_alias>
28+
<keystore.token.dname>CN=cf-java-logging-support, OU=None, O=SAP,
29+
L=Unknown, ST=Unknown, C=Unknown
30+
</keystore.token.dname>
2231
</properties>
2332

2433
<dependencyManagement>
@@ -68,7 +77,7 @@
6877
<artifactId>spring-security-test</artifactId>
6978
<scope>test</scope>
7079
</dependency>
71-
80+
7281
<!-- We're using the Servlet Filter instrumentation -->
7382
<dependency>
7483
<groupId>com.sap.hcp.cf.logging</groupId>
@@ -90,10 +99,21 @@
9099
</dependencies>
91100

92101
<build>
102+
<resources>
103+
<resource>
104+
<directory>src/main/resources</directory>
105+
<filtering>true</filtering>
106+
</resource>
107+
<resource>
108+
<directory>target/generated-resources/keystore</directory>
109+
</resource>
110+
</resources>
111+
93112
<plugins>
94113
<plugin>
95114
<groupId>org.springframework.boot</groupId>
96115
<artifactId>spring-boot-maven-plugin</artifactId>
116+
<version>${spring.boot.version}</version>
97117
<executions>
98118
<execution>
99119
<goals>
@@ -106,12 +126,51 @@
106126
</build>
107127

108128
<profiles>
129+
<profile>
130+
<id>initialze-keystore</id>
131+
<activation>
132+
<file>
133+
<missing>target/generated-resources/keystore/token_keystore.jks
134+
</missing>
135+
</file>
136+
</activation>
137+
<build>
138+
<plugins>
139+
<plugin>
140+
<groupId>org.codehaus.mojo</groupId>
141+
<artifactId>keytool-maven-plugin</artifactId>
142+
<version>${keytool.plugin.version}</version>
143+
<executions>
144+
<execution>
145+
<id>create-key-pair</id>
146+
<goals>
147+
<goal>generateKeyPair</goal>
148+
</goals>
149+
<phase>generate-resources</phase>
150+
</execution>
151+
</executions>
152+
<configuration>
153+
<keystore>target/generated-resources/keystore/token_keystore.jks
154+
</keystore>
155+
<storepass>${keystore.token.store_password}</storepass>
156+
<keypass>${keystore.token.key_password}</keypass>
157+
<alias>${keystore.token.key_alias}</alias>
158+
<dname>${keystore.token.dname}</dname>
159+
<sigalg>SHA256withRSA</sigalg>
160+
<ext></ext>
161+
<validity>100</validity>
162+
<keyalg>RSA</keyalg>
163+
<keysize>2048</keysize>
164+
</configuration>
165+
</plugin>
166+
</plugins>
167+
</build>
168+
</profile>
109169
<profile>
110170
<id>logback</id>
111171
<activation>
112172
<activeByDefault>true</activeByDefault>
113173
</activation>
114-
115174
<dependencies>
116175
<dependency>
117176
<groupId>org.springframework.boot</groupId>
@@ -129,7 +188,6 @@
129188
<activation>
130189
<activeByDefault>false</activeByDefault>
131190
</activation>
132-
133191
<dependencies>
134192
<dependency>
135193
<groupId>org.springframework.boot</groupId>

sample-spring-boot/src/main/resources/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ keystore:
33
token:
44
type: jks
55
location: "classpath:token_keystore.jks"
6-
password: "0bzhBRNUXBR5"
7-
keyAlias: jwt-token
8-
keyPassword: "0bzhBRNUXBR5"
6+
password: ${keystore.token.store_password}
7+
keyAlias: ${keystore.token.key_alias}
8+
keyPassword: ${keystore.token.key_password}
99
defaults:
1010
token:
1111
expiration: P2D
Binary file not shown.

0 commit comments

Comments
 (0)