From 2800c2f0776b7b86f31c6334c9a89d022c8891ea Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 27 Apr 2018 17:16:54 -0400 Subject: [PATCH] settings configuration --- .editorconfig | 1 + src/app/services/services.module.ts | 3 + src/app/tabs/settings.component.html | 195 +++++++++++++++++++++++++- src/app/tabs/settings.component.ts | 50 ++++++- src/enums/directoryType.ts | 5 + src/locales/en/messages.json | 113 ++++++++++++++- src/models/azureConfiguration.ts | 5 + src/models/gsuiteConfiguration.ts | 7 + src/models/ldapConfiguration.ts | 13 ++ src/models/syncConfiguration.ts | 21 +++ src/services/configuration.service.ts | 66 +++++++++ 11 files changed, 472 insertions(+), 7 deletions(-) create mode 100644 src/enums/directoryType.ts create mode 100644 src/models/azureConfiguration.ts create mode 100644 src/models/gsuiteConfiguration.ts create mode 100644 src/models/ldapConfiguration.ts create mode 100644 src/models/syncConfiguration.ts create mode 100644 src/services/configuration.service.ts diff --git a/.editorconfig b/.editorconfig index 332f3a5d..5284d16c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,7 @@ root = true [*] end_of_line = lf insert_final_newline = true +quote_type = single # Set default charset [*.{js,ts,scss,html}] diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 9f7ca3c2..01ac192c 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -15,6 +15,7 @@ import { isDev } from 'jslib/electron/utils'; import { AuthGuardService } from './auth-guard.service'; import { LaunchGuardService } from './launch-guard.service'; +import { ConfigurationService } from '../../services/configuration.service'; import { I18nService } from '../../services/i18n.service'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; @@ -68,6 +69,7 @@ const userService = new UserService(tokenService, storageService); const containerService = new ContainerService(cryptoService, platformUtilsService); const authService = new AuthService(cryptoService, apiService, userService, tokenService, appIdService, i18nService, platformUtilsService, messagingService, false); +const configurationService = new ConfigurationService(storageService, secureStorageService); const analytics = new Analytics(window, () => true, platformUtilsService, storageService, appIdService); containerService.attachToWindow(window); @@ -120,6 +122,7 @@ export function initFactory(): Function { { provide: StorageServiceAbstraction, useValue: storageService }, { provide: StateServiceAbstraction, useValue: stateService }, { provide: LogServiceAbstraction, useValue: logService }, + { provide: ConfigurationService, useValue: configurationService }, { provide: APP_INITIALIZER, useFactory: initFactory, diff --git a/src/app/tabs/settings.component.html b/src/app/tabs/settings.component.html index a2bee479..3537b9ba 100644 --- a/src/app/tabs/settings.component.html +++ b/src/app/tabs/settings.component.html @@ -1,3 +1,194 @@ - +
+

Directory

+
+ + +
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-The settings!!! +

Sync

+
+ + +
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
diff --git a/src/app/tabs/settings.component.ts b/src/app/tabs/settings.component.ts index 73e86155..8f4bf58d 100644 --- a/src/app/tabs/settings.component.ts +++ b/src/app/tabs/settings.component.ts @@ -1,6 +1,7 @@ import { Component, ComponentFactoryResolver, + OnInit, ViewChild, ViewContainerRef, } from '@angular/core'; @@ -9,12 +10,57 @@ import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; import { I18nService } from 'jslib/abstractions/i18n.service'; +import { StorageService } from 'jslib/abstractions/storage.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 { +export class SettingsComponent implements OnInit { + directory: DirectoryType; + directoryType = DirectoryType; + ldap = new LdapConfiguration(); + gsuite = new GSuiteConfiguration(); + azure = new AzureConfiguration(); + sync = new SyncConfiguration(); + directoryOptions: any[]; + constructor(analytics: Angulartics2, toasterService: ToasterService, - i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver) {} + i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver, + private configurationService: ConfigurationService, private storageService: StorageService) { + 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.storageService.get('directory'); + this.ldap = (await this.configurationService.get(DirectoryType.Ldap)) || + this.ldap; + this.gsuite = (await this.configurationService.get(DirectoryType.GSuite)) || + this.gsuite; + this.azure = (await this.configurationService.get(DirectoryType.AzureActiveDirectory)) || + this.azure; + this.sync = (await this.storageService.get('syncConfig')) || this.sync; + } + + async submit() { + await this.storageService.save('directory', this.directory); + await this.configurationService.save(DirectoryType.Ldap, this.ldap); + await this.configurationService.save(DirectoryType.GSuite, this.gsuite); + await this.configurationService.save(DirectoryType.AzureActiveDirectory, this.azure); + await this.storageService.save('syncConfig', this.sync); + } } diff --git a/src/enums/directoryType.ts b/src/enums/directoryType.ts new file mode 100644 index 00000000..0ba3f952 --- /dev/null +++ b/src/enums/directoryType.ts @@ -0,0 +1,5 @@ +export enum DirectoryType { + Ldap = 0, + AzureActiveDirectory = 1, + GSuite = 2, +} diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index a6531a24..9864dcab 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -229,13 +229,13 @@ "message": "Unknown" }, "view": { - "message": "View" + "message": "View" }, "file": { - "message": "File" + "message": "File" }, "edit": { - "message": "Edit" + "message": "Edit" }, "undo": { "message": "Undo" @@ -303,5 +303,112 @@ }, "window": { "message": "Window" + }, + "ex": { + "message": "ex.", + "description": "Short abbreviation for 'example'." + }, + "serverHostname": { + "message": "Server Hostname" + }, + "port": { + "message": "Port", + "description": "A server's port number. ex. google.com:8080" + }, + "username": { + "message": "Username" + }, + "password": { + "message": "Password" + }, + "thisIsActiveDirectory": { + "message": "This is an Active Directory LDAP server." + }, + "type": { + "message": "Type" + }, + "directory": { + "message": "Directory" + }, + "currentUser": { + "message": "Current user" + }, + "rootPath": { + "message": "Root Path" + }, + "tenant": { + "message": "Tenant" + }, + "applicationId": { + "message": "Application Id" + }, + "secretKey": { + "message": "Secret Key" + }, + "adminUser": { + "message": "Admin User" + }, + "domain": { + "message": "Domain" + }, + "customerId": { + "message": "Customer Id" + }, + "privateKey": { + "message": "Private Key (from key file)" + }, + "clientEmail": { + "message": "Client Email (from key file)" + }, + "interval": { + "message": "Interval (in minutes)" + }, + "removeDisabled": { + "message": "Remove disabled users" + }, + "memberAttribute": { + "message": "Member Attribute" + }, + "creationDateAttribute": { + "message": "Creation Date Attribute" + }, + "revisionDateAttribute": { + "message": "Revision Date Attribute" + }, + "useEmailPrefixSuffix": { + "message": "Use email prefix/suffix" + }, + "emailPrefixAttribute": { + "message": "Email Prefix Attribute" + }, + "emailSuffix": { + "message": "Email Suffix" + }, + "syncUsers": { + "message": "Sync users" + }, + "userFilter": { + "message": "User Filter" + }, + "userObjectClass": { + "message": "User Object Class" + }, + "userPath": { + "message": "User Path" + }, + "syncGroups": { + "message": "Sync groups" + }, + "groupFilter": { + "message": "Group Filter" + }, + "groupObjectClass": { + "message": "Group Object Class" + }, + "groupPath": { + "message": "Group Path" + }, + "groupNameAttribute": { + "message": "Group Name Attribute" } } diff --git a/src/models/azureConfiguration.ts b/src/models/azureConfiguration.ts new file mode 100644 index 00000000..b9a113c0 --- /dev/null +++ b/src/models/azureConfiguration.ts @@ -0,0 +1,5 @@ +export class AzureConfiguration { + tenant: string; + applicationId: string; + key: string; +} diff --git a/src/models/gsuiteConfiguration.ts b/src/models/gsuiteConfiguration.ts new file mode 100644 index 00000000..cbe18e8b --- /dev/null +++ b/src/models/gsuiteConfiguration.ts @@ -0,0 +1,7 @@ +export class GSuiteConfiguration { + clientEmail: string; + privateKey: string; + domain: string; + adminUser: string; + customer: string; +} diff --git a/src/models/ldapConfiguration.ts b/src/models/ldapConfiguration.ts new file mode 100644 index 00000000..ba8adb13 --- /dev/null +++ b/src/models/ldapConfiguration.ts @@ -0,0 +1,13 @@ +import { DirectoryType } from '../enums/directoryType'; + +export class LdapConfiguration { + ssl: boolean = false; + hostname: string; + port: number = 389; + domain: string; + rootPath: string; + currentUser: boolean = false; + username: string; + password: string; + ad: boolean = true; +} diff --git a/src/models/syncConfiguration.ts b/src/models/syncConfiguration.ts new file mode 100644 index 00000000..d0054779 --- /dev/null +++ b/src/models/syncConfiguration.ts @@ -0,0 +1,21 @@ +export class SyncConfiguration { + users: boolean = false; + groups: boolean = false; + interval: number = 5; + userFilter: string; + groupFilter: string; + removeDisabled: boolean = false; + // Ldap properties + groupObjectClass: string; + userObjectClass: string; + groupPath: string; + userPath: string; + groupNameAttribute: string; + userEmailAttribute: string; + memberAttribute: string; + useEmailPrefixSuffix: boolean = false; + emailPrefixAttribute: string; + emailSuffix: string; + creationDateAttribute: string; + revisionDateAttribute: string; +} diff --git a/src/services/configuration.service.ts b/src/services/configuration.service.ts new file mode 100644 index 00000000..14a187da --- /dev/null +++ b/src/services/configuration.service.ts @@ -0,0 +1,66 @@ +import { DirectoryType } from '../enums/directoryType'; + +import { StorageService } from 'jslib/abstractions/storage.service'; + +const StoredSecurely = '[STORED SECURELY]'; +const Keys = { + ldap: 'ldapPassword', + gsuite: 'gsuitePrivateKey', + azure: 'azureKey', + directoryConfigPrefix: 'directoryConfig_', +}; + +export class ConfigurationService { + constructor(private storageService: StorageService, private secureStorageService: StorageService) { } + + async get(type: DirectoryType): Promise { + const config = await this.storageService.get(Keys.directoryConfigPrefix + type); + if (config == null) { + return config; + } + + switch (type) { + case DirectoryType.Ldap: + (config as any).password = await this.secureStorageService.get(Keys.ldap); + break; + case DirectoryType.AzureActiveDirectory: + (config as any).key = await this.secureStorageService.get(Keys.azure); + break; + case DirectoryType.GSuite: + (config as any).privateKey = await this.secureStorageService.get(Keys.gsuite); + break; + } + return config; + } + + async save(type: DirectoryType, config: T): Promise { + const savedConfig: any = Object.assign({}, config); + switch (type) { + case DirectoryType.Ldap: + if (savedConfig.password == null) { + await this.secureStorageService.remove(Keys.ldap); + } else { + await this.secureStorageService.save(Keys.ldap, savedConfig.password); + savedConfig.password = StoredSecurely; + } + break; + case DirectoryType.AzureActiveDirectory: + if (savedConfig.key == null) { + await this.secureStorageService.remove(Keys.azure); + } else { + await this.secureStorageService.save(Keys.azure, savedConfig.key); + savedConfig.key = StoredSecurely; + } + break; + case DirectoryType.GSuite: + if (savedConfig.privateKey == null) { + await this.secureStorageService.remove(Keys.gsuite); + } else { + await this.secureStorageService.save(Keys.gsuite, savedConfig.privateKey); + savedConfig.privateKey = StoredSecurely; + } + break; + } + await this.storageService.save(Keys.directoryConfigPrefix + type, savedConfig); + } +}