use of com.bluenimble.platform.http.auth.HttpRequestSignerException in project serverless by bluenimble.
the class BlueNimbleHttpRequestVisitor method visit.
@Override
public void visit(HttpRequest request, HttpURLConnection connection) throws HttpRequestWriteException {
// sign request
List<HttpHeader> headers = request.getHeaders();
if (headers == null) {
headers = new ArrayList<HttpHeader>();
request.setHeaders(headers);
}
AccessSecretKeysBasedHttpRequestSigner signer = new AccessSecretKeysBasedHttpRequestSigner("m>h>p>d>k>t", "Bearer", accessKey, secretKey);
String timestamp = Lang.utc();
headers.add(new HttpHeaderImpl(ApiHeaders.Timestamp, timestamp));
signer.getData().put('t', timestamp);
try {
signer.sign(request);
} catch (HttpRequestSignerException e) {
throw new HttpRequestWriteException(e.getMessage(), e);
}
}
use of com.bluenimble.platform.http.auth.HttpRequestSignerException in project serverless by bluenimble.
the class AccessSecretKeysBasedHttpRequestSigner method sign.
@Override
public void sign(HttpRequest request) throws HttpRequestSignerException {
List<HttpParameter> params = request.getParameters();
String signature = null;
try {
URI uri = request.getURI();
signature = generate(params, uri.getScheme() + "://" + uri.getHost(), uri.getPort(), uri.getPath(), request.getName());
} catch (Throwable th) {
throw new HttpRequestSignerException(th);
}
if (SignaturePlaceHolder.Headers.equals(signatureParameterPlace)) {
List<HttpHeader> headers = request.getHeaders();
if (headers == null) {
headers = new ArrayList<HttpHeader>();
request.setHeaders(headers);
}
headers.add(new HttpHeaderImpl(HttpHeaders.AUTHORIZATION, scheme + " " + accessKey + ":" + signature));
} else {
if (signatureParameterName == null) {
signatureParameterName = "signature";
}
params.add(new HttpParameterImpl(signatureParameterName, encode(signature)));
}
}
Aggregations