Skip to content

Commit 90f7d6d

Browse files
veigapclaude
andcommitted
feat(auth): disable local login and registration when OIDC is configured
Once the generic OpenID Connect provider (registration id "oidc") is configured it becomes the way users sign in, so the identity provider's policies (MFA, password rules...) apply to every login (#67): - LocalLoginPolicy decides; local login is enabled only while no oidc client-id is configured. - The database AuthenticationProvider refuses email/password login with LocalLoginDisabledException. Checked in the provider, not the controller, so HTTP Basic (app.api.http-basic-enabled) is covered too. /authenticate maps it to a 401 with the localized LOCAL_LOGIN_DISABLED message (added to every bundle). - Self-registration is refused regardless of app.registration.enabled. - Password reset sends no link and answers OAUTH2_USER. - /api/restful/app/config exposes localLoginEnabled and reports registrationEnabled=false, so the login page can hide the form. Existing local accounts, the admin included, keep their maps by signing in through the identity provider and confirming the link once. Google, Facebook and LDAP logins are unaffected. Documented as the expected behaviour in doc/oidc/README.md, the application.yml comment, the Docker README, CLAUDE.md and the CHANGELOG. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 0835479 commit 90f7d6d

31 files changed

Lines changed: 337 additions & 10 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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`
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`. Once configured, OIDC becomes the way users sign in, so the identity provider's policies (MFA, password rules…) apply to every login ([#67](https://github.com/wisemapping/wisemapping-open-source/issues/67)): email/password login of local accounts (form and HTTP Basic), self-registration and password reset are disabled, and `/api/restful/app/config` exposes `localLoginEnabled: false` so the login page can hide the form. Accounts are created on first OIDC login; existing local accounts, the admin included, keep their maps by signing in with the same email and confirming the link once. Google, Facebook and LDAP logins are unaffected. Setup guide: `doc/oidc/README.md`
2525

2626
#### Bug Fixes
2727
- **[#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

‎CLAUDE.md‎

Lines changed: 1 addition & 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, 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.
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. Configuring `oidc` disables database email/password login, self-registration and password reset by design (`LocalLoginPolicy`), so every login goes through the identity provider.
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.

‎distribution/app/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ docker run -d --name wisemapping -p 80:80 \
222222

223223
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.
224224

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.
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. Once it is configured, users can only sign in through your identity provider: email/password login and sign-up are disabled.
226226
- **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.
227227

228228
Behind HTTPS, these logins need the reverse-proxy settings below.

‎doc/oidc/README.md‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,26 @@ The provider is configured with standard Spring Security properties under the re
2323
> **verified** e-mail addresses. If its users can sign up or change their e-mail without
2424
> verifying it, they can sign in as any WiseMapping user with that address, the admin included.
2525
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.
26+
## Local login is disabled
27+
28+
Once the `oidc` registration is configured, the identity provider is **the** way to sign in.
29+
This is the expected behaviour, not an option, so the provider's policies (MFA, password rules,
30+
account lockout…) apply to every login:
31+
32+
- **Email/password login is disabled** for local (`DATABASE`) accounts, through the login form
33+
and through HTTP Basic (`app.api.http-basic-enabled`). The login page hides the form
34+
(`/api/restful/app/config` returns `localLoginEnabled: false`).
35+
- **Self-registration is disabled**, whatever `app.registration.enabled` says. Accounts are
36+
created on each user's first OIDC login instead.
37+
- **Password reset sends no e-mail**; the user is told to sign in with the external provider.
38+
- **Existing local accounts keep their maps.** Their owners sign in with the identity provider
39+
using the same e-mail and confirm the link once (see step 3 above). This includes the admin:
40+
the account named by `app.admin.user` must exist in the identity provider with that e-mail.
41+
- Google and Facebook login, when configured, keep working. LDAP is not affected.
42+
- Sessions opened with a password before OIDC was configured stay valid until their token
43+
expires (`app.jwt.expirationMin`, 7 days by default).
44+
45+
To go back to email/password login, remove the `oidc` registration.
2946

3047
## Configuration
3148

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* This configuration sets up authentication providers for the application.
3232
* It supports multiple authentication methods:
3333
*
34-
* 1. DATABASE Authentication (always enabled)
34+
* 1. DATABASE Authentication (disabled when OpenID Connect is configured, see LocalLoginPolicy)
3535
* - Traditional username/password authentication against WiseMapping's database
3636
* - Users with AuthenticationType.DATABASE
3737
*
@@ -79,6 +79,9 @@ public class SecurityConfig {
7979
@Autowired
8080
private LdapProperties ldapProperties;
8181

82+
@Autowired
83+
private LocalLoginPolicy localLoginPolicy;
84+
8285
@Autowired
8386
@Lazy
8487
private UserService userService;
@@ -120,6 +123,7 @@ public AuthenticationProvider dbAuthenticationProvider() {
120123
provider.setEncoder(passwordEncoder());
121124
provider.setUserDetailsService(userDetailsService);
122125
provider.setMetricsService(metricsService);
126+
provider.setLocalLoginPolicy(localLoginPolicy);
123127

124128
logger.info("DATABASE authentication provider initialized");
125129
return provider;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright [2007-2025] [wisemapping]
3+
*
4+
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
5+
* It is basically the Apache License, Version 2.0 (the "License") plus the
6+
* "powered by wisemapping" text requirement on every single page;
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the license at
9+
*
10+
* https://github.com/wisemapping/wisemapping-open-source/blob/main/LICENSE.md
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.wisemapping.exceptions;
19+
20+
import org.springframework.security.core.AuthenticationException;
21+
22+
/**
23+
* Raised when a local account tries to sign in with email and password while OpenID Connect
24+
* is configured (see {@link com.wisemapping.security.LocalLoginPolicy}).
25+
*/
26+
public class LocalLoginDisabledException extends AuthenticationException {
27+
28+
public LocalLoginDisabledException(String message) {
29+
super(message);
30+
}
31+
}

‎wise-api/src/main/java/com/wisemapping/exceptions/UserCouldNotBeAuthException.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class UserCouldNotBeAuthException extends ClientException {
2626
private static final String MSG_ACCOUNT_SUSPENDED = "ACCOUNT_SUSPENDED";
2727
private static final String MSG_ACCOUNT_SUSPENDED_INACTIVITY = "ACCOUNT_SUSPENDED_INACTIVITY";
2828
private static final String MSG_ACCOUNT_DISABLED = "ACCOUNT_DISABLED";
29+
private static final String MSG_LOCAL_LOGIN_DISABLED = "LOCAL_LOGIN_DISABLED";
2930

3031
private final String msgKey;
3132

@@ -69,6 +70,10 @@ public static UserCouldNotBeAuthException accountDisabled(Throwable cause) {
6970
return new UserCouldNotBeAuthException(MSG_ACCOUNT_DISABLED, "Account disabled: " + cause.getMessage(), cause);
7071
}
7172

73+
public static UserCouldNotBeAuthException localLoginDisabled(Throwable cause) {
74+
return new UserCouldNotBeAuthException(MSG_LOCAL_LOGIN_DISABLED, "Local login disabled: " + cause.getMessage(), cause);
75+
}
76+
7277
@NotNull
7378
@Override
7479
protected String getMsgBundleKey() {

‎wise-api/src/main/java/com/wisemapping/rest/AppController.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.wisemapping.rest;
2020

2121
import com.wisemapping.rest.model.RestAppConfig;
22+
import com.wisemapping.security.LocalLoginPolicy;
2223
import org.springframework.beans.factory.annotation.Autowired;
2324
import org.springframework.beans.factory.annotation.Value;
2425
import org.springframework.core.env.Environment;
@@ -59,6 +60,9 @@ public class AppController {
5960
@Value("${app.oauth.oidc.label:Single Sign-On}")
6061
private String oidcLabel;
6162

63+
@Autowired
64+
private LocalLoginPolicy localLoginPolicy;
65+
6266
@RequestMapping(method = RequestMethod.GET, value = "/config")
6367
@ResponseStatus(value = HttpStatus.OK)
6468
public RestAppConfig appConfig() {
@@ -76,7 +80,9 @@ public RestAppConfig appConfig() {
7680
.setFacebookOauth2Enabled(facebookEnabled)
7781
.setOidcOauth2Enabled(oidcEnabled)
7882
.setAnalyticsAccount(analyticsAccount)
79-
.setRegistrationEnabled(isRegistrationEnabled)
83+
// Local login and registration are off while OpenID Connect is configured.
84+
.setLocalLoginEnabled(localLoginPolicy.isLocalLoginEnabled())
85+
.setRegistrationEnabled(isRegistrationEnabled && localLoginPolicy.isLocalLoginEnabled())
8086
.setJwtExpirationMin(jwtExpirationMin);
8187

8288
// Only set OAuth2 URLs if providers are configured

‎wise-api/src/main/java/com/wisemapping/rest/JwtAuthController.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.wisemapping.exceptions.AccountDisabledException;
2222
import com.wisemapping.exceptions.AccountSuspendedException;
2323
import com.wisemapping.exceptions.AccountSuspendedInactivityException;
24+
import com.wisemapping.exceptions.LocalLoginDisabledException;
2425
import com.wisemapping.exceptions.UserCouldNotBeAuthException;
2526
import com.wisemapping.exceptions.WiseMappingException;
2627
import com.wisemapping.model.Account;
@@ -128,6 +129,9 @@ private String authenticate(@NotNull String username, @NotNull String password)
128129
} catch (AccountSuspendedException e) {
129130
// Account is suspended
130131
throw UserCouldNotBeAuthException.accountSuspended(e);
132+
} catch (LocalLoginDisabledException e) {
133+
// OpenID Connect is configured: local accounts must use the Single Sign-On button
134+
throw UserCouldNotBeAuthException.localLoginDisabled(e);
131135
} catch (AccountDisabledException e) {
132136
// Account is disabled/not activated (email not confirmed for DATABASE users)
133137
throw UserCouldNotBeAuthException.accountDisabled(e);

‎wise-api/src/main/java/com/wisemapping/rest/UserController.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.wisemapping.rest.model.RestPasswordResetRequest;
2929
import com.wisemapping.rest.model.RestResetPasswordResponse;
3030
import com.wisemapping.rest.model.RestUserRegistration;
31+
import com.wisemapping.security.LocalLoginPolicy;
3132
import com.wisemapping.service.DisposableEmailService;
3233
import com.wisemapping.service.InvalidUserEmailException;
3334
import com.wisemapping.service.MetricsService;
@@ -78,6 +79,9 @@ public class UserController {
7879
@Value("${app.registration.enabled:true}")
7980
private Boolean registrationEnabled;
8081

82+
@Autowired
83+
private LocalLoginPolicy localLoginPolicy;
84+
8185
@Value("${app.registration.email-confirmation-enabled:true}")
8286
private Boolean emailConfirmationEnabled;
8387

@@ -96,6 +100,9 @@ public void registerUser(@RequestBody RestUserRegistration registration,
96100
if (!registrationEnabled) {
97101
throw new WiseMappingException("Registration is disabled. You can enable it using app.registration.enabled");
98102
}
103+
if (!localLoginPolicy.isLocalLoginEnabled()) {
104+
throw new WiseMappingException("Registration is disabled: users sign in through OpenID Connect");
105+
}
99106

100107
if (!registration.isAcceptedTerms()) {
101108
throw new WiseMappingException("You must accept the Terms of Use and Privacy Policy to register.");

0 commit comments

Comments
 (0)