Search in sources :

Example 1 with HttpRequestSignerException

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);
    }
}
Also used : HttpHeader(com.bluenimble.platform.http.HttpHeader) AccessSecretKeysBasedHttpRequestSigner(com.bluenimble.platform.http.auth.impls.AccessSecretKeysBasedHttpRequestSigner) HttpRequestSignerException(com.bluenimble.platform.http.auth.HttpRequestSignerException) HttpHeaderImpl(com.bluenimble.platform.http.impls.HttpHeaderImpl) HttpRequestWriteException(com.bluenimble.platform.http.request.HttpRequestWriteException)

Example 2 with HttpRequestSignerException

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)));
    }
}
Also used : HttpParameterImpl(com.bluenimble.platform.http.impls.HttpParameterImpl) HttpHeader(com.bluenimble.platform.http.HttpHeader) HttpRequestSignerException(com.bluenimble.platform.http.auth.HttpRequestSignerException) HttpParameter(com.bluenimble.platform.http.HttpParameter) URI(java.net.URI) HttpHeaderImpl(com.bluenimble.platform.http.impls.HttpHeaderImpl)

Aggregations

HttpHeader (com.bluenimble.platform.http.HttpHeader)2 HttpRequestSignerException (com.bluenimble.platform.http.auth.HttpRequestSignerException)2 HttpHeaderImpl (com.bluenimble.platform.http.impls.HttpHeaderImpl)2 HttpParameter (com.bluenimble.platform.http.HttpParameter)1 AccessSecretKeysBasedHttpRequestSigner (com.bluenimble.platform.http.auth.impls.AccessSecretKeysBasedHttpRequestSigner)1 HttpParameterImpl (com.bluenimble.platform.http.impls.HttpParameterImpl)1 HttpRequestWriteException (com.bluenimble.platform.http.request.HttpRequestWriteException)1 URI (java.net.URI)1