fix(core): Persist CurrentAuthenticationMethod setting change (#5762)

* limit user invites when saml is enabled

* persist CurrentAuthenticationMethod
This commit is contained in:
Michael Auerswald 2023-03-23 15:13:05 +01:00 committed by GitHub
parent 57748b71e5
commit 4498c6013d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -210,7 +210,7 @@ export class SamlService {
}
this._samlPreferences.metadata = prefs.metadata;
}
setSamlLoginEnabled(prefs.loginEnabled ?? isSamlLoginEnabled());
await setSamlLoginEnabled(prefs.loginEnabled ?? isSamlLoginEnabled());
setSamlLoginLabel(prefs.loginLabel ?? getSamlLoginLabel());
this.getIdentityProviderInstance(true);
const result = await this.saveSamlPreferencesToDb();

View file

@ -28,15 +28,15 @@ export function getSamlLoginLabel(): string {
}
// can only toggle between email and saml, not directly to e.g. ldap
export function setSamlLoginEnabled(enabled: boolean): void {
export async function setSamlLoginEnabled(enabled: boolean): Promise<void> {
if (enabled) {
if (isEmailCurrentAuthenticationMethod()) {
config.set(SAML_LOGIN_ENABLED, true);
setCurrentAuthenticationMethod('saml');
await setCurrentAuthenticationMethod('saml');
}
} else {
config.set(SAML_LOGIN_ENABLED, false);
setCurrentAuthenticationMethod('email');
await setCurrentAuthenticationMethod('email');
}
}

View file

@ -1,4 +1,5 @@
import config from '@/config';
import * as Db from '@/Db';
import type { AuthProviderType } from '@/databases/entities/AuthIdentity';
export function isSamlCurrentAuthenticationMethod(): boolean {
@ -17,6 +18,12 @@ export function doRedirectUsersFromLoginToSsoFlow(): boolean {
return config.getEnv('sso.redirectLoginToSso');
}
export function setCurrentAuthenticationMethod(authenticationMethod: AuthProviderType): void {
export async function setCurrentAuthenticationMethod(
authenticationMethod: AuthProviderType,
): Promise<void> {
config.set('userManagement.authenticationMethod', authenticationMethod);
await Db.collections.Settings.save({
key: 'userManagement.authenticationMethod',
value: authenticationMethod,
});
}