fix(core-authentication): authentication request

This commit is contained in:
Wroud
2020-09-08 19:05:18 +03:00
parent 2353643c1b
commit a63e0c99f2
4 changed files with 34 additions and 22 deletions
@@ -91,7 +91,7 @@ export class ServerConfigurationService {
try {
await this.graphQLService.gql.setDefaultNavigatorSettings({ settings: this.state.navigatorConfig });
await this.graphQLService.gql.configureServer({ configuration: this.state.serverConfig });
this.usersResource.refreshAll();
this.usersResource.refreshAllLazy();
} catch (exception) {
this.notificationService.logException(exception, 'Can\'t save server configuration');
@@ -175,6 +175,11 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
return this.data;
}
refreshAllLazy() {
this.markOutdated('all');
this.metadata.set('all', false);
}
protected async loader(key: ResourceKey<string>): Promise<Map<string, AdminUserInfo>> {
const userId = key === 'all' ? undefined : key as string;
@@ -13,7 +13,6 @@ import { injectable, Bootstrap } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { ServerService } from '@cloudbeaver/core-root';
import { AuthenticationService } from './AuthenticationService';
import { AuthDialogService } from './Dialog/AuthDialogService';
import { UserInfo } from './UserInfo';
@@ -24,7 +23,6 @@ export class AuthMenuService extends Bootstrap {
private authDialogService: AuthDialogService,
private authInfoService: AuthInfoService,
private settingsMenuService: SettingsMenuService,
private authenticationService: AuthenticationService,
private notificationService: NotificationService,
private topNavService: TopNavService,
private administrationTopAppBarService: AdministrationTopAppBarService,
@@ -64,7 +62,6 @@ export class AuthMenuService extends Bootstrap {
private async logout() {
try {
await this.authInfoService.logout();
await this.authenticationService.auth();
} catch (exception) {
this.notificationService.logException(exception, 'Can\'t logout');
}
@@ -8,14 +8,16 @@
import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { injectable, Bootstrap } from '@cloudbeaver/core-di';
import { ServerService } from '@cloudbeaver/core-root';
import { ServerService, SessionService } from '@cloudbeaver/core-root';
import { AuthDialogService } from './Dialog/AuthDialogService';
@injectable()
export class AuthenticationService extends Bootstrap {
private authenticating = false;
constructor(
private serverService: ServerService,
private sessionService: SessionService,
private authDialogService: AuthDialogService,
private authInfoService: AuthInfoService,
) {
@@ -23,29 +25,37 @@ export class AuthenticationService extends Bootstrap {
}
async auth() {
const config = await this.serverService.config.load(null);
if (!config) {
throw new Error('Can\'t configure Authentication');
}
if (!config.authenticationEnabled) {
if (this.authenticating) {
return;
}
this.authenticating = true;
try {
const config = await this.serverService.config.load(null);
if (!config) {
throw new Error('Can\'t configure Authentication');
}
const userInfo = await this.authInfoService.updateAuthInfo();
if (userInfo) {
return;
}
if (!config.authenticationEnabled) {
return;
}
if (!config.anonymousAccessEnabled) {
await this.authDialogService.showLoginForm(true);
const userInfo = await this.authInfoService.updateAuthInfo();
if (userInfo) {
return;
}
if (!config.anonymousAccessEnabled) {
await this.authDialogService.showLoginForm(true);
}
} finally {
this.authenticating = false;
}
}
register(): void | Promise<void> { }
load() {
// we do not await it because to unblock app loading
this.auth();
register(): void | Promise<void> {
this.serverService.config.onDataUpdate.subscribe(this.auth.bind(this));
this.sessionService.session.onDataUpdate.subscribe(this.auth.bind(this));
}
load() { }
}