ldap-rest 0.0.1 → 0.1.0

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.
Files changed (62) hide show
  1. package/README.md +38 -0
  2. package/bin/sync-app-accounts.mjs +276 -0
  3. package/dist/abstract/ldapFlat.js +1 -1
  4. package/dist/abstract/plugin.js +1 -1
  5. package/dist/bin/index.js +1 -1
  6. package/dist/config/args.js +1 -1
  7. package/dist/lib/ldapActions.js +1 -1
  8. package/dist/lib/utils.js +1 -1
  9. package/dist/logger/winston.js +1 -1
  10. package/dist/plugins/auth/hmac.js +1 -0
  11. package/dist/plugins/auth/totp.js +1 -0
  12. package/dist/plugins/demo/helloworld.js +1 -1
  13. package/dist/plugins/ldap/groups.js +1 -1
  14. package/dist/plugins/ldap/onChange.js +1 -1
  15. package/dist/plugins/static.js +1 -1
  16. package/dist/plugins/twake/appAccountsApi.js +1 -0
  17. package/dist/plugins/twake/appAccountsConsistency.js +1 -0
  18. package/dist/plugins/twake/james.js +1 -1
  19. package/dist/plugins/weblogs.js +1 -1
  20. package/dist/src/abstract/ldapFlat.d.ts +0 -5
  21. package/dist/src/abstract/plugin.d.ts +1 -0
  22. package/dist/src/bin/index.d.ts +1 -0
  23. package/dist/src/browser/shared/index.d.ts +1 -0
  24. package/dist/src/browser/shared/utils/hmac.d.ts +73 -0
  25. package/dist/src/browser/shared/utils/totp.d.ts +64 -0
  26. package/dist/src/config/args.d.ts +9 -1
  27. package/dist/src/hooks.d.ts +2 -2
  28. package/dist/src/lib/ldapActions.d.ts +3 -7
  29. package/dist/src/lib/utils.d.ts +17 -0
  30. package/dist/src/logger/winston.d.ts +5 -0
  31. package/dist/src/plugins/auth/hmac.d.ts +24 -0
  32. package/dist/src/plugins/auth/totp.d.ts +35 -0
  33. package/dist/src/plugins/ldap/onChange.d.ts +1 -0
  34. package/dist/src/plugins/static.d.ts +4 -0
  35. package/dist/src/plugins/twake/appAccountsApi.d.ts +52 -0
  36. package/dist/src/plugins/twake/appAccountsConsistency.d.ts +58 -0
  37. package/docs/DEVELOPER_GUIDE.md +1 -0
  38. package/docs/PLUGIN_DEPENDENCIES.md +19 -0
  39. package/docs/README.md +74 -30
  40. package/docs/authentication.md +600 -12
  41. package/docs/plugins/DEVELOPMENT.md +148 -76
  42. package/docs/testing-with-embedded-ldap.md +342 -0
  43. package/docs/twakeAppAccountsApi.md +485 -0
  44. package/docs/weblogs.md +36 -8
  45. package/examples/web/README.md +166 -0
  46. package/examples/web/ldap-tree-viewer.html +16 -2
  47. package/examples/web/totp-client.html +543 -0
  48. package/package.json +46 -1
  49. package/static/browser/shared/index.js +1 -0
  50. package/static/browser/shared/index.js.map +1 -1
  51. package/static/browser/shared/utils/hmac.js +202 -0
  52. package/static/browser/shared/utils/hmac.js.map +1 -0
  53. package/static/browser/shared/utils/totp.js +182 -0
  54. package/static/browser/shared/utils/totp.js.map +1 -0
  55. package/static/browser/shared.esm.js +181 -1
  56. package/static/browser/shared.esm.js.map +1 -1
  57. package/static/browser/shared.js +184 -0
  58. package/static/browser/shared.js.map +1 -1
  59. package/static/browser/shared.min.js +1 -1
  60. package/static/browser/shared.min.js.map +1 -1
  61. package/static/schemas/obm/organizations.json +24 -0
  62. package/static/schemas/obm/users.json +192 -0
@@ -0,0 +1,58 @@
1
+ /**
2
+ * App Accounts Consistency Plugin
3
+ *
4
+ * Automatically manages applicative account entries for protocol-based authentication
5
+ * (e.g., IMAP, SMTP, CalDAV, CardDAV).
6
+ *
7
+ * ## Concept
8
+ *
9
+ * Instead of using a single primary password for all services, this system separates:
10
+ * - **Primary authentication**: May use passwordless methods (smart cards, biometrics, SSO)
11
+ * - **Applicative accounts**: Dedicated accounts per device/application
12
+ *
13
+ * This is essential for protocols requiring password authentication (IMAP, SMTP, CalDAV)
14
+ * while maintaining security and allowing easy revocation per device.
15
+ *
16
+ * ## Behavior
17
+ *
18
+ * When a user with a mail attribute is created, this plugin creates a corresponding
19
+ * principal applicative account entry in a separate branch (e.g., ou=applicative).
20
+ *
21
+ * When a user is deleted, all corresponding applicative accounts are also deleted.
22
+ *
23
+ * When a user's mail changes, all applicative accounts are updated with the new mail.
24
+ */
25
+ import DmPlugin from '../../abstract/plugin';
26
+ import type { Role } from '../../abstract/plugin';
27
+ import type { DM } from '../../bin';
28
+ import { Hooks } from '../../hooks';
29
+ export default class AppAccountsConsistency extends DmPlugin {
30
+ name: string;
31
+ roles: Role[];
32
+ dependencies: {
33
+ onLdapChange: string;
34
+ };
35
+ private mailAttr;
36
+ private applicativeAccountBase;
37
+ private operationalAttributes;
38
+ constructor(server: DM);
39
+ /**
40
+ * Check if an attribute should be excluded when copying LDAP entry attributes
41
+ * @param key - The attribute name to check
42
+ * @returns true if the attribute should be excluded
43
+ */
44
+ private shouldExcludeAttribute;
45
+ hooks: Hooks;
46
+ /**
47
+ * Create applicative account for a user
48
+ */
49
+ private createApplicativeAccount;
50
+ /**
51
+ * Delete applicative account by mail
52
+ */
53
+ private deleteApplicativeAccount;
54
+ /**
55
+ * Update applicative account when mail changes
56
+ */
57
+ private updateApplicativeAccount;
58
+ }
@@ -34,6 +34,7 @@ LDAP-Rest is a lightweight LDAP directory manager that provides:
34
34
  - **Schema-driven architecture** to adapt to different directory types (Twake, Active Directory, standard LDAP)
35
35
  - **Dynamic configuration** exposed via API
36
36
  - **Plugin-based extensibility** for custom functionality
37
+ - **Robust error handling** ensuring server stability even when plugins encounter errors
37
38
 
38
39
  ### Architecture Overview
39
40
 
@@ -200,6 +200,25 @@ dependencies = {
200
200
  - **Consumes Hooks**: None
201
201
  - **Notes**: Synchronizes calendar resources with Twake Calendar
202
202
 
203
+ #### `appAccountsConsistency` (twake/appAccountsConsistency)
204
+
205
+ - **Dependencies**:
206
+ - `onLdapChange: 'core/ldap/onChange'` ⚠️ **Required**
207
+ - **Provides Hooks**:
208
+ - `ldapadddone` - After user added, creates principal applicative account
209
+ - `onLdapMailChange` - When mail changes, updates applicative accounts
210
+ - **Consumes Hooks**: (Hooks provided by `onLdapChange`)
211
+ - **Notes**: Automatically creates and maintains principal applicative accounts (uid=mail)
212
+
213
+ #### `appAccountsApi` (twake/appAccountsApi)
214
+
215
+ - **Dependencies**:
216
+ - `authToken: 'core/auth/token'` ⚠️ **Required** (or another auth plugin)
217
+ - `appAccountsConsistency: 'core/twake/appAccountsConsistency'` ⚠️ **Required**
218
+ - **Provides Hooks**: None
219
+ - **Consumes Hooks**: None
220
+ - **Notes**: RESTful API for managing applicative accounts (device/app-specific accounts). Depends on `appAccountsConsistency` for automatic cleanup and synchronization of app accounts.
221
+
203
222
  ### Utility Plugins
204
223
 
205
224
  #### `static` (core/static)
package/docs/README.md CHANGED
@@ -77,6 +77,7 @@ If you want to extend LDAP-Rest with custom plugins, see below:
77
77
 
78
78
  - **[twakeJames](twakeJames.md)** - Apache James mail server synchronization
79
79
  - **[twakeCalendarResources](twakeCalendarResources.md)** - Twake Calendar resources synchronization
80
+ - **[twakeAppAccountsApi](twakeAppAccountsApi.md)** - Applicative accounts API (device/app-specific accounts)
80
81
 
81
82
  ## Quick Start
82
83
 
@@ -134,67 +135,68 @@ ldap-rest \
134
135
 
135
136
  Plugins for managing different LDAP entity types:
136
137
 
137
- | Plugin | Entity Type | Features |
138
- | ----------------- | ------------------------ | --------------------------------------------- |
139
- | ldapFlatGeneric | Users, Positions, Custom | Schema-driven, Validation, Pointers |
140
- | ldapGroups | Groups | Member validation, Nested groups |
141
- | ldapOrganizations | Organizational Units | Tree navigation, Search |
142
- | ldapBulkImport | Any (bulk operations) | CSV import, Template generation, Multi-schema |
143
- | ldapTrash | Any (soft delete) | Trash system, Recovery, Metadata |
138
+ | Plugin | Entity Type | Features |
139
+ | ---------------------- | ------------------------ | --------------------------------------------- |
140
+ | core/ldap/flatGeneric | Users, Positions, Custom | Schema-driven, Validation, Pointers |
141
+ | core/ldap/groups | Groups | Member validation, Nested groups |
142
+ | core/ldap/organization | Organizational Units | Tree navigation, Search |
143
+ | core/ldap/bulkImport | Any (bulk operations) | CSV import, Template generation, Multi-schema |
144
+ | core/ldap/trash | Any (soft delete) | Trash system, Recovery, Metadata |
144
145
 
145
146
  ### Authentication
146
147
 
147
148
  Secure API access:
148
149
 
149
- | Plugin | Type | Use Case |
150
- | -------------- | ------------- | ---------------------------- |
151
- | token | Bearer tokens | Development, APIs, Scripts |
152
- | llng | LemonLDAP::NG | Enterprise SSO |
153
- | openidconnect | OAuth2/OIDC | Cloud identity, Social login |
154
- | authzPerBranch | Authorization | Branch-level access control |
155
- | authzLinid1 | Authorization | LinID 1.x integration |
150
+ | Plugin | Type | Use Case |
151
+ | ------------------------ | ------------- | ---------------------------- |
152
+ | core/auth/token | Bearer tokens | Development, APIs, Scripts |
153
+ | core/auth/llng | LemonLDAP::NG | Enterprise SSO |
154
+ | core/auth/openidconnect | OAuth2/OIDC | Cloud identity, Social login |
155
+ | core/auth/authzPerBranch | Authorization | Branch-level access control |
156
+ | core/auth/authzLinid1 | Authorization | LinID 1.x integration |
156
157
 
157
158
  ### Security
158
159
 
159
160
  Protection and rate limiting:
160
161
 
161
- | Plugin | Type | Use Case |
162
- | --------- | ------------- | ----------------------------- |
163
- | crowdsec | IP blocking | Block banned IPs via CrowdSec |
164
- | rateLimit | Rate limiting | Prevent brute-force attacks |
162
+ | Plugin | Type | Use Case |
163
+ | ------------------- | ------------- | ----------------------------- |
164
+ | core/auth/crowdsec | IP blocking | Block banned IPs via CrowdSec |
165
+ | core/auth/rateLimit | Rate limiting | Prevent brute-force attacks |
165
166
 
166
167
  ### Integration
167
168
 
168
169
  Connect to external systems:
169
170
 
170
- | Plugin | Integrates With | Purpose |
171
- | --------------------- | --------------- | -------------------- |
172
- | onChange | Any | Detect LDAP changes |
173
- | twake/james | Apache James | Mail server sync |
174
- | externalUsersInGroups | Groups | Auto-create contacts |
171
+ | Plugin | Integrates With | Purpose |
172
+ | ------------------------------- | --------------- | ------------------------ |
173
+ | core/ldap/onChange | Any | Detect LDAP changes |
174
+ | core/twake/james | Apache James | Mail server sync |
175
+ | core/twake/appAccountsApi | LDAP | App-specific account API |
176
+ | core/ldap/externalUsersInGroups | Groups | Auto-create contacts |
175
177
 
176
178
  ### Utilities
177
179
 
178
180
  Support plugins:
179
181
 
180
- | Plugin | Purpose |
181
- | ------- | --------------------- |
182
- | static | Serve web UI, schemas |
183
- | weblogs | Request logging |
182
+ | Plugin | Purpose |
183
+ | ------------ | --------------------- |
184
+ | core/static | Serve web UI, schemas |
185
+ | core/weblogs | Request logging |
184
186
 
185
187
  ## Plugin Dependencies
186
188
 
187
189
  Some plugins require others:
188
190
 
189
191
  ```
190
- twake/james
192
+ core/twake/james
191
193
  └─ requires: core/ldap/onChange
192
194
 
193
195
  core/ldap/externalUsersInGroups
194
196
  └─ requires: core/ldap/groups
195
197
 
196
198
  core/auth/authzPerBranch
197
- └─ requires: Any authentication plugin (token, llng, openidconnect)
199
+ └─ requires: Any authentication plugin (core/auth/token, core/auth/llng, core/auth/openidconnect)
198
200
  ```
199
201
 
200
202
  ## Configuration
@@ -205,7 +207,7 @@ All CLI options can be set via environment variables:
205
207
 
206
208
  ```bash
207
209
  # LDAP connection
208
- export DM_LDAP_URL="ldap://localhost:389"
210
+ export DM_LDAP_URL="ldap://localhost:389" # or multiple URLs for failover
209
211
  export DM_LDAP_DN="cn=admin,dc=example,dc=com"
210
212
  export DM_LDAP_PWD="password"
211
213
  export DM_LDAP_BASE="dc=example,dc=com"
@@ -215,10 +217,45 @@ export DM_PLUGIN="core/auth/token,core/ldap/flatGeneric"
215
217
  export DM_AUTH_TOKENS="token1,token2"
216
218
  export DM_LDAP_FLAT_SCHEMA="./schemas/users.json"
217
219
 
220
+ # Logging
221
+ export DM_LOG_LEVEL="notice" # error, warn, notice, info, debug
222
+
218
223
  # Start server
219
224
  ldap-rest
220
225
  ```
221
226
 
227
+ ### LDAP Failover
228
+
229
+ LDAP-Rest supports multiple LDAP servers for high availability. Provide multiple URLs separated by commas:
230
+
231
+ ```bash
232
+ # Command line
233
+ --ldap-url ldap://ldap1.example.com,ldap://ldap2.example.com,ldap://ldap3.example.com
234
+
235
+ # Or via environment variable
236
+ export DM_LDAP_URL="ldap://ldap1.example.com,ldap://ldap2.example.com,ldap://ldap3.example.com"
237
+ ```
238
+
239
+ The system will:
240
+ 1. Try to connect to each URL in order
241
+ 2. Use the first successful connection
242
+ 3. Automatically failover to the next URL if the current connection fails
243
+ 4. Log failover events for monitoring
244
+
245
+ ### Log Levels
246
+
247
+ LDAP-Rest uses syslog-style log levels:
248
+
249
+ ```bash
250
+ --log-level error # Only errors
251
+ --log-level warn # Warnings and errors
252
+ --log-level notice # Web access logs (recommended for production)
253
+ --log-level info # General info + web logs + warnings + errors
254
+ --log-level debug # All messages including debug output
255
+ ```
256
+
257
+ The **notice** level is ideal for production as it shows web access logs without flooding with general info messages.
258
+
222
259
  ### Configuration Files
223
260
 
224
261
  Use `.env` files or shell scripts:
@@ -439,6 +476,13 @@ Enable detailed logging:
439
476
  ldap-rest --log-level debug ...
440
477
  ```
441
478
 
479
+ Available log levels (following syslog convention):
480
+ - `error` - Only errors
481
+ - `warn` - Warnings and errors
482
+ - `notice` - Web access logs, warnings and errors (recommended for production)
483
+ - `info` - General info messages, web logs, warnings and errors
484
+ - `debug` - All messages including debug output
485
+
442
486
  ### Testing
443
487
 
444
488
  Run test suite: