Skip to content

Commit 6b66474

Browse files
committed
Add readme for queryparam and add description in javadoc for ApiSigning method
1 parent 83301a7 commit 6b66474

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ repositories {
133133
mavenLocal()
134134
}
135135
dependencies {
136-
compile group: 'com.api.util', name: 'ApiSecurity', version: '1.0-SNAPSHOT'
136+
compile group: 'com.api.util', name: 'ApiSecurity', version: '1.3.0-SNAPSHOT'
137137
}
138138
139139
```
@@ -148,7 +148,7 @@ Params:
148148
* realm
149149
* authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg'
150150
* httpMethod
151-
* urlPath
151+
* urlPath - Signing URL, remember to append <<tenant>>.e.api.gov.sg or <<tenant>>-pvt.i.api.gov.sg in <<URL>>
152152
* appId - App ID created in Gateway
153153
* secret - set to null for REST L2 SHA256WITHRSA
154154
* formList - to support parameter for form data if any
@@ -163,18 +163,33 @@ Params:
163163
String realm = "<<your_client_host_url>>"
164164
String authPrefix = "<<authPrefix>>
165165
String httpMethod = "get"
166-
String url = "https://<<Target_URL>>/api/v1/?param1=first&param2=123";
166+
//Append the query param in the url or else add as ApiList
167+
String signingUrl = "https://<<URL>>/api/v1/?param1=first&param2=123";
167168
String certFileName = "certificates/ssc.alpha.example.com.p12";
168169
String password = "<<passphrase>>";
169170
String alias = "alpha";
170171
String appId = "<<appId>>";
171172
String secret = null;
173+
//only needed for Content-Type: application/x-www-form-urlencoded, else null
172174
ApiList formList = null;
173175
String nonce = null;
174176
String timestamp = null;
175177

178+
179+
//optional for QueryParam - in-case not append the query parameters in the signingUrl
180+
//Sring signingUrl = "https://<<tenant>>-pvt.i.api.gov.sg/api/v1"
181+
ApiList queryParam = new ApiList();
182+
queryParam.add("query1","value1");
183+
184+
//optional for formList
185+
ApiList formList = new ApiList();
186+
formList.add("param1", "data1");
187+
188+
//If queryParam and formList are both available, combine the list before submitting
189+
formList.addAll(queryParam);
190+
176191
try {
177-
String signature = ApiSigning.getSignatureToken(authPrefix, authPrefix, httpMethod, url, appId, secret, formList, password, alias, certFileName, nonce, timestamp);
192+
String signature = ApiSigning.getSignatureToken(authPrefix, authPrefix, httpMethod, signingUrl, appId, secret, formList, password, alias, certFileName, nonce, timestamp);
178193
} catch (ApiUtilException e) {
179194
e.printStackTrace();
180195
}
@@ -196,7 +211,7 @@ Params:
196211
* timestamp - set to null for current timestamp
197212

198213
```java
199-
String url = "https://<<Target_URL>>/api/v1/?param1=first&param2=123";
214+
String signingUrl = "https://<<URL>>/api/v1/?param1=first&param2=123";
200215

201216
ApiList formList = new ApiList();
202217
formList.add("param1", "data1");
@@ -208,7 +223,7 @@ baseString = ApiSigning.getBaseString(
208223
"<<authPrefix>>",
209224
"HMACSHA256",
210225
"<<appId>>",
211-
url,
226+
signingUrl,
212227
"post",
213228
formList,
214229
"6584351262900708156",

src/main/java/com/api/util/ApiSecurity/ApiSigning.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,10 @@ public static PublicKey getPublicKeyFromX509Certificate(String publicCertificate
364364
}
365365

366366
/**
367-
* @param key
368-
* @return
367+
* Get Public Key from PEM format file
368+
*
369+
* @param publicCertificateFileName PEM file path
370+
* @return Public Key
369371
* @throws IOException
370372
* @throws GeneralSecurityException
371373
*/
@@ -619,6 +621,12 @@ private static long getNewTimestamp() {
619621
return System.currentTimeMillis();
620622
}
621623

624+
/**
625+
* Get new Nonce value used for signature generation
626+
*
627+
* @return nonce value
628+
* @throws NoSuchAlgorithmException
629+
*/
622630
private static String getNewNonce() throws NoSuchAlgorithmException {
623631
String nonce = null;
624632
byte[] b = new byte[32];
@@ -629,6 +637,15 @@ private static String getNewNonce() throws NoSuchAlgorithmException {
629637
}
630638

631639

640+
/**
641+
* Get Private Key from PEM format file
642+
*
643+
* @param privateKeyFileName PEM file path
644+
* @param password
645+
* @return Private Key
646+
* @throws IOException
647+
* @throws GeneralSecurityException
648+
*/
632649
public static PrivateKey getPrivateKeyPEM(String privateKeyFileName, String password) throws IOException, GeneralSecurityException{
633650
log.debug("Enter :: getPrivateKeyPEM :: privateKeyFileName : {} ", privateKeyFileName);
634651
PrivateKey key = null;

0 commit comments

Comments
 (0)