mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix(core-connections): CB-1252 add autofill to db auth dialog
This commit is contained in:
@@ -18,9 +18,12 @@ import type { IConnectionAuthenticationConfig } from '../ConnectionAuthenticatio
|
||||
import { ConnectionInfoResource, ConnectionInitConfig } from '../ConnectionInfoResource';
|
||||
import { DBDriverResource } from '../DBDriverResource';
|
||||
|
||||
const USER_NAME_PROPERTY_ID = 'userName';
|
||||
|
||||
@injectable()
|
||||
export class DBAuthDialogController implements IInitializableController, IDestructibleController {
|
||||
isAuthenticating = false;
|
||||
configured = false;
|
||||
config: IConnectionAuthenticationConfig = {
|
||||
credentials: {},
|
||||
networkHandlersConfig: [],
|
||||
@@ -31,6 +34,7 @@ export class DBAuthDialogController implements IInitializableController, IDestru
|
||||
|
||||
private connectionId!: string;
|
||||
private isDistructed = false;
|
||||
private networkHandlers!: string[];
|
||||
private close!: () => void;
|
||||
|
||||
constructor(
|
||||
@@ -40,16 +44,22 @@ export class DBAuthDialogController implements IInitializableController, IDestru
|
||||
private dbDriverResource: DBDriverResource
|
||||
) {
|
||||
makeObservable(this, {
|
||||
isAuthenticating: observable,
|
||||
isAuthenticating: observable.ref,
|
||||
configured: observable.ref,
|
||||
config: observable,
|
||||
});
|
||||
}
|
||||
|
||||
init(connectionId: string, onClose: () => void): void {
|
||||
async init(connectionId: string, networkHandlers: string[], onClose: () => void): Promise<void> {
|
||||
this.connectionId = connectionId;
|
||||
this.networkHandlers = networkHandlers;
|
||||
this.close = onClose;
|
||||
this.loadAuthModel();
|
||||
|
||||
await this.loadAuthModel();
|
||||
this.fillCredentials();
|
||||
this.loadDrivers();
|
||||
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
destruct(): void {
|
||||
@@ -80,6 +90,35 @@ export class DBAuthDialogController implements IInitializableController, IDestru
|
||||
}
|
||||
};
|
||||
|
||||
private fillCredentials() {
|
||||
const connection = this.connectionInfoResource.get(this.connectionId);
|
||||
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (connection.authNeeded) {
|
||||
const property = connection.authProperties?.find(property => property.id === USER_NAME_PROPERTY_ID);
|
||||
|
||||
if (property?.value) {
|
||||
this.config.credentials[USER_NAME_PROPERTY_ID] = property.value;
|
||||
}
|
||||
}
|
||||
|
||||
for (const id of this.networkHandlers) {
|
||||
const handler = connection.networkHandlersConfig.find(handler => handler.id === id);
|
||||
|
||||
if (handler?.userName) {
|
||||
this.config.networkHandlersConfig.push({
|
||||
id: handler.id,
|
||||
userName: handler.userName,
|
||||
password: handler.password,
|
||||
savePassword: handler.savePassword,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getConfig() {
|
||||
const config: ConnectionInitConfig = {
|
||||
id: this.connectionId,
|
||||
@@ -99,7 +138,7 @@ export class DBAuthDialogController implements IInitializableController, IDestru
|
||||
|
||||
private async loadAuthModel() {
|
||||
try {
|
||||
await this.connectionInfoResource.load(this.connectionId, ['includeAuthProperties']);
|
||||
await this.connectionInfoResource.load(this.connectionId, ['includeAuthProperties', 'customIncludeNetworkHandlerCredentials']);
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, 'Can\'t load auth model');
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export const DatabaseAuthDialog: DialogComponent<Payload> = observer(function Da
|
||||
rejectDialog,
|
||||
}) {
|
||||
const connection = useConnectionInfo(payload.connectionId);
|
||||
const controller = useController(DBAuthDialogController, payload.connectionId, rejectDialog);
|
||||
const controller = useController(DBAuthDialogController, payload.connectionId, payload.networkHandlers, rejectDialog);
|
||||
|
||||
const { driver } = useDBDriver(connection.connectionInfo?.driverId || '');
|
||||
const { credentialsSavingEnabled } = useAdministrationSettings();
|
||||
@@ -93,7 +93,7 @@ export const DatabaseAuthDialog: DialogComponent<Payload> = observer(function Da
|
||||
)}
|
||||
onReject={options?.persistent ? undefined : rejectDialog}
|
||||
>
|
||||
{(!connection.isLoaded() || connection.isLoading())
|
||||
{(!connection.isLoaded() || connection.isLoading() || !controller.configured)
|
||||
? <Loader />
|
||||
: (
|
||||
<SubmittingForm ref={focusedRef} onSubmit={controller.login}>
|
||||
|
||||
Reference in New Issue
Block a user