@Provider @Priority(value=2000) public class WebhookSignatureFilter extends Object implements javax.ws.rs.container.ContainerRequestFilter
X-Hub-Signature request header against the request body
and a shared secret.
The secret can either be given to the filter constructor, or retrieved from the
matched resource which must then implement
HasWebhookSecret. Alternatively, the filter can be subclassed and the
getSecret(ContainerRequestContext) method overridden.
The filter will only apply to resources annotated with Webhook.
| Constructor and Description |
|---|
WebhookSignatureFilter()
Constructs a
WebhookSignatureFilter that will ask the
matched resource for the secret. |
WebhookSignatureFilter(byte[] secret)
Constructs a
WebhookSignatureFilter with a fixed secret. |
WebhookSignatureFilter(String secret)
Constructs a
WebhookSignatureFilter with a fixed secret. |
| Modifier and Type | Method and Description |
|---|---|
void |
filter(javax.ws.rs.container.ContainerRequestContext requestContext) |
protected byte[] |
getSecret(javax.ws.rs.container.ContainerRequestContext requestContext)
Returns the secret to use for computing the signature of the request body (before comparing it
with the one sent in the
X-Hub-Signature request header). |
public WebhookSignatureFilter()
WebhookSignatureFilter that will ask the
matched resource for the secret.
Matched resources MUST implement HasWebhookSecret or the filter
will error out with a ClassCastException (leading to an internal server error response).
public WebhookSignatureFilter(String secret)
WebhookSignatureFilter with a fixed secret.
The secret's UTF-8 bytes will actually be used as the secret. This is equivalent to calling:
new WebhookSignatureFilter(secret.getBytes(StandardCharsets.UTF-8))
public WebhookSignatureFilter(byte[] secret)
WebhookSignatureFilter with a fixed secret.protected byte[] getSecret(javax.ws.rs.container.ContainerRequestContext requestContext)
X-Hub-Signature request header).
The default implementation will either return the fixed secret if one has been set through
the constructor, or cast the matched resource to
HasWebhookSecret and call HasWebhookSecret.getWebhookSecret().
public void filter(javax.ws.rs.container.ContainerRequestContext requestContext)
throws IOException
filter in interface javax.ws.rs.container.ContainerRequestFilterIOExceptionCopyright © 2015. All rights reserved.