/** * Create a filter that will encode every request that is made by the Jersey client * using this filter. * * @param apiKey the API key * @param secretKey the secret key * @param messageBodyWorkers the {@link MessageBodyWorkers} used by the client */ public HmacClientFilter(String apiKey, String secretKey, MessageBodyWorkers messageBodyWorkers) { this(apiKey, secretKey, messageBodyWorkers, null, new RequestConfiguration()); }
/** * Create a signature given the set of request credentials and a secret key. * * @param credentials the credentials specified on the request * @param secretKey the secret key that will be used to generate the signature * @return the signature */ private String createSignature(Credentials credentials, String secretKey) { return new SignatureGenerator().generate( secretKey, credentials.getMethod(), credentials.getTimestamp(), credentials.getPath(), credentials.getContent()); }
public static Builder builder() { return new Builder(); }
public Credentials decode(HttpRequestContext request) { return Credentials.builder() .withApiKey(getApiKey(request)) .withSignature(getSignature(request)) .withPath(getPath(request)) .withTimestamp(getTimestamp(request)) .withContent(getContent(request)) .withMethod(getMethod(request)) .withVersion(Version.V1) .build(); }
private String buildSignature(ClientRequest request, String timestamp) { String method = getMethod(request); String path = getPath(request); byte[] content = getContent(request); return signatureGenerator.generate(secretKey, method, timestamp, path, content); }
public void encode(ClientRequest request) { String timestamp = TimeUtils.getCurrentTimestamp(); addApiKey(request); addTimestamp(request, timestamp); addSignature(request, timestamp); addVersion(request, Version.V1); }
public Credentials build() { return new Credentials(version, apiKey, signature, path, timestamp, method, content); }
public static CredentialsBuilder builder() { return new CredentialsBuilder(); }
public Credentials decode(HttpRequestContext request) { return Credentials.builder() .withApiKey(getApiKey(request)) .withSignature(getSignature(request)) .withPath(getPath(request)) .withTimestamp(getTimestamp(request)) .withContent(getContent(request)) .withMethod(getMethod(request)) .withVersion(Version.V1) .build(); }
/** * Create a signature given the set of request credentials and a secret key. * * @param credentials the credentials specified on the request * @param secretKey the secret key that will be used to generate the signature * @return the signature */ private String createSignature(Credentials credentials, String secretKey) { return new SignatureGenerator().generate( secretKey, credentials.getMethod(), credentials.getTimestamp(), credentials.getPath(), credentials.getContent()); }
/** * Create a filter that will encode every request that is made by the Jersey client * using this filter. * * @param apiKey the API key * @param secretKey the secret key * @param messageBodyWorkers the {@link MessageBodyWorkers} used by the client */ public HmacClientFilter(String apiKey, String secretKey, MessageBodyWorkers messageBodyWorkers) { this(apiKey, secretKey, messageBodyWorkers, null, new RequestConfiguration()); }
public static Builder builder() { return new Builder(); }
public Credentials build() { return new Credentials(version, apiKey, signature, path, timestamp, method, content); }
public static CredentialsBuilder builder() { return new CredentialsBuilder(); }
public Credentials decode(HttpRequestContext request) { return Credentials.builder() .withApiKey(getApiKey(request)) .withSignature(getSignature(request)) .withPath(getPath(request)) .withTimestamp(getTimestamp(request)) .withContent(getContent(request)) .withMethod(getMethod(request)) .withVersion(Version.V1) .build(); }
/** * Create a filter that will encode every request that is made by the Jersey client * using this filter. * * @param apiKey the API key * @param secretKey the secret key */ public HmacClientFilter(String apiKey, String secretKey) { this(apiKey, secretKey, null, new RequestConfiguration()); }
public RequestConfiguration build() { return new RequestConfiguration(signatureHttpHeader, timestampHttpHeader, versionHttpHeader, apiKeyQueryParamName); } }
public RequestConfiguration build() { return new RequestConfiguration(signatureHttpHeader, timestampHttpHeader, versionHttpHeader, apiKeyQueryParamName); } }
/** * Create a filter that will encode every request made to the specified * endpoint. This is useful if the Jersey client to which this filter is applied * is used to invoke other services as well, ensuring that the specified API key * and secret keys are used to secure only the requests that are made to the given * endpoint. * <p> * The portion of the endpoint {@link URI} that is used is the "authority" of the URI, which * is essentially just the host and port, or just the host if there is no port specified. * * @param apiKey the API key * @param secretKey the secret key * @param endpointToSecure the endpoint {@link URI} to secure with this filter */ public HmacClientFilter(String apiKey, String secretKey, URI endpointToSecure) { this(apiKey, secretKey, endpointToSecure, new RequestConfiguration()); }
/** * Create a filter that will encode every request made to the specified * endpoint. This is useful if the Jersey client to which this filter is applied * is used to invoke other services as well, ensuring that the specified API key * and secret keys are used to secure only the requests that are made to the given * endpoint. * <p> * The portion of the endpoint {@link URI} that is used is the "authority" of the URI, which * is essentially just the host and port, or just the host if there is no port specified. * * @param apiKey the API key * @param secretKey the secret key * @param messageBodyWorkers the {@link MessageBodyWorkers} utilized by the client * @param endpointToSecure the endpoint {@link URI} to secure with this filter */ public HmacClientFilter(String apiKey, String secretKey, MessageBodyWorkers messageBodyWorkers, URI endpointToSecure) { this(apiKey, secretKey, messageBodyWorkers, endpointToSecure, new RequestConfiguration()); }