Atrybuty unikalne w OpenDJ
Czasem istnieje potrzeba ustawienia pewnych atrybutów jako unikalne, na przykład jeśli LDAP zawiera użytkowników systemowych, to atrybut uid nie powinien się powtarzać w obrębie danego systemu. OpenDJ ma gotowy plugin do tego, ale domyślnie nie jest włączony. Podobnie w przypadku systemu pocztowego, atrybut mail powinien być unikalny. Tu już nie ma gotowego pluginu, ale można go łatwo stworzyć bazując na pluginie UID Unique Attribute i na tym opisie oraz tym.
No ale nie po to robię ten wpis żeby Was odsyłać do angielskich opisów. Pokażę tu jak dodać Plugin za pomocą dsconfig i jak go później przenieść do repliki za pomocą LDIFa.
root@ldapdj1:~# dsconfig -D cn=dirmgr -h localhost -p 4444 -X
>>>> Specify OpenDS LDAP connection parameters
Password for user 'cn=dirmgr':
>>>> OpenDS configuration console main menu
What do you want to configure?
1) Access Control Handler 23) Log Rotation Policy
2) Account Status Notification Handler 24) Matching Rule
3) Administration Connector 25) Monitor Provider
4) Alert Handler 26) Network Group
5) Attribute Syntax 27) Network Group QOS Policy
6) Backend 28) Password Generator
7) Certificate Mapper 29) Password Policy
8) Connection Handler 30) Password Storage Scheme
9) Crypto Manager 31) Password Validator
10) Debug Target 32) Plugin
11) Entry Cache 33) Plugin Root
12) Extended Operation Handler 34) Replication Domain
13) Extension 35) Replication Server
14) External Changelog Domain 36) Root DN
15) Global Configuration 37) Root DSE Backend
16) Group Implementation 38) SASL Mechanism Handler
17) Identity Mapper 39) Synchronization Provider
18) Key Manager Provider 40) Trust Manager Provider
19) Local DB Index 41) Virtual Attribute
20) Local DB VLV Index 42) Work Queue
21) Log Publisher 43) Workflow
22) Log Retention Policy 44) Workflow Element
q) quit
Enter choice: 32
>>>> Plugin management menu
What would you like to do?
1) List existing Plugins
2) Create a new Plugin
3) View and edit an existing Plugin
4) Delete an existing Plugin
b) back
q) quit
Enter choice [b]: 1
Plugin : Type : enabled
-----------------------------------:---------------------------------:--------
7-Bit Clean : seven-bit-clean : false
Change Number Control : change-number-control : true
Entry UUID : entry-uuid : true
Fractional Replication LDIF Import : fractional-ldif-import : true
LastMod : last-mod : true
LDAP Attribute Description List : ldap-attribute-description-list : true
Password Policy Import : password-policy-import : true
Profiler : profiler : true
Referential Integrity : referential-integrity : false
UID Unique Attribute : unique-attribute : false
Widać, że jest plugin UID Unique Attribute w stanie wyłączonym. Jego włączenie to kwestia przełączenia enable na true, pominę ten krok. Tworzymy nowy plugin:
What would you like to do?
1) List existing Plugins
2) Create a new Plugin
3) View and edit an existing Plugin
4) Delete an existing Plugin
b) back
q) quit
Enter choice [b]: 2
>>>> Select the type of Plugin that you want to create:
1) Change Number Control Plugin 7) Password Policy Import
Plugin
2) Entry UUID Plugin 8) Profiler Plugin
3) Fractional LDIF Import Plugin 9) Referential Integrity
Plugin
4) Last Mod Plugin 10) Seven Bit Clean Plugin
5) LDAP Attribute Description List 11) Unique Attribute Plugin
Plugin
6) Network Group Plugin
?) help
c) cancel
q) quit
Enter choice : 11
>>>> Enter a name for the Unique Attribute Plugin that you want to create: Mail Unique Attribute
>>>> Configuring the "enabled" property
Indicates whether the plug-in is enabled for use.
Select a value for the "enabled" property:
1) true
2) false
?) help
c) cancel
q) quit
Enter choice : 1
>>>> Configuring the "type" property
Specifies the type of attributes to check for value uniqueness.
Syntax: OID
Enter a value for the "type" property: mail
Enter another value for the "type" property [continue]:
>>>> Configure the properties of the Unique Attribute Plugin
Property Value(s)
-----------------------------------------------------------------------
1) base-dn The plug-in uses the server's public naming contexts in the
searches.
2) enabled true
3) type mail
?) help
f) finish - create the new Unique Attribute Plugin
c) cancel
q) quit
Enter choice [f]:
The Unique Attribute Plugin was created successfully
Press RETURN to continue
Proste i intuicyjne, na dodatek to samo jest w przytoczonym opisie. Trochę się powtarzam, ale chcę zwrócić uwagę, że:
- można tworzyć pluginy również dla atrybutów z własnych, dodanych do OpenDJ schematów
- atrybuty dla których tworzona jest unikalność muszą być poindeksowane eq
Jeśli mamy skonfigurowaną replikację Multi-Master, to należy również dodać unikalność do bliźniaczego serwera. Można to zrobić przy pomocy dsconfig w trybie interaktywnym lub nieinteraktywnym, ale czy nie prościej będzie LDIFem?
Może i nie prościej jeśli nie byłoby możliwości eksportu z jakiegoś narzędzia. Można się podłączyć aplikacją control-panel, ale ja osobiście używam Eclipse, którym łączę się na port 4444 z SSL i ustawiam bazowy DN jako cn=config. Wchodzę więc w odpowiednią gałąź cn=Plugins,cn=config, podświetlam cn=Mail Unique Attribute i eksportuję do LDIFa, którego zapisuję na dysk:
# cat Mail-unique.ldif
version: 1 dn: cn=Mail Unique Attribute,cn=Plugins,cn=config objectClass: ds-cfg-unique-attribute-plugin objectClass: ds-cfg-plugin objectClass: top cn: Mail Unique Attribute ds-cfg-enabled: true ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin ds-cfg-plugin-type: postoperationadd ds-cfg-plugin-type: postoperationmodify ds-cfg-plugin-type: postoperationmodifydn ds-cfg-plugin-type: postsynchronizationadd ds-cfg-plugin-type: postsynchronizationmodify ds-cfg-plugin-type: postsynchronizationmodifydn ds-cfg-plugin-type: preoperationadd ds-cfg-plugin-type: preoperationmodify ds-cfg-plugin-type: preoperationmodifydn ds-cfg-type: mail
Wrzucam LDIFa na serwer i importuję go do katalogu:
# ldapmodify -a -D cn=dirmgr -h localhost -X -f Mail-unique.ldif
Password for user 'cn=dirmgr': Processing ADD request for cn=Mail Unique Attribute,cn=Plugins,cn=config ADD operation successful for DN cn=Mail Unique Attribute,cn=Plugins,cn=config
Można też to zrobić przy pomocy narzędzia graficznego, ale chciałem pokazać jak to zrobić „z palca” 🙂
