@nymphjs/tilmeld-client 1.0.0-beta.15 → 1.0.0-beta.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,257 @@
1
+ import { Entity, Options, Selector } from '@nymphjs/client';
2
+
3
+ import type { AdminGroupData, Group, Group as GroupClass } from './Group.js';
4
+ import type { AdminUserData, User } from './User.js';
5
+ import { AccessControlData } from './Tilmeld.types.js';
6
+
7
+ export type RawLDAPBinaryData = {
8
+ base64: string;
9
+ };
10
+ export type RawLDAPEntry = {
11
+ dn: string;
12
+ [index: string]: RawLDAPBinaryData | RawLDAPBinaryData[] | string[] | string;
13
+ };
14
+ export type RawLDAPSearchResult = RawLDAPEntry[];
15
+
16
+ export interface LDAPSourceData extends AccessControlData {
17
+ /**
18
+ * The host of the server.
19
+ */
20
+ host: string;
21
+ /**
22
+ * The port on the server. Default is 389 for plain/StartTLS, 636 for LDAPS.
23
+ */
24
+ port?: number;
25
+ /**
26
+ * The encryption type.
27
+ */
28
+ encryption: 'none' | 'starttls' | 'ldaps';
29
+ /**
30
+ * Whether to ignore SSL certificate errors.
31
+ *
32
+ * This is not secure, and should not be used in production environments.
33
+ */
34
+ ignoreCertificateErrors: boolean;
35
+ /**
36
+ * The Distinguished Name or User Principal Name of a service account.
37
+ *
38
+ * This account will be used to search the directory. Leave empty for
39
+ * anonymous bind.
40
+ */
41
+ bindUsername: string;
42
+ /**
43
+ * The password for the bind account.
44
+ */
45
+ bindPassword: string;
46
+ /**
47
+ * The base Distinguished Name used to search for user entries.
48
+ */
49
+ searchBase: string;
50
+ /**
51
+ * The LDAP search filter used to find all users.
52
+ *
53
+ * Use `(objectClass=organizationalPerson)` for most directories.
54
+ */
55
+ userFilter: string;
56
+ /**
57
+ * The LDAP search filter used to find the user.
58
+ *
59
+ * Use `{0}` as a placeholder for the username.
60
+ *
61
+ * Use `(sAMAccountName={0})` for Active Directory. Use `(uid={0})` for
62
+ * OpenLDAP. Use `(userPrincipalName={0})` if usernames in the directory are
63
+ * stored under the "userPrincipalName" attribute.
64
+ */
65
+ userSearchFilter: string;
66
+ /**
67
+ * The user attribute listing group memberships.
68
+ *
69
+ * Use `memberOf` for Active Directory.
70
+ */
71
+ groupAttributeOnUser?: string;
72
+ /**
73
+ * The group attribute listing member users.
74
+ *
75
+ * Use `uniqueMember` for LDAP. Empty for Active Directory.
76
+ */
77
+ groupAttributeOnGroup?: string;
78
+ /**
79
+ * Restrict user registration only to users belonging to a mapped group.
80
+ *
81
+ * If you set this to true and don't map any groups, no users will be able to
82
+ * register an account through this LDAP source.
83
+ */
84
+ restrictRegistrationToMappedUsers: boolean;
85
+ /**
86
+ * A map of remote groups to their local group equivalents.
87
+ *
88
+ * An LDAP user's group membership in these groups will be synced every time
89
+ * they log in.
90
+ */
91
+ groupMap: {
92
+ remoteDN: string;
93
+ localGroup: GroupClass & AdminGroupData;
94
+ }[];
95
+ /**
96
+ * The mapping of attributes from Nymph to LDAP.
97
+ *
98
+ * The only required attribute is username.
99
+ */
100
+ attributeMap: {
101
+ nameFirst?: string;
102
+ nameMiddle?: string;
103
+ nameLast?: string;
104
+ name?: string;
105
+ phone?: string;
106
+ email?: string;
107
+ username: string;
108
+ avatar?: string;
109
+ enabled?: string;
110
+ };
111
+ /**
112
+ * Whether users from this LDAP Source are synced and enabled.
113
+ */
114
+ enabled: boolean;
115
+ }
116
+
117
+ export interface LDAPSource extends LDAPSourceData {}
118
+
119
+ export class LDAPSource extends Entity<LDAPSourceData> {
120
+ // The name of the server class
121
+ public static class = 'LDAPSource';
122
+
123
+ constructor() {
124
+ super();
125
+
126
+ // Defaults.
127
+ this.host = '';
128
+ this.encryption = 'starttls';
129
+ this.ignoreCertificateErrors = false;
130
+ this.bindUsername = '';
131
+ this.bindPassword = '';
132
+ this.searchBase = 'DC=example,DC=com';
133
+ this.userFilter = '(objectClass=organizationalPerson)';
134
+ this.userSearchFilter = '(sAMAccountName={0})';
135
+ this.groupAttributeOnUser = 'memberOf';
136
+ this.restrictRegistrationToMappedUsers = false;
137
+ this.groupMap = [];
138
+ this.attributeMap = {
139
+ nameFirst: 'givenName',
140
+ nameMiddle: 'initials',
141
+ nameLast: 'sn',
142
+ name: 'displayName',
143
+ phone: 'telephoneNumber',
144
+ email: 'mail',
145
+ username: 'sAMAccountName',
146
+ // AD stores this as a bitmask. We store it as a boolean.
147
+ // 512 = normal user
148
+ // 2 = disabled
149
+ enabled:
150
+ '(userAccountControl & 512) == 512 && (userAccountControl & 2) == 0',
151
+ };
152
+ this.enabled = true;
153
+ }
154
+
155
+ public $fillWithTestServer(source: 'forumsys' | 'freeipa') {
156
+ if (source === 'forumsys') {
157
+ this.host = 'ldap.forumsys.com';
158
+ this.bindUsername = 'cn=read-only-admin,dc=example,dc=com';
159
+ this.bindPassword = 'password';
160
+ this.searchBase = 'dc=example,dc=com';
161
+ this.userFilter = '(objectClass=organizationalPerson)';
162
+ this.userSearchFilter = '(uid={0})';
163
+ this.groupAttributeOnUser = '';
164
+ this.groupAttributeOnGroup = 'uniqueMember';
165
+ this.attributeMap = {
166
+ nameFirst: '',
167
+ nameMiddle: '',
168
+ nameLast: 'sn',
169
+ name: 'cn',
170
+ phone: 'telephoneNumber',
171
+ email: 'mail',
172
+ username: 'uid',
173
+ avatar: '',
174
+ enabled: 'true',
175
+ };
176
+ } else {
177
+ this.host = 'ipa.demo1.freeipa.org';
178
+ this.bindUsername =
179
+ 'uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org';
180
+ this.bindPassword = 'Secret123';
181
+ this.searchBase = 'cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org';
182
+ this.userFilter = '(objectClass=inetuser)';
183
+ this.userSearchFilter = '(uid={0})';
184
+ this.groupAttributeOnUser = 'memberOf';
185
+ this.groupAttributeOnGroup = '';
186
+ this.attributeMap = {
187
+ nameFirst: 'givenName',
188
+ nameMiddle: '',
189
+ nameLast: 'sn',
190
+ name: 'cn',
191
+ phone: '',
192
+ email: 'mail || uid+"@demo1.freeipa.org"',
193
+ username: 'uid',
194
+ avatar: '',
195
+ enabled: 'objectClass =~ /(^|,)posixaccount(,|$)/',
196
+ };
197
+ }
198
+ this.port = 389;
199
+ this.encryption = 'none';
200
+ this.ignoreCertificateErrors = false;
201
+ this.restrictRegistrationToMappedUsers = false;
202
+ this.groupMap = [];
203
+ this.enabled = true;
204
+ }
205
+
206
+ public async $testBind(): Promise<void> {
207
+ return await this.$serverCall('$testBind', [], {
208
+ pushState: true,
209
+ });
210
+ }
211
+
212
+ public async $testList(): Promise<RawLDAPSearchResult> {
213
+ return await this.$serverCall('$testList', [], {
214
+ pushState: true,
215
+ });
216
+ }
217
+
218
+ public async $testMapping(
219
+ username: string,
220
+ ): Promise<(User & AdminUserData) | null> {
221
+ return await this.$serverCall('$testMapping', [username], {
222
+ pushState: true,
223
+ });
224
+ }
225
+
226
+ public async $testSearch(username: string): Promise<RawLDAPEntry | null> {
227
+ return await this.$serverCall('$testSearch', [username], {
228
+ pushState: true,
229
+ });
230
+ }
231
+
232
+ public async $getUsers(
233
+ limit?: number,
234
+ offset?: number,
235
+ reverse?: boolean,
236
+ sort?: string,
237
+ enabled?: boolean,
238
+ ): Promise<{ entities: User[]; count: number }> {
239
+ return await this.$serverCall('$getUsers', [
240
+ limit,
241
+ offset,
242
+ reverse,
243
+ sort,
244
+ enabled,
245
+ ]);
246
+ }
247
+
248
+ public static async getMappableGroups(
249
+ options?: Options,
250
+ selectors?: Selector[],
251
+ ): Promise<Group[]> {
252
+ return await this.serverCallStatic('getMappableGroups', [
253
+ { ...options, class: this.class },
254
+ selectors,
255
+ ]);
256
+ }
257
+ }
@@ -0,0 +1,13 @@
1
+ import { Group } from './Group.js';
2
+ import { User } from './User.js';
3
+
4
+ export interface AccessControlData {
5
+ user?: User;
6
+ group?: Group;
7
+ acUser?: number;
8
+ acGroup?: number;
9
+ acOther?: number;
10
+ acFull?: string[];
11
+ acWrite?: string[];
12
+ acRead?: string[];
13
+ }