Skip to content

Commit

Permalink
fix(core): Persist CurrentAuthenticationMethod setting change (#5762)
Browse files Browse the repository at this point in the history
* limit user invites when saml is enabled

* persist CurrentAuthenticationMethod
  • Loading branch information
flipswitchingmonkey committed Mar 23, 2023
1 parent 57748b7 commit 4498c60
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/sso/saml/saml.service.ee.ts
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/sso/saml/samlHelpers.ts
Expand Up @@ -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');
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/sso/ssoHelpers.ts
@@ -1,4 +1,5 @@
import config from '@/config';
import * as Db from '@/Db';
import type { AuthProviderType } from '@/databases/entities/AuthIdentity';

export function isSamlCurrentAuthenticationMethod(): boolean {
Expand All @@ -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,
});
}

0 comments on commit 4498c60

Please sign in to comment.