Skip to content

Commit 0835479

Browse files
Fguarienclaudeveigap
authored
feat(auth): generic OpenID Connect login provider (#76)
* feat(auth): generic OpenID Connect login provider Add a generic OIDC provider next to Google and Facebook, configured with standard Spring Security properties under the registration id "oidc" (issuer discovery, Keycloak / Authentik / Okta / Entra ID...). - AuthenticationType.OIDC ('O'); accounts get no local password. - OAuth2 success handler and account-sync confirmation map "oidc". - The success redirect names the provider (&provider=...), so the frontend confirms an account link for the provider that signed in instead of assuming Google. - /api/restful/app/config exposes oidcOauth2Enabled, oidcOauth2Url and oidcOauth2Label (app.oauth.oidc.label, default "Single Sign-On"). - First OIDC login provisions the account even when app.registration.enabled=false. - doc/oidc/README.md, application.yml examples, messages in every locale. - Tests: RestAppControllerOidcTest, OidcProvisioningTest, AuthenticationTypeTest, RestAppConfigTest, RestAppControllerTest. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(distribution): proxy OAuth2 login paths to the API in the app image The combined image only proxied /api/ to Spring Boot, so /oauth2/authorization/{id} and /login/oauth2/code/{id} were answered by the SPA fallback and no OAuth2 login (Google, Facebook or OIDC) could complete. Proxy both prefixes, with the forwarded headers Spring needs to rebuild the public redirect_uri behind a reverse proxy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(auth): match OAuth2 emails ignoring case and reject logins without email - Look up the account by exact email first (index-backed), then fall back to a case-insensitive match. Identity providers such as Entra ID return mixed-case emails, which created a second account instead of signing in to the existing one. A login matching several accounts that differ only in case is refused. - Reject a login whose provider releases no email claim, with a log message naming the cause, instead of an unexplained oauth_failed. - Docs: the Docker README links to doc/oidc/README.md instead of duplicating it, replaces the Google example that used keys no code reads, and documents the X-Forwarded-Proto header needed behind HTTPS. The OIDC guide gains a setup check and a verified-email warning. - CHANGELOG entries for OIDC login and the related fixes; CLAUDE.md now requires changes to be documented in the changelog and the owning doc. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Paulo Gustavo Veiga <pveiga@wisemapping.com>
1 parent 2e802af commit 0835479

34 files changed

Lines changed: 744 additions & 13 deletions

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ All notable changes to the Wisemapping Frontend project are documented in this f
2121
- **Robust Reset Password**: Replaced the previous reset-password flow with a secure link-based mechanism — a time-limited signed token is emailed to the user; clicking the link opens a dedicated reset form, eliminating the possibility of replay or enumeration attacks
2222
- **Arabic Language Support**: Added Arabic (`ar`) to the supported server-side message bundles, enabling fully localized error messages and email templates for Arabic-speaking users
2323
- **MariaDB Native Support**: Added first-class MariaDB support with the native JDBC driver and dialect, dedicated `schema-mariadb.sql` / `data-mariadb.sql` seed files, and a ready-to-run `distribution/app-mariadb/` Docker Compose overlay
24+
- **Generic OpenID Connect Login**: Self-hosted instances can delegate sign-in to their own identity provider (Keycloak, Authentik, Authelia, Okta, Entra ID, Zitadel…) through the standard `spring.security.oauth2.client` settings under the registration id `oidc`; endpoints are discovered from `issuer-uri`. Off unless configured. The login button label comes from `app.oauth.oidc.label`, and the first login provisions the account even with `app.registration.enabled=false`, so an instance can let users in only through its identity provider. Accounts are matched by email; an existing password account is linked after a one-time confirmation. Setup guide: `doc/oidc/README.md`
2425

2526
#### Bug Fixes
2627
- **[#69](https://github.com/wisemapping/wisemapping-open-source/issues/69)**: Normalized database identifiers and data types across MySQL, MariaDB, PostgreSQL and HSQLDB; all JPA entity table names and the schema files are now lowercase so deployments on case-sensitive Linux filesystems behave identically to macOS/Windows
2728
- **[#70](https://github.com/wisemapping/wisemapping-open-source/issues/70)**: Fixed the 6.0.8 Docker image failing at startup with `ModuleNotFoundError: No module named 'xmlrpclib'`; the container now uses `tini` as PID 1 with a small shell launcher instead of the broken Alpine supervisor + Python combination, removing Python from the runtime image entirely
29+
- **OAuth2 Login in the Docker Image**: Google and Facebook login could not complete in `wisemapping/wisemapping`: nginx only proxied `/api/` to the API, so `/oauth2/authorization/{id}` and the provider callback `/login/oauth2/code/{id}` fell through to the frontend. Both paths are now proxied with the forwarded headers Spring needs to rebuild the public redirect URI
30+
- **OAuth2 Email Case**: An OAuth2/OIDC login whose email differed only in case from an existing account (identity providers such as Entra ID return `John.Doe@Example.com`) created a second account instead of signing in to the existing one. Accounts are now matched ignoring case, and a login that matches several accounts differing only in case is refused
31+
- **OAuth2 Missing Email Claim**: A provider that releases no `email` claim now fails the login with a log message naming the cause, instead of an unexplained `oauth_failed`
32+
- **Docker Docs – Google Login Keys**: The Docker Hub page configured Google login with `app.security.oauth2.google.*`, keys no code reads, so following it produced no login button. It now points to the `spring.security.oauth2.client` settings and documents the `X-Forwarded-Proto` header the reverse proxy must forward for OAuth2 logins behind HTTPS
2833

2934
#### Maintenance
3035
- **Java 26**: Moved the build and both runtime images from Java 24 to Java 26. Java 24 stopped receiving updates in September 2025 — its `eclipse-temurin:24-jre-alpine` base image had not been rebuilt since August 2025, so neither JVM nor Alpine security patches were reaching the published containers. Building from source now requires JDK 26 or higher. The compiled classes had stayed on Java 17 bytecode: Spring Boot's parent compiles with `release=${java.version}` (default 17), which overrides `maven.compiler.source`/`target`, so the version is now set through `java.version`. JaCoCo moved 0.8.13 → 0.8.15 to read Java 26 class files: 0.8.13 failed to instrument every Mockito mock with `Unsupported class file major version 70`

‎CLAUDE.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Default seed credentials in dev: `test@wisemapping.org` / `test`.
4242

4343
Key namespaces (read `application.yml` before changing behavior):
4444
- `spring.datasource` — defaults to embedded HSQLDB. Switch to `postgresql`/`mysql`/`mariadb` by overriding driver/url/username/password; the matching `schema-*.sql` and `data-*.sql` under `src/main/resources/` are auto-applied. Reference overlays live under `distribution/app-{postgresql,mysql,mariadb}/app.yml`.
45-
- `spring.security.oauth2.client` — Google/Facebook OAuth2; client IDs/secrets are expected to be supplied via overlay.
45+
- `spring.security.oauth2.client` — Google/Facebook OAuth2, plus a generic OpenID Connect provider under the registration id `oidc` (see `doc/oidc/README.md`); client IDs/secrets are expected to be supplied via overlay.
4646
- `spring.ldap` + `app.security.ldap` — LDAP auth (see `doc/ldap/README.md`). Disabled by default.
4747
- `app.jwt` — JWT signing key + expiration (used by `JwtTokenUtil`, `JwtAuthController`).
4848
- `app.site.*` — base URLs the API embeds in emails and OAuth redirects.
@@ -129,7 +129,13 @@ To ensure cross-platform consistency and resolve encoding/case-sensitivity issue
129129

130130
**Tests** — JUnit 5 (`junit-vintage-engine` is excluded; don't import JUnit 4). Spring Boot test slices preferred over full-context tests when possible. Test class naming mirrors the SUT: `FooService` → `FooServiceTest`.
131131

132+
**Documenting changes** — a change is not done until it is documented.
133+
- **Changelog**: every functional change (feature, bug fix, security fix, breaking change, behavior or configuration change an operator would notice) adds an entry under `## [Unreleased]` → `### 🔧 Backend (wisemapping-open-source)` in `CHANGELOG.md`, in the matching `Security & Privacy` / `Features` / `Bug Fixes` / `Maintenance` subsection. Follow the existing style: a bold title, then what changed and why it matters to users or operators. Pure refactors and test-only changes need no entry. Use the `update-changelog` skill to regenerate the section before a release.
134+
- **Docs**: a change to configuration, deployment or authentication updates the doc that owns the topic (`doc/<topic>/README.md`, `distribution/<variant>/README.md`, the comments in `application.yml`). Keep one source per topic and link to it rather than copying it. `distribution/app/README.md` is the Docker Hub page: keep it short, link to the repo with absolute GitHub URLs, and paste it to Docker Hub by hand at release (no workflow syncs it).
135+
- **Breaking changes** (removed features, config keys, data migrations) also need upgrade instructions in the changelog entry.
136+
132137
## Documentation pointers
133138

134139
- `doc/api-documentation/` — REST API reference + backend specifics (telemetry, OpenAPI).
140+
- `doc/oidc/README.md` — generic OpenID Connect login (Keycloak, Authentik, Okta...).
135141
- `doc/ldap/README.md` — LDAP setup. The `app.security.ldap` block in `application.yml` is heavily commented and is the source of truth.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ WiseMapping provides a comprehensive set of features for creating, managing and
4949

5050
### 🔐 Accounts & administration
5151

52-
- **Authentication**: Database accounts, Google and Facebook OAuth2, and LDAP, with JWT-based sessions
52+
- **Authentication**: Database accounts, Google and Facebook OAuth2, any OpenID Connect provider ([doc/oidc](doc/oidc/README.md)), and LDAP, with JWT-based sessions
5353
- **Account self-service**: Registration with optional reCAPTCHA, email activation, link-based password reset, and account deletion
5454
- **Admin console**: Account management and system status pages for administrators
5555
- **Spam & abuse controls**: Spam detection on write and as a scheduled batch, with automatic user suspension

‎distribution/app/README.md‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,6 @@ app:
207207
port: 587
208208
username: your_email@example.com
209209
password: your_password
210-
security:
211-
oauth2:
212-
google:
213-
enabled: true
214-
clientId: YOUR_CLIENT_ID
215-
clientSecret: YOUR_CLIENT_SECRET
216210
site:
217211
ui-base-url: https://your-domain.com
218212
api-base-url: https://your-domain.com
@@ -224,9 +218,21 @@ docker run -d --name wisemapping -p 80:80 \
224218
wisemapping/wisemapping:latest
225219
```
226220

221+
### Login with OpenID Connect, Google or Facebook
222+
223+
Users can sign in through your own identity provider (Keycloak, Authentik, Authelia, Okta, Microsoft Entra ID, ...) or with Google or Facebook. These logins are off until you configure them with the standard `spring.security.oauth2.client` settings, either in the mounted `application.yml` or as environment variables.
224+
225+
- **OpenID Connect**: follow the [setup guide](https://github.com/wisemapping/wisemapping-open-source/blob/main/doc/oidc/README.md). It covers configuration, how to check that it works, and troubleshooting.
226+
- **Google and Facebook**: copy the commented `spring.security.oauth2.client` block from [application.yml](https://github.com/wisemapping/wisemapping-open-source/blob/main/wise-api/src/main/resources/application.yml) into your configuration.
227+
228+
Behind HTTPS, these logins need the reverse-proxy settings below.
229+
227230
### SSL/HTTPS with Reverse Proxy
228231

229-
Place WiseMapping behind a reverse proxy (Traefik, Nginx, etc.) for SSL/HTTPS termination. Ensure the reverse proxy forwards the original `Host` header (including port) to the container.
232+
Place WiseMapping behind a reverse proxy (Traefik, Nginx, etc.) for SSL/HTTPS termination. The reverse proxy must forward:
233+
234+
- the original `Host` header (including port);
235+
- `X-Forwarded-Proto: https`. Without it, WiseMapping builds `http://` redirect URIs and OpenID Connect, Google and Facebook logins fail with a `redirect_uri` mismatch. Traefik and Caddy send it by default; with Nginx add `proxy_set_header X-Forwarded-Proto $scheme;`.
230236

231237
## Troubleshooting
232238

‎distribution/app/nginx.conf‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ server {
6060
proxy_read_timeout 60s;
6161
}
6262

63+
# OAuth2 / OpenID Connect login (Google, Facebook, generic OIDC). Spring Security serves the
64+
# authorization redirect (/oauth2/authorization/{id}) and the provider callback
65+
# (/login/oauth2/code/{id}); without these locations both fall through to the SPA.
66+
# The forwarded headers let Spring rebuild the public redirect_uri behind a reverse proxy.
67+
location ~ ^/(oauth2|login/oauth2)/ {
68+
proxy_set_header X-Real-IP $remote_addr;
69+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
70+
proxy_set_header X-Forwarded-Proto $base_scheme;
71+
proxy_set_header X-Forwarded-Host $http_host;
72+
proxy_set_header Host $http_host;
73+
proxy_pass http://localhost:8080;
74+
proxy_redirect off;
75+
}
76+
6377
# Health check endpoint
6478
location /health {
6579
access_log off;

‎doc/oidc/README.md‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Generic OpenID Connect (OIDC) login
2+
3+
WiseMapping can delegate sign-in to any OpenID Connect provider — Keycloak, Authentik,
4+
Authelia, Okta, Microsoft Entra ID, Zitadel, … — next to (or instead of) Google and Facebook.
5+
The provider is configured with standard Spring Security properties under the registration id
6+
**`oidc`**; nothing is enabled unless that registration exists.
7+
8+
## How it works
9+
10+
1. The login page shows a **"Sign in with {label}"** button when `/api/restful/app/config`
11+
returns `oidcOauth2Enabled: true`. The label comes from `app.oauth.oidc.label`.
12+
2. The button opens `{api-base-url}/oauth2/authorization/oidc`; Spring Security runs the
13+
authorization-code flow against the provider.
14+
3. On the callback (`{api-base-url}/login/oauth2/code/oidc`) the user is matched **by e-mail**
15+
(ignoring case; a login whose e-mail matches several accounts that differ only in case is refused):
16+
- **no account** → an account of type `OIDC` is created (no local password);
17+
- **an `OIDC` account** → signed in;
18+
- **a local (`DATABASE`) account** → the user is asked to confirm the link once; the account
19+
then becomes `OIDC` and its local password is cleared;
20+
- **an account bound to another provider** (Google, Facebook, LDAP) → refused.
21+
22+
> **Security** — because accounts are matched by e-mail, the provider must only issue
23+
> **verified** e-mail addresses. If its users can sign up or change their e-mail without
24+
> verifying it, they can sign in as any WiseMapping user with that address, the admin included.
25+
26+
Provisioning on first login does **not** depend on `app.registration.enabled`: an instance that
27+
lets only its identity provider in can close the public sign-up form
28+
(`app.registration.enabled: false`) and still create accounts on first OIDC login.
29+
30+
## Configuration
31+
32+
Endpoints are discovered from the issuer (`<issuer-uri>/.well-known/openid-configuration`).
33+
34+
```yaml
35+
spring:
36+
security:
37+
oauth2:
38+
client:
39+
registration:
40+
oidc:
41+
client-id: wisemapping
42+
client-secret: <client secret>
43+
authorization-grant-type: authorization_code # required for a custom registration id
44+
scope: openid,profile,email
45+
redirect-uri: "${app.site.api-base-url}/login/oauth2/code/{registrationId}"
46+
provider:
47+
oidc:
48+
issuer-uri: https://sso.example.com/realms/example
49+
user-name-attribute: sub
50+
51+
app:
52+
oauth:
53+
oidc:
54+
label: Example SSO # button text: "Sign in with Example SSO"
55+
```
56+
57+
The same settings as environment variables (Docker):
58+
59+
```sh
60+
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=wisemapping
61+
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=<client secret>
62+
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_AUTHORIZATION_GRANT_TYPE=authorization_code
63+
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_SCOPE=openid,profile,email
64+
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_REDIRECT_URI={baseUrl}/login/oauth2/code/{registrationId}
65+
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=https://sso.example.com/realms/example
66+
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_USER_NAME_ATTRIBUTE=sub
67+
APP_OAUTH_OIDC_LABEL="Example SSO"
68+
```
69+
70+
The provider must return the `email` claim (scope `email`). `given_name` and `family_name`
71+
fill the account's first and last name.
72+
73+
### Keycloak
74+
75+
- Client: *OpenID Connect*, *Client authentication* on, *Standard flow* only.
76+
- Valid redirect URI: `https://wm.example.com/login/oauth2/code/oidc`.
77+
- Issuer: `https://keycloak.example.com/realms/<realm>`.
78+
79+
### Authentik
80+
81+
- Provider: *OAuth2/OpenID Provider*, client type *Confidential*, scopes `openid`, `email`,
82+
`profile`.
83+
- Redirect URI (strict): `https://wm.example.com/login/oauth2/code/oidc`.
84+
- Issuer: `https://authentik.example.com/application/o/<application-slug>/`
85+
(keep the trailing slash: it is part of the issuer Authentik announces).
86+
87+
## Checking the setup
88+
89+
1. `curl -s {api-base-url}/api/restful/app/config` must return `"oidcOauth2Enabled":true` and
90+
the label in `oidcOauth2Label`. `false` means the `client-id` setting did not reach the API.
91+
2. The login page shows the **"Sign in with {label}"** button.
92+
3. Signing in with a user of the provider brings you back to WiseMapping signed in; the first
93+
login creates the account.
94+
4. If the login fails, the API log says why (see below).
95+
96+
## Troubleshooting
97+
98+
- **`authorizationGrantType cannot be null` at startup** — add
99+
`authorization-grant-type: authorization_code`; Spring only presets it for the providers it
100+
knows (Google, Facebook, GitHub, Okta).
101+
- **`redirect_uri` mismatch** — the URI registered in the provider must be exactly
102+
`{api-base-url}/login/oauth2/code/oidc`. Behind an HTTPS reverse proxy, a mismatch on the
103+
scheme (`http://` sent instead of `https://`) means the proxy does not forward
104+
`X-Forwarded-Proto`; see
105+
[SSL/HTTPS with Reverse Proxy](../../distribution/app/README.md#sslhttps-with-reverse-proxy).
106+
- **Login fails and the log says `the provider returned no email claim`** — request the `email`
107+
scope and make sure the provider releases the claim (Microsoft Entra ID, for instance, only
108+
sends it when the optional `email` claim is configured on the app registration).
109+
- **Issuer mismatch** — `issuer-uri` must equal the `issuer` field of the discovery document,
110+
character for character.

‎wise-api/src/main/java/com/wisemapping/config/GlobalExceptionHandler.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ public RestErrors handleWrongAuthenticationTypeException(@NotNull WrongAuthentic
374374
messageKey = "ACCOUNT_USES_FACEBOOK_OAUTH";
375375
defaultMessage = "This account is registered with Facebook. Please use the 'Sign in with Facebook' button to login.";
376376
break;
377+
case OIDC:
378+
messageKey = "ACCOUNT_USES_OIDC_OAUTH";
379+
defaultMessage = "This account is registered with Single Sign-On. Please use the Single Sign-On button to login.";
380+
break;
377381
case LDAP:
378382
messageKey = "ACCOUNT_USES_EXTERNAL_AUTH";
379383
defaultMessage = "This account uses external authentication. Please use the appropriate sign-in method.";

‎wise-api/src/main/java/com/wisemapping/dao/UserManager.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public interface UserManager {
3636

3737
Account getUserBy(String email);
3838

39+
/**
40+
* Accounts whose email matches ignoring case. Not index-backed: prefer {@link #getUserBy(String)}
41+
* and use this only as a fallback when the exact lookup finds nothing.
42+
*/
43+
@NotNull
44+
List<Account> getUsersByEmailIgnoreCase(@NotNull String email);
45+
3946
Account getUserBy(int id);
4047

4148
void createUser(Account user);

‎wise-api/src/main/java/com/wisemapping/dao/UserManagerImpl.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Calendar;
4545
import java.util.Collection;
4646
import java.util.List;
47+
import java.util.Locale;
4748
import java.util.Set;
4849
import java.util.concurrent.CopyOnWriteArraySet;
4950

@@ -98,6 +99,18 @@ public Account getUserBy(@NotNull final String email) {
9899
return null;
99100
}
100101

102+
@Override
103+
@NotNull
104+
public List<Account> getUsersByEmailIgnoreCase(@NotNull final String email) {
105+
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
106+
final CriteriaQuery<Account> cq = cb.createQuery(Account.class);
107+
final Root<Account> root = cq.from(Account.class);
108+
109+
cq.select(root).where(cb.equal(cb.lower(root.get("email")), email.toLowerCase(Locale.ROOT)));
110+
111+
return entityManager.createQuery(cq).getResultList();
112+
}
113+
101114
@Override
102115
public Collaborator getCollaboratorBy(final String email) {
103116
// Use Criteria API for type-safe query that handles inheritance properly
@@ -126,7 +139,9 @@ public Account getUserBy(int id) {
126139
@Transactional
127140
public void createUser(Account user) {
128141
assert user != null : "Trying to store a null user";
129-
if (!AuthenticationType.GOOGLE_OAUTH2.equals(user.getAuthenticationType())) {
142+
// Accounts backed by an external identity provider have no local password.
143+
if (!AuthenticationType.GOOGLE_OAUTH2.equals(user.getAuthenticationType())
144+
&& !AuthenticationType.OIDC.equals(user.getAuthenticationType())) {
130145
user.setPassword(passwordEncoder.encode(user.getPassword()));
131146
} else {
132147
user.setPassword("");

‎wise-api/src/main/java/com/wisemapping/model/AuthenticationType.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public enum AuthenticationType {
2424
DATABASE('D'),
2525
LDAP('L'),
2626
GOOGLE_OAUTH2('G'),
27-
FACEBOOK_OAUTH2('F');
27+
FACEBOOK_OAUTH2('F'),
28+
OIDC('O');
2829

2930
private final char schemaCode;
3031

0 commit comments

Comments
 (0)