use of com.bluenimble.platform.api.security.ApiRequestSignerException in project serverless by bluenimble.
the class DefaultApiRequestSigner method sign.
/**
* [VERB] + '\n' + [ENDPOINT] + '\n' + [REQUEST URI: must starts with '/'] + '\n' + [ACCESS_KEY] '\n' + [ORDERED REQUEST PARAMETERS] + '\n' + [Timestamp Header]
*/
public String sign(ApiRequest request, String utcTimestamp, String accessKey, String secretKey, boolean writeTorequest) throws ApiRequestSignerException {
SortedMap<String, String> sorted = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
Iterator<String> names = request.keys(Scope.Parameter);
if (names != null) {
while (names.hasNext()) {
String name = names.next();
sorted.put(name, String.valueOf(request.get(name)));
}
}
String params = canonicalize(sorted);
String rEndpoint = request.getEndpoint();
StringBuilder sb = new StringBuilder();
sb.append(request.getVerb().name()).append(Lang.ENDLN).append(request.getScheme()).append(Lang.COLON).append(Lang.SLASH).append(Lang.SLASH).append(rEndpoint).append(Lang.ENDLN).append(request.getPath()).append(Lang.ENDLN).append(params).append(Lang.ENDLN).append(accessKey).append(Lang.ENDLN).append(utcTimestamp);
String s = sb.toString();
sb.setLength(0);
try {
s = hmac(secretKey, s);
} catch (Exception e) {
throw new ApiRequestSignerException(e.getMessage(), e);
}
return s;
}
Aggregations