Skip to content

feat(#1737): Add OAuth2 JWT authentication support via JAAS LoginModule#1738

Open
jbonofre wants to merge 5 commits intoapache:mainfrom
jbonofre:gh-1737
Open

feat(#1737): Add OAuth2 JWT authentication support via JAAS LoginModule#1738
jbonofre wants to merge 5 commits intoapache:mainfrom
jbonofre:gh-1737

Conversation

@jbonofre
Copy link
Member

@jbonofre jbonofre commented Mar 8, 2026

Add OAuth2LoginModule to activemq-jaas that validates JWT access tokens using JWKS endpoint for signature verification.

Clients pass the JWT as the password field, and claims are mapped to UserPrincipal/GroupPrincipal for seamless integration with the existing JaasAuthenticationPlugin.

…inModule

Add OAuth2LoginModule to activemq-jaas that validates JWT access tokens
using JWKS endpoint for signature verification. Clients pass the JWT as
the password field, and claims are mapped to UserPrincipal/GroupPrincipal
for seamless integration with the existing JaasAuthenticationPlugin.
@jbonofre jbonofre requested a review from jeanouii March 8, 2026 08:04
@jbonofre
Copy link
Member Author

jbonofre commented Mar 8, 2026

NB: this is a better approach imho to what I did initially in #1035 (with the same goal).

@jbonofre
Copy link
Member Author

jbonofre commented Mar 8, 2026

The test failure is related to #1741

Copy link
Contributor

@jeanouii jeanouii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small details. nothing important

jeanouii
jeanouii previously approved these changes Mar 9, 2026
Copy link
Contributor

@jeanouii jeanouii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattrpav
Copy link
Contributor

-1 on merging this as part of the activemq-jaas module. This drags in 3rd party dependency to all deployments -- I think this should go into a activemq-jaas-oath2 module.

@mattrpav mattrpav self-requested a review March 11, 2026 01:27
Copy link
Contributor

@mattrpav mattrpav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go into a separate module and get deployed into an extras folder (with the 3rd party) dependency instead of installed into the classpath by default for every running broker.

@jbonofre
Copy link
Member Author

I think this should go into a separate module and get deployed into an extras folder (with the 3rd party) dependency instead of installed into the classpath by default for every running broker.

@mattrpav what is the concern about the Nimbus dependency in the JAAS module ?

At the end, regarding the ActiveMQ distribution, it will be a dependency like another (like Jetty or Rome for instance).

Your concern is about the "embedded" ActiveMQ service in application (BrokerService) ?

@jeanouii
Copy link
Contributor

jeanouii commented Mar 11, 2026

@mattrpav Using LinkedHashSet is a nice to have but not strictly required per spec. Actually Subject.getPrincipals() returns a Set, that's it. The rest is platform dependant. Our JaasAuthenticationBroker for instance gets all the principals and then iterates until it finds an instance of UserPrincipal.
The other login modules all rely on HashSet, so it is now inconsistent with other ActiveMQ LoginModule.

On the dependency, it will be in the final zip anyways, so until it becomes a problem, I'd prefer to keep in in activemq-jaas instead of creating another module for one class only. It is both simpler for us and for our users that don't have to know they need another module to use oauth2 tokens. We could go like this and if it's a problem split later on.
Jasypt is there as optional as well, so it's similar here. It won't be pulled as transitive dependency.
On the other hand, we have a full independant shiro module. Both are valid, Shiro has much more code, so that's understandable. activemq-jaas-oauth2 definitely makes sense, but it's one class for now so splitting now just makes it harder for us.

@jbonofre jbonofre linked an issue Mar 11, 2026 that may be closed by this pull request
@mattrpav
Copy link
Contributor

mattrpav commented Mar 14, 2026

but it's one class for now so splitting now just makes it harder for us.

I think this line of thinking 'it's just one class' is what gets us into dependency trouble as a project. Yes, it is one class in the ActiveMQ tree, but this pulls in several transitive dependencies-- not just the one listed as optional. Being a security-related component also increases the probability that it will get tagged w/ a vulnerability (or one of its transitive deps will).

I think it would be most correct to have separate modules per security mechanism (the shiro appoarch). We could do an activemq-jaas-extras, but that doesn't seem to make sense b/c rarely are multiple external security providers (used outside of local accounts).

@jbonofre
Copy link
Member Author

@mattrpav that's fair. I'm not a big fan of activemq-jaas-extras, I would prefer to have activemq-jaas-oauth2.

I will update the PR accordingly.

…h2 module

Extract OAuth2 JWT authentication into its own activemq-oauth2 module
(similar to activemq-shiro) with package org.apache.activemq.oauth2.
Remove nimbus-jose-jwt dependency from activemq-jaas and assembly,
add activemq-oauth2 to parent modules/dependencyManagement and assembly.
Include commented-out OAuth2 configuration example in the distribution
login.config.
@jbonofre
Copy link
Member Author

@jeanouii @mattrpav I moved the OAuth2LoginModule in a dedicated activemq-oauth2 module.

@jbonofre jbonofre requested review from jeanouii and mattrpav March 14, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OAuth2 support

3 participants