mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-05 23:53:21 +00:00
76 lines
3.0 KiB
TypeScript
76 lines
3.0 KiB
TypeScript
import {
|
|
Component,
|
|
OnDestroy,
|
|
OnInit,
|
|
} from '@angular/core';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { ConfigurationService } from '../../services/configuration.service';
|
|
|
|
import { DirectoryType } from '../../enums/directoryType';
|
|
|
|
import { AzureConfiguration } from '../../models/azureConfiguration';
|
|
import { GSuiteConfiguration } from '../../models/gsuiteConfiguration';
|
|
import { LdapConfiguration } from '../../models/ldapConfiguration';
|
|
import { SyncConfiguration } from '../../models/syncConfiguration';
|
|
|
|
@Component({
|
|
selector: 'app-settings',
|
|
templateUrl: 'settings.component.html',
|
|
})
|
|
export class SettingsComponent implements OnInit, OnDestroy {
|
|
directory: DirectoryType;
|
|
directoryType = DirectoryType;
|
|
ldap = new LdapConfiguration();
|
|
gsuite = new GSuiteConfiguration();
|
|
azure = new AzureConfiguration();
|
|
sync = new SyncConfiguration();
|
|
directoryOptions: any[];
|
|
|
|
constructor(private i18nService: I18nService, private configurationService: ConfigurationService) {
|
|
this.directoryOptions = [
|
|
{ name: i18nService.t('select'), value: null },
|
|
{ name: 'Active Directory / LDAP', value: DirectoryType.Ldap },
|
|
{ name: 'Azure Active Directory', value: DirectoryType.AzureActiveDirectory },
|
|
{ name: 'G Suite (Google)', value: DirectoryType.GSuite },
|
|
];
|
|
}
|
|
|
|
async ngOnInit() {
|
|
this.directory = await this.configurationService.getDirectoryType();
|
|
this.ldap = (await this.configurationService.getDirectory<LdapConfiguration>(DirectoryType.Ldap)) ||
|
|
this.ldap;
|
|
this.gsuite = (await this.configurationService.getDirectory<GSuiteConfiguration>(DirectoryType.GSuite)) ||
|
|
this.gsuite;
|
|
this.azure = (await this.configurationService.getDirectory<AzureConfiguration>(
|
|
DirectoryType.AzureActiveDirectory)) || this.azure;
|
|
this.sync = (await this.configurationService.getSync()) || this.sync;
|
|
}
|
|
|
|
async ngOnDestroy() {
|
|
await this.submit();
|
|
}
|
|
|
|
async submit() {
|
|
if (this.ldap.ad) {
|
|
this.sync.creationDateAttribute = 'whenCreated';
|
|
this.sync.revisionDateAttribute = 'whenChanged';
|
|
this.sync.emailPrefixAttribute = 'sAMAccountName';
|
|
this.sync.groupPath = 'CN=Users';
|
|
this.sync.userPath = 'CN=Users';
|
|
this.sync.memberAttribute = 'member';
|
|
this.sync.userObjectClass = 'person';
|
|
this.sync.groupObjectClass = 'group';
|
|
this.sync.userEmailAttribute = 'mail';
|
|
this.sync.groupNameAttribute = 'name';
|
|
}
|
|
|
|
await this.configurationService.saveDirectoryType(this.directory);
|
|
await this.configurationService.saveDirectory(DirectoryType.Ldap, this.ldap);
|
|
await this.configurationService.saveDirectory(DirectoryType.GSuite, this.gsuite);
|
|
await this.configurationService.saveDirectory(DirectoryType.AzureActiveDirectory, this.azure);
|
|
await this.configurationService.saveSync(this.sync);
|
|
}
|
|
}
|