Skip to content

JSPWIKI-1375 Make the OpenID Connect login work with any OpenID Connect provider - #644

Draft
arturobernalg wants to merge 4 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1375-generic-oidc
Draft

arturobernalg wants to merge 4 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1375-generic-oidc

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

The OpenID Connect login of #643 uses the Keycloak client of pac4j and its roles generator, so it works only with Keycloak. This makes it work with any OpenID Connect provider, as Google or Microsoft Entra ID (Azure), which speak standard OpenID Connect.

This depends on #643, so the commits of that PR are included here. The new one is the last: JSPWIKI-1375 Make the OpenID Connect login work with any OpenID Connect provider. When #643 is merged I will rebase this on master.

cc @spyhunter99 @juanpablo-santos

What changes:

  • The generic OpenID Connect client of pac4j is configured with the discovery address of the provider, instead of the Keycloak client with its realm and base address.
  • The claim with the name of the user is configurable (oidc.usernameClaim, preferred_username by default, then the e-mail address, then the identifier of the user at the provider).
  • The claim with the roles is configurable (oidc.rolesClaim). It is searched in the profile and in the access token when this is a JWT, and it may be a dotted path through nested claims: realm_access.roles for Keycloak, roles for the application roles of Azure.
  • An optional mapping (oidc.roleMapping) turns the values of that claim into roles of the wiki, for the providers that send identifiers instead of names.
  • The callback address has no parameters, so it can be registered as is in the provider; Azure and Google need an exact address.
  • The README describes the settings, and the configuration for Keycloak, Azure and Google.

I checked it with a real Keycloak used as a generic provider, the wiki with its pages in Tomcat, and two configurations:

  • Keycloak style (oidc.rolesClaim=realm_access.roles): a normal user logs in and gets 403 on a page that needs Admin; the administrator sees it. Log out returns to the wiki, and Keycloak asks for the credentials again.
  • Azure and Google style (oidc.usernameClaim=email, oidc.rolesClaim=roles with a flat claim, and oidc.roleMapping=Authenticated=Admin): the wiki shows the e-mail address as the name, and the normal user, who got the 403 before, sees the Admin page, so the role mapping works.
  • The unit tests of the new classes pass (18 in the module).

I did not try it with Google or Azure themselves, as that needs an application registered in each. The configurations in the README follow what those providers document.

A new jspwiki-oidc module uses the pac4j filters to send the user to the identity provider and a filter that presents the logged in user to the wiki as a container login. The wiki recognizes the user as authenticated without changes in its authentication code. Work in progress, not ready for review.
…d a test

The filters of the proof of concept are commented out in web.xml, as the container managed authentication section is, and the war does not include the module. Adds the ChangeLog entry and a test of the request wrapper.
…onnect module

OidcAuthorizer declares that the container handles the login and takes the roles from the property jspwiki.oidc.roles, so Login.jsp and the roles of the identity provider work as with a container login. The logout filter ends the session of the identity provider and returns to the wiki. The war includes the module with the profile oidc. Adds the tests of the authorizer and a description of how to enable it.
…ct provider

The login used the Keycloak client of pac4j and its roles generator. It now uses the generic OpenID Connect client, configured with the discovery address of the provider. The claim with the name of the user, the claim with the roles, which may be a dotted path and is read from the profile and from the access token, and a mapping from the values of that claim to roles of the wiki are configurable. The callback address has no parameters, so it can be registered as is in the provider. Adds the tests of the new classes and the description of the configuration for Keycloak, Azure and Google.
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.

1 participant