I've since picked back up on the project and similar aspects, and I figured it'd be useful to return to provide some more details.
For starters, I mentioned in passing my configuration of the delightful
openapi-generator tool, but didn't actually detail my configuration. It's changed a little since my first work, since I found where you can specify using the
I use a config.yaml file like:
That will generate client interfaces that will mostly compile in a plain Jakarta EE project. The files have some references to an implementation-specific MIME class to work around JAX-RS's historical lack of one, but those imports can be safely deleted.
Keycloak/OIDC in Keep
I also mentioned only in passing that you could configure Keep to trust the Keycloak server's public keys with a link to the documentation. Things on the Keep side have expanded since then, and you can now configure Keep to reference Keycloak using Vert.x's internal OIDC support, and also skip the step of creating special fields in your person docs to house the Notes-format DN. For example, in a Keep JSON config file:
That will cause Keep to fetch much of the configuration information from the well-known endpoint Keycloak exposes, and also to map names from Keycloak from the LDAP-style format of "cn=Foo Fooson,o=SomeOrg" to Domino-style "CN=Foo Fooson/O=SomeOrg". This is useful even when using Domino as the Keycloak LDAP backend, since Domino does the translation in the other direction first.
Keycloak/OIDC in Jakarta EE
In the original post in the series, talking about configuring app authentication for the AppDev Pack, I talked about Open Liberty's
openidConnectClient feature, which lets you configure OIDC at the server level. That's neat, and I remain partial to putting authentication at the server level when it makes sense, but it's no longer the only game in town. The version of Jakarta Security that comes with Jakarta EE 10 supports OIDC inside the app in a neat way, and so I've switched to using that.
To do that, you make a CDI bean that defines your OIDC configuration - this can actually be on a class that does other things as well, but I like putting it in its own place:
There are a couple EL references here.
baseURL is provided for "free" by the framework, allowing you to say "wherever the app is hosted" without having to hard-code it.
oidc here refers to a bean I made that's annotated with
@Named("oidc") and has getters like
getClientId() and so forth. You can make a class like that to pull in your OIDC config and secrets from outside, such as a resource file, environment variables, or so forth.
providerURI should be the same base URL as Keep uses above.
Once you do that, you can start putting
@RolesAllowed annotations on resources you want protected. So far, I've been using
@RolesAllowed("users"), since my Keycloak puts all authenticated users in that group, but you could mix it up with "admin" or other meaningful roles per endpoint. For example, inside a JAX-RS class:
When accessing that endpoint, the app will redirect the user to Keycloak (or your OIDC provider) automatically if they're not already logged in.
Accessing the Token
In my previous posts, I mentioned that I was able to access the OIDC token that the server used by setting
accessTokenInLtpaCookie in the Liberty config, and then getting
oidc_access_token from the Servlet request object's attributes, and that that only showed up on requests after the first.
The good news is that, with the latest Jakarta Security, there's a standardized way to do this. In a CDI bean, you can inject an
OpenIdContext object to get the current user's token:
There are other methods on that
OpenIdContext object, providing access to specific claims and information from the token, which would be useful in other situations. Here, I only really care about the token as a string, since that's what I'll send to Keep.
With that token in hand, you can build a MicroProfile Rest Client using the generated API interfaces. For example:
That will cascade the OIDC token used for your app login over to Keep, allowing your app to access data on behalf of the logged-in user smoothly.
I've been kicking the tires on some example apps and fleshing out the Jakarta NoSQL driver using this, and it's been going really smoothly so far. Eventually, my goal will be to make it so that you can take code using the JNoSQL driver for Domino inside an NSF using the XPages JEE project and move it with minimal changes over to a "normal" JEE app using Keep for access. There'll be a bit of rockiness in that the upstream JNoSQL API is changing a bit to adapt to Jakarta Data and will do so in time for JEE to require Java 21, but at least it won't be too painful an analogy.