Yuki Takei 1 год назад
Родитель
Сommit
2941dcece4

+ 11 - 9
apps/app/src/features/external-user-group/server/service/ldap-user-group-sync.ts

@@ -1,12 +1,14 @@
 import { configManager } from '~/server/service/config-manager';
 import { configManager } from '~/server/service/config-manager';
-import { ldapService, SearchResultEntry } from '~/server/service/ldap';
-import PassportService from '~/server/service/passport';
-import { S2sMessagingService } from '~/server/service/s2s-messaging/base';
+import type { SearchResultEntry } from '~/server/service/ldap';
+import { ldapService } from '~/server/service/ldap';
+import type PassportService from '~/server/service/passport';
+import type { S2sMessagingService } from '~/server/service/s2s-messaging/base';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 import { batchProcessPromiseAll } from '~/utils/promise';
 import { batchProcessPromiseAll } from '~/utils/promise';
 
 
+import type { ExternalUserGroupTreeNode, ExternalUserInfo } from '../../interfaces/external-user-group';
 import {
 import {
-  ExternalGroupProviderType, ExternalUserGroupTreeNode, ExternalUserInfo, LdapGroupMembershipAttributeType,
+  ExternalGroupProviderType, LdapGroupMembershipAttributeType,
 } from '../../interfaces/external-user-group';
 } from '../../interfaces/external-user-group';
 
 
 import ExternalUserGroupSyncService from './external-user-group-sync';
 import ExternalUserGroupSyncService from './external-user-group-sync';
@@ -47,11 +49,11 @@ export class LdapUserGroupSyncService extends ExternalUserGroupSyncService {
   }
   }
 
 
   override async generateExternalUserGroupTrees(): Promise<ExternalUserGroupTreeNode[]> {
   override async generateExternalUserGroupTrees(): Promise<ExternalUserGroupTreeNode[]> {
-    const groupChildGroupAttribute: string = configManager.getConfig('crowi', 'external-user-group:ldap:groupChildGroupAttribute');
-    const groupMembershipAttribute: string = configManager.getConfig('crowi', 'external-user-group:ldap:groupMembershipAttribute');
-    const groupNameAttribute: string = configManager.getConfig('crowi', 'external-user-group:ldap:groupNameAttribute');
-    const groupDescriptionAttribute: string = configManager.getConfig('crowi', 'external-user-group:ldap:groupDescriptionAttribute');
-    const groupBase: string = ldapService.getGroupSearchBase();
+    const groupChildGroupAttribute = configManager.getConfig('crowi', 'external-user-group:ldap:groupChildGroupAttribute');
+    const groupMembershipAttribute = configManager.getConfig('crowi', 'external-user-group:ldap:groupMembershipAttribute');
+    const groupNameAttribute = configManager.getConfig('crowi', 'external-user-group:ldap:groupNameAttribute');
+    const groupDescriptionAttribute = configManager.getConfig('crowi', 'external-user-group:ldap:groupDescriptionAttribute');
+    const groupBase = ldapService.getGroupSearchBase();
 
 
     const groupEntries = await ldapService.searchGroupDir();
     const groupEntries = await ldapService.searchGroupDir();
 
 

+ 8 - 7
apps/app/src/server/service/ldap.ts

@@ -58,7 +58,7 @@ class LdapService {
    * @param {string} userBindUsername Necessary when bind type is user bind
    * @param {string} userBindUsername Necessary when bind type is user bind
    * @param {string} userBindPassword Necessary when bind type is user bind
    * @param {string} userBindPassword Necessary when bind type is user bind
    */
    */
-  bind(userBindUsername?: string, userBindPassword?: string): Promise<void> {
+  bind(userBindUsername = '', userBindPassword = ''): Promise<void> {
     const client = this.client;
     const client = this.client;
     if (client == null) throw new Error('LDAP client is not initialized');
     if (client == null) throw new Error('LDAP client is not initialized');
 
 
@@ -71,8 +71,8 @@ class LdapService {
 
 
     // get configurations
     // get configurations
     const isUserBind = configManager?.getConfig('crowi', 'security:passport-ldap:isUserBind');
     const isUserBind = configManager?.getConfig('crowi', 'security:passport-ldap:isUserBind');
-    const bindDN = configManager?.getConfig('crowi', 'security:passport-ldap:bindDN');
-    const bindCredentials = configManager?.getConfig('crowi', 'security:passport-ldap:bindDNPassword');
+    const bindDN = configManager?.getConfig('crowi', 'security:passport-ldap:bindDN') ?? '';
+    const bindCredentials = configManager?.getConfig('crowi', 'security:passport-ldap:bindDNPassword') ?? '';
 
 
     // user bind
     // user bind
     const fixedBindDN = (isUserBind)
     const fixedBindDN = (isUserBind)
@@ -146,12 +146,12 @@ class LdapService {
     return this.search(undefined, this.getGroupSearchBase());
     return this.search(undefined, this.getGroupSearchBase());
   }
   }
 
 
-  getArrayValFromSearchResultEntry(entry: SearchResultEntry, attributeType: string): string[] {
+  getArrayValFromSearchResultEntry(entry: SearchResultEntry, attributeType: string | undefined): string[] {
     const values: string | string[] = entry.attributes.find(attribute => attribute.type === attributeType)?.values || [];
     const values: string | string[] = entry.attributes.find(attribute => attribute.type === attributeType)?.values || [];
     return typeof values === 'string' ? [values] : values;
     return typeof values === 'string' ? [values] : values;
   }
   }
 
 
-  getStringValFromSearchResultEntry(entry: SearchResultEntry, attributeType: string): string | undefined {
+  getStringValFromSearchResultEntry(entry: SearchResultEntry, attributeType: string | undefined): string | undefined {
     const values: string | string[] | undefined = entry.attributes.find(attribute => attribute.type === attributeType)?.values;
     const values: string | string[] | undefined = entry.attributes.find(attribute => attribute.type === attributeType)?.values;
     if (typeof values === 'string' || values == null) {
     if (typeof values === 'string' || values == null) {
       return values;
       return values;
@@ -163,8 +163,9 @@ class LdapService {
   }
   }
 
 
   getGroupSearchBase(): string {
   getGroupSearchBase(): string {
-    return configManager?.getConfig('crowi', 'external-user-group:ldap:groupSearchBase')
-    || configManager?.getConfig('crowi', 'security:passport-ldap:groupSearchBase');
+    return configManager.getConfig('crowi', 'external-user-group:ldap:groupSearchBase')
+      ?? configManager.getConfig('crowi', 'security:passport-ldap:groupSearchBase')
+      ?? '';
   }
   }
 
 
 }
 }