-
Notifications
You must be signed in to change notification settings - Fork 24
Security Options
Hammock provides a few useful security hacks.
This provides some useful interceptor based checking to ensure that a user is in a role or is logged in to the system.
<dependency>
<artifactId>security-spi</artifactId>
<groupId>ws.ament.hammock</groupId>
<version>${hammock.version}</version>
</dependency>
You can add JWT processing in to your Hammock runtime, as a preview of Microprofile JWT RBAC. It's built on nimbus-jose-jwt
. Any request that includes JWT in the Authorization
header or an access_token
query parameter will be processed.
Configuration Options:
-
jwt.filter.uris
: The URIs to apply JWT processing to. You may want it off in some areas of your application, but by default it's bound to/*
-
jwt.header.enabled
: Default totrue
, whetherAuthorization
header processing should be enabled -
jwt.query.param.enabled
: Defaults totrue
whether query parameter process should be enabled -
jwt.query.param.name
: What the name of the query parameter to read from should be. The default is to match the OIDC spec, and useaccess_token
-
jwt.processor
: The full class name to use as your JWT processor. The default is aSimpleJWTProcessor
that just reads the JWT without doing any validation on it. This should not be used in production. There is a second built in to Hammock,ws.ament.hammock.jwt.processor.DefaultValidatingJWTProcessor
, which uses the next set of properties. Otherwise you can provide your own implementation ofws.ament.hammock.jwt.processor.JWTProcessor
Options specific to DefaultValidatingJWTProcessor
:
-
jwt.algorithm
: The signing algorithm to use. Defaults toHS256
. The valid values come from here -
jwt.jwk.source.url
: The URL to download the JWK(s) from when looking at the signed values. -
jwt.jwk.source.file
: The file to look at for the JWK(s).
Note: One of source url/file must be specified.
To add to your application use
<dependency>
<artifactId>security-jose</artifactId>
<groupId>ws.ament.hammock</groupId>
<version>${hammock.version}</version>
</dependency>
You can integrate a Hammock application with Keycloak. It assumes that your backend is using JAX-RS (only tested so far with RestEasy). Any request that includes an Authorization
header with Bearer
will be treated as a JWT and authenticated against Keycloak.
If you're using a single realm, you can provide all configuration options that would go into AdapterConfig
as properties. They would be prefixed with keycloak
, as an example:
keycloak.auth-server-url=http://localhost:8080/auth/
keycloak.realm=master
keycloak.resource=test-client
keycloak.public-client=true
keycloak.ssl-required=external
You can also set keycloak.config.file
to point to a keycloak.json
file with your configuration.
KeycloakConfiguration
implements KeycloakConfigResolver
so if you need to use multiple realms on a per request basis, using Keycloak's native functionality, you can do that by creating an alternative implementation of KeycloakConfigResolver
.