Skip to content

Commit d71bf2f

Browse files
authored
Merge pull request #31 from Axway-API-Management-Plus/Devops
Pipeline to run junit
2 parents 7eda1f9 + 90ea7f5 commit d71bf2f

File tree

16 files changed

+378
-70
lines changed

16 files changed

+378
-70
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: APIM ENV CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up JDK 11
12+
uses: actions/setup-java@v2
13+
with:
14+
java-version: '11'
15+
distribution: 'adopt'
16+
- name: Delete Gateway dependent file
17+
run: rm src/main/java/com/axway/ExternalConfigLoader.java
18+
- name: Build with Maven
19+
run: mvn -f pom_test.xml test

pom.xml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,29 @@
2222
<dependency>
2323
<groupId>junit</groupId>
2424
<artifactId>junit</artifactId>
25-
<version>[4.13.1,)</version>
25+
<version>4.13.2</version>
2626
<scope>test</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.apache.logging.log4j</groupId>
30+
<artifactId>log4j-api</artifactId>
31+
<version>2.14.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.logging.log4j</groupId>
35+
<artifactId>log4j-core</artifactId>
36+
<version>2.14.1</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.bouncycastle</groupId>
40+
<artifactId>bcprov-jdk15on</artifactId>
41+
<version>1.69</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.bouncycastle</groupId>
45+
<artifactId>bcpkix-jdk15on</artifactId>
46+
<version>1.69</version>
47+
</dependency>
2848
<dependency>
2949
<groupId>apigw-common</groupId>
3050
<artifactId>apigw-common</artifactId>
@@ -65,26 +85,6 @@
6585
<artifactId>vordel-config</artifactId>
6686
<version>${apigateway.version}</version>
6787
</dependency>
68-
<dependency>
69-
<groupId>org.apache.logging.log4j</groupId>
70-
<artifactId>log4j-api</artifactId>
71-
<version>2.13.3</version>
72-
</dependency>
73-
<dependency>
74-
<groupId>org.apache.logging.log4j</groupId>
75-
<artifactId>log4j-core</artifactId>
76-
<version>2.13.3</version>
77-
</dependency>
78-
<dependency>
79-
<groupId>org.bouncycastle</groupId>
80-
<artifactId>bcprov-jdk15on</artifactId>
81-
<version>1.69</version>
82-
</dependency>
83-
<dependency>
84-
<groupId>org.bouncycastle</groupId>
85-
<artifactId>bcpkix-jdk15on</artifactId>
86-
<version>1.69</version>
87-
</dependency>
8888
</dependencies>
8989
<build>
9090
<plugins>

pom_test.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.axway</groupId>
8+
<artifactId>apim-env-module</artifactId>
9+
<version>1.1.6</version>
10+
11+
<name>apim-env-module</name>
12+
<url>https://axway.com</url>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
<apigateway.version>7.7.0.20210830-2</apigateway.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.13.2</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.logging.log4j</groupId>
30+
<artifactId>log4j-api</artifactId>
31+
<version>2.14.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.logging.log4j</groupId>
35+
<artifactId>log4j-core</artifactId>
36+
<version>2.14.1</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.bouncycastle</groupId>
40+
<artifactId>bcprov-jdk15on</artifactId>
41+
<version>1.69</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.bouncycastle</groupId>
45+
<artifactId>bcpkix-jdk15on</artifactId>
46+
<version>1.69</version>
47+
</dependency>
48+
</dependencies>
49+
</project>

src/main/java/com/axway/CertHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
public class CertHelper {
2020

21+
2122
final JcaPEMKeyConverter jcaPEMKeyConverter = new JcaPEMKeyConverter();
2223

2324
public PKCS12 parseP12(File file, char[] password) throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException, UnrecoverableKeyException {
@@ -78,6 +79,7 @@ public PrivateKey parsePrivateKey(String base64EncodedCertOrFilePath) throws IOE
7879
}
7980
PEMParser pemParser = new PEMParser(reader);
8081
Object pemContent = pemParser.readObject();
82+
System.out.println(pemContent.getClass().getName());
8183
if (pemContent instanceof PEMKeyPair) {
8284
PEMKeyPair pemKeyPair = (PEMKeyPair) pemContent;
8385
KeyPair keyPair = jcaPEMKeyConverter.getKeyPair(pemKeyPair);
@@ -121,7 +123,6 @@ public List<X509Certificate> parseX509(String base64EncodedCertOrFilePath) throw
121123
}
122124
}
123125
}
124-
// return (X509Certificate) certificateFactory.generateCertificate(inputStream);
125126
}
126127

127128
}

src/main/java/com/axway/ExternalConfigLoader.java

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void updatePassword(EntityStore entityStore) {
153153
Trace.info("Pem file alias name :" + alias);
154154
connectToURLConfigureP12(entityStore, filterName, alias);
155155
} catch (Exception e) {
156-
Trace.error("Unable to add the pem key, ca and certificate from Environment variable", e);
156+
Trace.error("Unable to add the key and certificate from Environment variable", e);
157157
}
158158
} else if (key.startsWith("jwtsigncert_")) {
159159
try {
@@ -164,7 +164,7 @@ private void updatePassword(EntityStore entityStore) {
164164
Trace.info("Pem file alias name :" + alias);
165165
jwtSignConfigureP12(entityStore, filterName, alias);
166166
} catch (Exception e) {
167-
Trace.error("Unable to add the p12 from Environment variable", e);
167+
Trace.error("Unable to add the key and certificate from Environment variable", e);
168168
}
169169
} else if (key.startsWith("jwtverifycert_")) {
170170
try {
@@ -173,7 +173,7 @@ private void updatePassword(EntityStore entityStore) {
173173
String alias = importPublicCertificate(certificate, entityStore);
174174
jwtVerifyConfigureCertificate(entityStore, filterName, alias);
175175
} catch (Exception e) {
176-
Trace.error("Unable to add the p12 from Environment variable", e);
176+
Trace.error("Unable to add the certificate from Environment variable", e);
177177
}
178178
}else if (key.startsWith("gatewaytoplogycertandkey_")) {
179179
try {
@@ -199,7 +199,7 @@ private void updatePassword(EntityStore entityStore) {
199199
}
200200
}
201201

202-
Map<String, Map<String, String>> httpBasicObjs = parseCred(httpBasic);
202+
Map<String, Map<String, String>> httpBasicObjs = Util.parseCred(httpBasic);
203203
if (!httpBasicObjs.isEmpty()) {
204204
for (Map.Entry<String, Map<String, String>> entry : httpBasicObjs.entrySet()) {
205205
String filterName = entry.getKey();
@@ -210,23 +210,23 @@ private void updatePassword(EntityStore entityStore) {
210210
}
211211
}
212212

213-
Map<String, Map<String, String>> ldapObjs = parseCred(ldap);
213+
Map<String, Map<String, String>> ldapObjs = Util.parseCred(ldap);
214214
if (!ldapObjs.isEmpty()) {
215215
for (Map.Entry<String, Map<String, String>> entry : ldapObjs.entrySet()) {
216216
String filterName = entry.getKey();
217217
Map<String, String> attributes = entry.getValue();
218218
updateLdap(entityStore, attributes, filterName);
219219
}
220220
}
221-
Map<String, Map<String, String>> jmsObjs = parseCred(jms);
221+
Map<String, Map<String, String>> jmsObjs = Util.parseCred(jms);
222222
if (!jmsObjs.isEmpty()) {
223223
for (Map.Entry<String, Map<String, String>> entry : jmsObjs.entrySet()) {
224224
String filterName = entry.getKey();
225225
Map<String, String> attributes = entry.getValue();
226226
updateJMS(entityStore, attributes, filterName);
227227
}
228228
}
229-
Map<String, Map<String, String>> smtpObjs = parseCred(smtp);
229+
Map<String, Map<String, String>> smtpObjs = Util.parseCred(smtp);
230230
if (!smtpObjs.isEmpty()) {
231231
for (Map.Entry<String, Map<String, String>> entry : smtpObjs.entrySet()) {
232232
String filterName = entry.getKey();
@@ -265,30 +265,7 @@ private Map<String, String> groupEnvVariables(Map<String, String> envValues, Str
265265
}
266266

267267

268-
public Map<String, Map<String, String>> parseCred(Map<String, String> envMap) {
269-
270-
Map<String, Map<String, String>> values = new HashMap<>();
271-
if (envMap != null && !envMap.isEmpty()) {
272-
Iterator<String> keyIterator = envMap.keySet().iterator();
273-
while (keyIterator.hasNext()) {
274-
String key = keyIterator.next();
275-
String[] delimitedKeys = key.split("_");
276-
String filterName;
277-
if (delimitedKeys.length == 3) {
278-
filterName = delimitedKeys[1];
279-
String attribute = delimitedKeys[2];
280-
String value = envMap.get(key);
281-
Map<String, String> attributes = values.get(filterName);
282-
if (attributes == null) {
283-
attributes = new HashMap<>();
284-
values.put(filterName, attributes);
285-
}
286-
attributes.put(attribute, value);
287-
}
288-
}
289-
}
290-
return values;
291-
}
268+
292269

293270
private void updatePasswordField(EntityStore entityStore, String shorthandKey, String fieldName, String
294271
value, Object secret) {
@@ -683,6 +660,9 @@ private PKCS12 importCertAndKeyAndCA(EntityStore entityStore, String cert, Strin
683660
alias = certObj.getSerialNumber().toString();
684661
}
685662
PrivateKey privateKey = certHelper.parsePrivateKey(key);
663+
if( privateKey == null){
664+
throw new Exception("Unable to parse a private key");
665+
}
686666
Trace.info("Certificate alias name : " + alias);
687667
String escapedAlias = ShorthandKeyFinder.escapeFieldValue(alias);
688668
Entity certEntity = getCertEntity(entityStore, escapedAlias);
@@ -717,7 +697,6 @@ private PKCS12 importCertAndKeyAndCA(EntityStore entityStore, String cert, Strin
717697
importPublicCertificate(x509Certificate, entityStore);
718698
Trace.info("Imported root / intermediate certificate");
719699
}
720-
//handle CA Certificate chain
721700
}
722701
pkcs12.setAlias(alias);
723702
pkcs12.setPrivateKey(privateKey);
@@ -735,20 +714,14 @@ private void updateCassandraConsistencyLevel(EntityStore entityStore, String rea
735714
// Update KPS table consistency level
736715
updateCassandraConsistencyLevel(shorthandKeyFinder, "/[KPSRoot]name=Key Property Stores/[KPSPackage]**/[KPSDataSourceGroup]**/[KPSCassandraDataSource]name=Cassandra Storage",
737716
"readConsistencyLevel", readConsistencyLevel, "writeConsistencyLevel", writeConsistencyLevel);
738-
// Update OAUTH table consistency level
739-
// updateCassandraConsistencyLevel(shorthandKeyFinder, "/[KPSRoot]name=Key Property Stores/[KPSPackage]**/[KPSDataSourceGroup]name=DataSources/[KPSCassandraDataSource]name=Cassandra Storage",
740-
// "readConsistencyLevel", readConsistencyLevel, "writeConsistencyLevel", writeConsistencyLevel);
741-
// Update Quota table consistency level
742717
updateCassandraConsistencyLevel(shorthandKeyFinder, "/[PortalConfiguration]name=Portal Config",
743718
"quotaReadConsistency", readConsistencyLevel, "quotaWriteConsistency", writeConsistencyLevel);
744719
//Update throttling consistency level
745720
updateCassandraConsistencyLevel(shorthandKeyFinder, "/[CassandraSettings]name=Cassandra Settings",
746721
"throttlingReadConsistencyLevel", readConsistencyLevel, "throttlingWriteConsistencyLevel", writeConsistencyLevel);
747-
748722
//Update access token consistency level
749723
updateCassandraConsistencyLevel(shorthandKeyFinder, "/[OAuth2StoresGroup]name=OAuth2 Stores/[AccessTokenStoreGroup]name=Access Token Stores/[AccessTokenPersist]**",
750724
"readConsistencyLevel", readConsistencyLevel, "writeConsistencyLevel", writeConsistencyLevel);
751-
752725
//Update auth code consistency level
753726
updateCassandraConsistencyLevel(shorthandKeyFinder, "/[OAuth2StoresGroup]name=OAuth2 Stores/[AuthzCodeStoreGroup]name=Authorization Code Stores/[AuthzCodePersist]**",
754727
"readConsistencyLevel", readConsistencyLevel, "writeConsistencyLevel", writeConsistencyLevel);
@@ -764,15 +737,9 @@ private void updateCassandraConsistencyLevel(ShorthandKeyFinder shorthandKeyFind
764737
Trace.info("Total number of KPS Store: " + kpsEntities.size() + " in entity : " + shorthandKey);
765738
EntityStore entityStore = shorthandKeyFinder.getEntityStore();
766739
for (Entity entity : kpsEntities) {
767-
// Trace.info(entity.toString());
768-
// Trace.info("Read "+ entity.getStringValue(readConsistencyLevelFieldName));
769-
// Trace.info("Write "+ entity.getStringValue(readConsistencyLevelFieldName));
770740
entity.setStringField(readConsistencyLevelFieldName, readConsistencyLevel);
771741
entity.setStringField(writeConsistencyLevelFieldName, writeConsistencyLevel);
772742
entityStore.updateEntity(entity);
773-
// Trace.info("Update Read "+ entity.getStringValue(readConsistencyLevelFieldName));
774-
// Trace.info("Update Write "+ entity.getStringValue(readConsistencyLevelFieldName));
775-
776743
}
777744
}
778745
}

src/main/java/com/axway/Util.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.axway;
2+
3+
import java.util.HashMap;
4+
import java.util.Iterator;
5+
import java.util.Map;
6+
7+
public final class Util {
8+
9+
public static Map<String, Map<String, String>> parseCred(Map<String, String> envMap) {
10+
11+
Map<String, Map<String, String>> values = new HashMap<>();
12+
if (envMap != null && !envMap.isEmpty()) {
13+
Iterator<String> keyIterator = envMap.keySet().iterator();
14+
while (keyIterator.hasNext()) {
15+
String key = keyIterator.next();
16+
String[] delimitedKeys = key.split("_");
17+
String filterName;
18+
if (delimitedKeys.length == 3) {
19+
filterName = delimitedKeys[1];
20+
String attribute = delimitedKeys[2];
21+
String value = envMap.get(key);
22+
Map<String, String> attributes = values.get(filterName);
23+
if (attributes == null) {
24+
attributes = new HashMap<>();
25+
values.put(filterName, attributes);
26+
}
27+
attributes.put(attribute, value);
28+
}
29+
}
30+
}
31+
return values;
32+
}
33+
}

src/test/java/com/axway/CertHelperTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ public void testPrivatelyPublicAndCACert() {
133133
}
134134
}
135135

136+
@Test
137+
public void testKeyAndCert() {
138+
139+
try {
140+
List<X509Certificate> certificates = new ArrayList<>();
141+
X509Certificate cert = certHelper.parseX509("src/test/resources/test_cert.pem").get(0);
142+
certificates.add(cert);
143+
144+
145+
for (X509Certificate certificate: certificates) {
146+
String name = certificate.getSubjectDN().getName();
147+
System.out.println("Serial number :"+ certificate.getSerialNumber());
148+
System.out.println("DN Name :"+ name);
149+
150+
}
151+
152+
PrivateKey privateKey = certHelper.parsePrivateKey("src/test/resources/test_key.pem");
153+
System.out.println(privateKey);
154+
155+
} catch (CertificateException | FileNotFoundException e) {
156+
e.printStackTrace();
157+
} catch (IOException e) {
158+
e.printStackTrace();
159+
}
160+
}
161+
136162

137163
@Test
138164
public void testInvalidTest(){

0 commit comments

Comments
 (0)