/** * 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, RequestConfiguration requestConfiguration) { checkNotNull(apiKey, "apiKey"); checkNotNull(secretKey, "secretKey"); this.endpointToSecure = endpointToSecure; this.requestEncoder = new RequestEncoder(apiKey, secretKey, new SignatureGenerator(), 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 * @param requestConfiguration your settings for this endpoint. */ public HmacClientFilter(String apiKey, String secretKey, MessageBodyWorkers messageBodyWorkers, URI endpointToSecure, RequestConfiguration requestConfiguration) { checkNotNull(apiKey, "apiKey"); checkNotNull(secretKey, "secretKey"); checkNotNull(messageBodyWorkers, "messageBodyWorkers"); this.endpointToSecure = endpointToSecure; this.requestEncoder = new RequestEncoder(apiKey, secretKey, messageBodyWorkers, new SignatureGenerator(), 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 * @param requestConfiguration your settings for this endpoint. */ public HmacClientFilter(String apiKey, String secretKey, MessageBodyWorkers messageBodyWorkers, URI endpointToSecure, RequestConfiguration requestConfiguration) { checkNotNull(apiKey, "apiKey"); checkNotNull(secretKey, "secretKey"); checkNotNull(messageBodyWorkers, "messageBodyWorkers"); this.endpointToSecure = endpointToSecure; this.requestEncoder = new RequestEncoder(apiKey, secretKey, messageBodyWorkers, new SignatureGenerator(), 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()); }
/** * 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()); }