Performing LDAP OperationsOpenDJ comes with a Control Panel browser for managing entries and also
command-line tools for performing LDAP operations. This chapter demonstrates
how to use the command line tools to script LDAP operations.Searching the DirectorySearching dataSearching the directory resembles searching for a phone number in
a paper phone book. You can look up a phone number because you know the
last name of a subscriber's entry. In other words, you use the value of
one attribute of the entry to find entries that have another attribute
you want.Yet whereas a paper phone book has only one index (alphabetical order
by name), the directory has many indexes. For a search you therefore always
specify which index to use, by specifying which attribute(s) you are using
to lookup entries.Your paper phone book might be divided into white pages for residential
subscribers, and yellow pages for businesses. If you are looking up an
individual's phone number, you limit your search to the white pages.
Directory services divide entries in various ways, often to separate
organizations, and to separate groups from user entries from printers for
example, but potentially in other ways. When searching you therefore also
specify where in the directory to search.The ldapsearch command thus takes at minimum a
search base DN option and an LDAP filter. The search base DN identifies
where in the directory to search for entries that match the filter.
For example, if you are looking for printers, you might specify the base
DN as ou=Printers,dc=example,dc=com. Perhaps you are
visiting the GNB00 office and are looking for a
printer.$ ldapsearch --baseDN ou=Printers,dc=example,dc=com "(printerLocation=GNB00)"In the example, the LDAP filter indicates to the directory that you
want to lookup printer entries where the printerLocation
attribute is equal to GNB00.You also specify the host and port to access directory services,
what protocol to use (for example, LDAP/SSL, or StartTLS to protect
communication). If the directory service does not allow anonymous access
to the data you want to search, you also identify who is performing the
search and provide their credentials, such as a password or
certificate. Finally, you can specify a list of attributes to return.
If you do not specify attributes, then the search returns all user attributes
for the entry.Review the following examples in this section to get a sense of how
searches work.Search: Simple FilterThe following example searches for entries with UID containing
jensen, returning only DNs and uid values.$ ldapsearch --port 1389 --baseDN dc=example,dc=com "(uid=*jensen*)" uid
dn: uid=ajensen,ou=People,dc=example,dc=com
uid: ajensen
dn: uid=bjensen,ou=People,dc=example,dc=com
uid: bjensen
dn: uid=gjensen,ou=People,dc=example,dc=com
uid: gjensen
dn: uid=jjensen,ou=People,dc=example,dc=com
uid: jjensen
dn: uid=kjensen,ou=People,dc=example,dc=com
uid: kjensen
dn: uid=rjensen,ou=People,dc=example,dc=com
uid: rjensen
dn: uid=tjensen,ou=People,dc=example,dc=com
uid: tjensen
Result Code: 0 (Success)Search: Complex FilterThe following example returns entries with uid
containing jensen for users located in Santa Clara. The
command returns the attributes associated with the person
object class.$ ldapsearch
--port 1389
--baseDN ou=people,dc=example,dc=com
"(&(uid=*jensen*)(l=Santa Clara))"
@person
dn: uid=ajensen,ou=People,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
cn: Allison Jensen
telephoneNumber: +1 408 555 7892
sn: Jensen
dn: uid=gjensen,ou=People,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
cn: Gern Jensen
telephoneNumber: +1 408 555 3299
sn: Jensen
dn: uid=kjensen,ou=People,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
cn: Kurt Jensen
telephoneNumber: +1 408 555 6127
sn: Jensen
dn: uid=tjensen,ou=People,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
cn: Ted Jensen
telephoneNumber: +1 408 555 8622
sn: Jensen
Complex filters can use both "and" syntax,
(&(filtercomp)(filtercomp)),
and "or" syntax,
(|(filtercomp)(filtercomp)).Search: Return Operational AttributesUse + in the attribute list after the filter
to return all operational attributes. Alternatively, specify operational
attributes by name.$ ldapsearch --port 1389 --baseDN dc=example,dc=com uid=bjensen +
dn: uid=bjensen,ou=People,dc=example,dc=com
numSubordinates: 0
structuralObjectClass: inetOrgPerson
pwdPolicySubentry: cn=Default Password Policy,cn=Password Policies,cn=config
subschemaSubentry: cn=schema
hasSubordinates: false
entryDN: uid=bjensen,ou=people,dc=example,dc=com
entryUUID: fc252fd9-b982-3ed6-b42a-c76d2546312cSearch: Return Attributes for an Object ClassUse @objectClass in the
attribute list after the filter to return the attributes associated with
a particular object class.$ ldapsearch --port 1389 --baseDN dc=example,dc=com uid=bjensen @person
dn: uid=bjensen,ou=People,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
cn: Barbara Jensen
cn: Babs Jensen
telephoneNumber: +1 408 555 1862
sn: JensenSearch: Escaping Search Filter CharactersRFC 4515:
Lightweight Directory Access Protocol (LDAP): String Representation
of Search Filters mentions a number of characters that you must
handle with care when using them in search filters.For a filter like (attr=value), the following list indicates characters
that you must replace with a backslash ( \ ) followed
by two hexadecimal digits when using them as part of the
value string.Replace * with \2a.Replace ( with \28.Replace ) with \29.Replace \ with \5c.Replace NUL (0x00) with \2a.The following example shows a filter with escaped characters matching
an actual value.$ ldapsearch --port 1389 --baseDN dc=example,dc=com
"(description=\28*\5c*\2a\29)" description
dn: uid=bjensen,ou=People,dc=example,dc=com
description: (A \great\ description*)Search: List Active AccountsOpenDJ supports extensible matching rules, meaning you can pass in
filters specifying a matching rule OID that extends your search beyond what
you can do with standard LDAP. One specific matching rule of this type that
OpenDJ supports is the generalized time based "later than" and "earlier
than" matching rules. See the example, Configure
an Extensible Match Index, showing how to build an index
for these matching rules.You can use these matching rules to list, for example, all users who
have authenticated recently.First set up an attribute to store a last login timestamp.
You can do this by adding a schema file for the attribute.$ ldapmodify
--port 1389
--hostname opendj.example.com
--bindDN "cn=Directory Manager"
--bindPassword password
dn: cn=schema
changetype: modify
add: attributeTypes
attributeTypes: ( lastLoginTime-oid
NAME 'lastLoginTime'
DESC 'Last time the user logged in'
EQUALITY generalizedTimeMatch
ORDERING generalizedTimeOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24
SINGLE-VALUE
NO-USER-MODIFICATION
USAGE directoryOperation
X-ORIGIN 'OpenDJ example documentation' )
Processing MODIFY request for cn=schema
MODIFY operation successful for DN cn=schema
Configure the applicable password policy to write the last login
timestamp when a user authenticates. The following command configures the
default password policy to write the timestamp in generalized time format
to the lastLoginTime operational attribute on the user's
entry.$ dsconfig
set-password-policy-prop
--port 4444
--hostname opendj.example.com
--bindDN "cn=Directory Manager"
--bindPassword password
--policy-name "Default Password Policy"
--set last-login-time-attribute:lastLoginTime
--set last-login-time-format:"yyyyMMddHH'Z'"
--trustAll
--no-promptWait a while for users to authenticate again (or test it yourself) so
that OpenDJ writes the timestamps. The following search then returns users
who have authenticated in the last three months (13 weeks) after you
configured OpenDJ to keep the last login timestamps.$ ldapsearch
--port 1389
--baseDN dc=example,dc=com
"(lastLoginTime:1.3.6.1.4.1.26027.1.4.6:=13w)" mail
dn: uid=bjensen,ou=People,dc=example,dc=com
mail: bjensen@example.com
dn: uid=kvaughan,ou=People,dc=example,dc=com
mail: kvaughan@example.comSearch: Language SubtypeOpenDJ directory server supports many language subtypes. See the
chapter on Localization for a list.When you perform a search you can request the language subtype by
OID or by language subtype string. For example, the following search gets
the French version of a common name. The example uses the
base64 command provided with OpenDJ directory server to
decode the attribute value.$ ldapsearch
--port 1389
--baseDN dc=example,dc=com
"(givenName:fr:=Fréderique)" cn\;lang-fr
dn: uid=fdupont,ou=People,dc=example,dc=com
cn;lang-fr:: RnJlZMOpcmlxdWUgRHVwb250
$ base64 decode -d RnJlZMOpcmlxdWUgRHVwb250
Fredérique DupontAt the end of the OID or language subtype, you further specify the
matching rule as follows:Add .1 for less thanAdd .2 for less than or equal toAdd .3 for equal to (default)Add .4 for greater than or equal toAdd .5 for greater thanAdd .6 for substringComparing Attribute ValuesComparing attribute valuesThe compare operation checks whether an attribute value you specify
matches the attribute value stored on one or more directory entries.Compare: Checking authPasswordIn this example, Kirsten Vaughan checks whether the hashed password
value matches the stored value on authPassword.$ ldapcompare
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
'authPassword:MD5$dFHgpDxXUT8=$qlC4xMXvmVlusJLz9/WJ5Q=='
uid=kvaughan,ou=people,dc=example,dc=com
Comparing type authPassword with value
MD5$dFHgpDxXUT8=$qlC4xMXvmVlusJLz9/WJ5Q== in entry
uid=kvaughan,ou=people,dc=example,dc=com
Compare operation returned true for entry
uid=kvaughan,ou=people,dc=example,dc=comUpdating the DirectoryUpdating dataLDIFExamplesAuthorized users can change directory data using the LDAP add, modify,
modify DN, and delete operations.Adding EntriesWith the ldapmodify -a command, authorized users
can add entire entries from the same sort of LDIF file used to import
and export data.Add: Two New Users$ cat new-users.ldif
dn: cn=Arsene Lupin,ou=Special Users,dc=example,dc=com
objectClass: person
objectClass: top
cn: Arsene Lupin
telephoneNumber: +33 1 23 45 67 89
sn: Lupin
dn: cn=Horace Velmont,ou=Special Users,dc=example,dc=com
objectClass: person
objectClass: top
cn: Horace Velmont
telephoneNumber: +33 1 12 23 34 45
sn: Velmont
$ ldapmodify
--defaultAdd
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--filename new-users.ldif
Processing ADD request for cn=Arsene Lupin,ou=Special Users,dc=example,dc=com
ADD operation successful for DN
cn=Arsene Lupin,ou=Special Users,dc=example,dc=com
Processing ADD request for cn=Horace Velmont,ou=Special Users,dc=example,dc=com
ADD operation successful for DN
cn=Horace Velmont,ou=Special Users,dc=example,dc=comModifying Entry AttributesWith the ldapmodify command, authorized users
can change the values of attributes in the directory using LDIF as specified
in RFC 2849.Modify: Adding AttributesThe following example adds a description and JPEG photo to Sam
Carter's entry.$ cat scarter-mods.ldif
dn: uid=scarter,ou=people,dc=example,dc=com
changetype: modify
add: description
description: Accounting Manager
-
add: jpegphoto
jpegphoto: /tmp/Samantha-Carter.jpg
$ ldapmodify
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--filename scarter-mods.ldif
Processing MODIFY request for uid=scarter,ou=people,dc=example,dc=com
MODIFY operation successful for DN uid=scarter,ou=people,dc=example,dc=comModify: Changing an Attribute ValueThe following example replaces the description on Sam Carter's
entry.$ cat scarter-newdesc.ldif
dn: uid=scarter,ou=people,dc=example,dc=com
changetype: modify
replace: description
description: Accounting Director
$ ldapmodify
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--filename scarter-newdesc.ldif
Processing MODIFY request for uid=scarter,ou=people,dc=example,dc=com
MODIFY operation successful for DN uid=scarter,ou=people,dc=example,dc=comModify: Deleting an Attribute ValueThe following example deletes the JPEG photo on Sam Carter's
entry.$ cat /path/to/scarter-deljpeg.ldif
dn: uid=scarter,ou=people,dc=example,dc=com
changetype: modify
delete: jpegphoto
$ ldapmodify
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--filename scarter-deljpeg.ldif
Processing MODIFY request for uid=scarter,ou=people,dc=example,dc=com
MODIFY operation successful for DN uid=scarter,ou=people,dc=example,dc=comModify: Optimistic ConcurrencyImagine you are writing an application that lets end users update
user profiles through a browser. You store user profiles as OpenDJ entries.
Your end users can look up user profiles and modify them. Your application
assumes that the end users can tell the right information when they see it,
and so aims to update profiles exactly as users see them on their
screens.Consider two users, Alice and Bob, both busy and often interrupted.
Alice has Babs Jensen's new phone and room numbers. Bob has Babs's new
location and description. Both assume that they have all the information
that has changed. What can you do to make sure that your application
applies the right changes when Alice and Bob simulaneously update Babs
Jensen's profile?OpenDJ offers a couple of features to help you in this situation.
One of the features is the LDAP Assertion
Control, used to tell OpenDJ to perform the modify only if
an assertion you make stays true. The other feature is OpenDJ's support
for entity tag (ETag) attributes, making it easy to
check whether the entry in the directory is the same as the entry you
read.Alice and Bob both get Babs's entry. In LDIF the relevant
attributes from the entry look like this. Notice the ETag.dn: uid=bjensen,ou=People,dc=example,dc=com
telephoneNumber: +1 408 555 1862
roomNumber: 0209
l: Cupertino
ETag: 000000007a1999dfBob prepares his changes in your application. Bob is almost ready
to submit the new location and description when Carol stops by to ask Bob
a few questions.Alice starts just after Bob, but manages to submit her changes
without getting interrupted. Now Babs's entry looks like this.dn: uid=bjensen,ou=People,dc=example,dc=com
description: Updated by Alice
telephoneNumber: +47 2108 1746
roomNumber: 1389
l: Cupertino
ETag: 00000000aec2c1e9In your application, you use the ETag attribute value with the
assertion control to prevent Bob's update from going through when the
ETag value has changed. Your application tries the equivalent of the
following commands with Bob's updates.$ cat /path/to/bobs.ldif
dn: uid=bjensen,ou=People,dc=example,dc=com
changetype: modify
replace: l
l: Grenoble
-
add: description
description: Employee of the Month
$ ldapmodify
--bindDN "cn=Directory Manager"
--bindPassword password
--port 1389
--filename /path/to/bobs.ldif
--assertionFilter "(ETag=000000007a1999df)"
Processing MODIFY request for uid=bjensen,ou=People,dc=example,dc=com
MODIFY operation failed
Result Code: 122 (Assertion Failed)
Additional Information: Entry uid=bjensen,ou=People,dc=example,dc=com
cannot be modified because the request contained an LDAP assertion control
and the associated filter did not match the contents of the that entryYour application therefore reloads Babs's entry, also getting the new
ETag value, 00000000aec2c1e9, and lets Bob try again.
This time Bob's changes do not collide with other changes. Babs's entry is
successfully updated.dn: uid=bjensen,ou=People,dc=example,dc=com
description: Employee of the Month
telephoneNumber: +47 2108 1746
roomNumber: 1389
l: Grenoble
ETag: 00000000e882c35eFiltering Add & Modify OperationsUpdating dataFilteringSome client applications send updates including attributes with names
that differ from the attribute names defined in OpenDJ. Other client
applications might try to update attributes they should not update, such
as the operational attributes creatorsName,
createTimestamp, modifiersName,
and modifyTimestamp. Ideally you would fix the client
application behavior, but that is not always feasible.You can configure the attribute cleanup plugin to filter add and
modify requests, renaming attributes in requests using incorrect names,
and removing attributes that applications should not change.Renaming Incoming AttributesThe following example renames incoming email
attributes to mail attributes. First, configure the
attribute cleanup plugin to rename the inbound attribute.$ dsconfig
create-plugin
--port 4444
--hostname opendj.example.com
--bindDN "cn=Directory Manager"
--bindPassword password
--type attribute-cleanup
--plugin-name "Rename email to mail"
--set enabled:true
--set rename-inbound-attributes:email:mail
--trustAll
--no-promptNext, see that it works as expected.$ cat email.ldif
dn: uid=newuser,ou=People,dc=example,dc=com
uid: newuser
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: top
cn: New User
sn: User
ou: People
email: newuser@example.com
userPassword: changeme
$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
--defaultAdd
--filename email.ldif
Processing ADD request for uid=newuser,ou=People,dc=example,dc=com
ADD operation successful for DN uid=newuser,ou=People,dc=example,dc=com
$ ldapsearch --port 1389 --baseDN dc=example,dc=com uid=newuser mail
dn: uid=newuser,ou=People,dc=example,dc=com
mail: newuser@example.comRemoving Incoming AttributesThe following example prevents client applications from adding or
modifying creatorsName,
createTimestamp, modifiersName,
and modifyTimestamp attributes. First, set up the
attribute cleanup plugin.$ dsconfig
create-plugin
--port 4444
--hostname opendj.example.com
--bindDN "cn=Directory Manager"
--bindPassword password
--type attribute-cleanup
--plugin-name "Remove attrs"
--set enabled:true
--set remove-inbound-attributes:creatorsName
--set remove-inbound-attributes:createTimestamp
--set remove-inbound-attributes:modifiersName
--set remove-inbound-attributes:modifyTimestamp
--trustAll
--no-promptNext, see that it works as expected.$ cat badattrs.ldif
dn: uid=badattr,ou=People,dc=example,dc=com
uid: newuser
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: top
cn: Bad Attr
sn: Attr
ou: People
mail: badattr@example.com
userPassword: changeme
creatorsName: cn=Bad Attr
createTimestamp: Never in a million years.
modifiersName: cn=Directory Manager,cn=Root DNs,cn=config
modifyTimestamp: 20110930164937Z
$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
--defaultAdd
--filename badattrs.ldif
Processing ADD request for uid=badattr,ou=People,dc=example,dc=com
ADD operation successful for DN uid=badattr,ou=People,dc=example,dc=com
$ ldapsearch --port 1389 --baseDN dc=example,dc=com uid=badattr +
dn: uid=badattr,ou=People,dc=example,dc=com
numSubordinates: 0
structuralObjectClass: inetOrgPerson
pwdPolicySubentry: cn=Default Password Policy,cn=Password Policies,cn=config
subschemaSubentry: cn=schema
hasSubordinates: false
entryDN: uid=badattr,ou=people,dc=example,dc=com
entryUUID: 35e5cb0e-e929-49d8-a50f-2df036d60db9
pwdChangedTime: 20110930165959.135Z
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
createTimestamp: 20110930165959ZRenaming EntriesThe Relative Distinguished Name (RDN) refers to the part of an
entry's DN that distinguishes it from all other DNs at the same level
in the directory tree. For example uid=bjensen is
the RDN of the entry having DN
uid=bjensen,ou=People,dc=example,dc=com.With the ldapmodify command, authorized users
can rename entries in the directory.When you change the RDN of the entry, you are renaming the entry,
modifying the value of the naming attribute, but also modifying the entry's
DN.Rename: Modifying the DNSam Carter is changing her last name to Jensen, and changing her
login from scarter to sjensen.
The following example renames and changes Sam Carter's entry accordingly.
Notice the boolean field, deleteoldrdn: 1, which
indicates that the previous RDN, uid: scarter, should
be removed. (Setting deleteoldrdn: 0 instead would
preserve uid: scarter on the entry.)$ cat /path/to/scarter-sjensen.ldif
dn: uid=scarter,ou=people,dc=example,dc=com
changetype: modrdn
newrdn: uid=sjensen
deleteoldrdn: 1
dn: uid=sjensen,ou=people,dc=example,dc=com
changetype: modify
replace: cn
cn: Sam Jensen
-
replace: sn
sn: Jensen
-
replace: homeDirectory
homeDirectory: /home/sjensen
-
replace: mail
mail: sjensen@example.com
$ ldapmodify
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--filename /path/to/scarter-sjensen.ldif
Processing MODIFY DN request for uid=scarter,ou=people,dc=example,dc=com
MODIFY DN operation successful for DN uid=scarter,ou=people,dc=example,dc=com
Processing MODIFY request for uid=sjensen,ou=people,dc=example,dc=com
MODIFY operation successful for DN uid=sjensen,ou=people,dc=example,dc=comMoving EntriesWhen you rename an entry with child entries, the directory has
to move all the entries underneath.The modify DN operation only works when moving entries in the same
backend, under the same suffix. Also, depending on the number of entries
you move, this can be a resource-intensive operation.With the ldapmodify command, authorized users
can move entries in the directory.Move: Merging Customer and Employees Under
ou=PeopleThe following example moves
ou=Customers,dc=example,dc=com to
ou=People,dc=example,dc=com, and then moves each
employee under ou=Employees,dc=example,dc=com
under ou=People,dc=example,dc=com as well, finally
removing the empty ou=Employees,dc=example,dc=com
container. Here, deleteoldrdn: 1 indicates that the
old RDN, ou: Customers, should be removed from the
entry. For employees, deleteoldrdn: 0 indicates that
old RDNs, in this case uid attribute values, should
be preserved.$ cat move-customers.ldif
dn: ou=Customers,dc=example,dc=com
changetype: modrdn
newrdn: ou=People
deleteoldrdn: 1
newsuperior: dc=example,dc=com
$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
--filename move-customers.ldif
Processing MODIFY DN request for ou=Customers,dc=example,dc=com
MODIFY DN operation successful for DN ou=Customers,dc=example,dc=com
$ cat move-employees.pl
#!/usr/bin/perl -w
# For each employee, construct a spec to move under ou=People.
while (<>)
{
# Next line folded for readability only. Should not be split.
$_ =~ s/dn: (.*?)(,.*)/dn: $1$2\nchangetype: moddn\nnewrdn: $1\n
deleteoldrdn: 0\nnewsuperior: ou=People,dc=example,dc=com/;
print;
}
$ ldapsearch --port 1389 --baseDN ou=Employees,dc=example,dc=com uid=* - |
move-employees.pl > /tmp/move-employees.ldif
$ head -n 6 /tmp/move-employees.ldif
dn: uid=abarnes,ou=Employees,dc=example,dc=com
changetype: moddn
newrdn: uid=abarnes
deleteoldrdn: 0
newsuperior: ou=People,dc=example,dc=com
$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
--filename /tmp/move-employees.ldif
Processing MODIFY DN request for uid=abarnes,ou=Employees,dc=example,dc=com
MODIFY DN operation successful for DN uid=abarnes,ou=Employees,dc=example,dc=com
Processing MODIFY DN request for uid=abergin,ou=Employees,dc=example,dc=com
MODIFY DN operation successful for DN uid=abergin,ou=Employees,dc=example,dc=com
...
Processing MODIFY DN request for uid=wlutz,ou=Employees,dc=example,dc=com
MODIFY DN operation successful for DN uid=wlutz,ou=Employees,dc=example,dc=com
$ ldapdelete
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
ou=Employees,dc=example,dc=com
Processing DELETE request for ou=Employees,dc=example,dc=com
DELETE operation successful for DN ou=Employees,dc=example,dc=comDeleting EntriesWith the ldapmodify command, authorized users
can delete entries from the directory.Delete: Removing a SubtreeThe following example uses the subtree delete option to remove
all Special Users from the directory.$ ldapdelete
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
--deleteSubtree "ou=Special Users,dc=example,dc=com"
Processing DELETE request for ou=Special Users,dc=example,dc=com
DELETE operation successful for DN ou=Special Users,dc=example,dc=comChanging PasswordsPasswordsChangingWith the ldappasswordmodify command, authorized
users can change and reset user passwords.Password ResetThe following example shows Kirsten Vaughan resetting Sam Carter's
password. Kirsten has the appropriate privilege to reset Sam's
password.$ ldappasswordmodify
--useStartTLS
--port 1389
--bindDN "uid=kvaughan,ou=people,dc=example,dc=com"
--bindPassword bribery
--authzID "dn:uid=scarter,ou=people,dc=example,dc=com"
--newPassword ChangeMe
The LDAP password modify operation was successfulWhenever one user changes another user's password, OpenDJ considers
it a password reset. That often means the user has to change her password
again after the reset.If you want your application to change a user's password, rather
than reset a user's password, have your application request the password
change as the user whose password is changing. To change the password as
the user, either bind as the user or use proxied authorization. For
instructions on the latter, see the section on Configuring
Proxied Authorization.You could also accomplish password reset with the following command,
but set-password-is-reset is a hidden option, supported
only for testing.$ manage-account
set-password-is-reset
--bindDN "cn=Directory Manager"
--bindPassword password
--targetDN uid=scarter,ou=people,dc=example,dc=com
--operationValue true
Password Is Reset: trueChange Own PasswordYou can use the ldappasswordmodify command to
change your password, as long as you know your current password.$ ldappasswordmodify
--port 1389
--authzID "dn:uid=bjensen,ou=people,dc=example,dc=com"
--currentPassword hifalutin
--newPassword secret12
The LDAP password modify operation was successfulThe same operation works for cn=Directory
Manager.$ ldappasswordmodify
--port 1389
--authzID "dn:cn=Directory Manager"
--currentPassword password
--newPassword secret12
The LDAP password modify operation was successfulPasswords With Special CharactersOpenDJ expects passwords to be UTF-8 encoded (base64 encoded when
included in LDIF).$ echo $LANG
en_US.utf8
$ ldappasswordmodify
--port 1389
--bindDN uid=bjensen,ou=People,dc=example,dc=com
--bindPassword hifalutin
--currentPassword hifalutin
--newPassword pàsswȏrd
The LDAP password modify operation was successful
$ ldapsearch
--port 1389
--bindDN uid=bjensen,ou=People,dc=example,dc=com
--bindPassword pàsswȏrd
--baseDN dc=example,dc=com
"(uid=bjensen)" cn
dn: uid=bjensen,ou=People,dc=example,dc=com
userPassword: {SSHA}k0eEeCxj9YRXUp8yJn0Z/mwqe+wrcFb1N1gg2g==
cn: Barbara Jensen
cn: Babs Jensen
If you forget the password for cn=Directory Manager,
then one remedy uses the following steps.Generate an encoded password value using the
encode-password command.By default, the password for Directory Manager uses the SSHA512
password storage scheme. In the following example, the encoded password
is wrapped to fit on a printed page.$ encode-password --storageScheme SSHA512 --interactivePassword
Please enter the password :
Please renter the password:
Encoded Password:
"{SSHA512}U7Kx5oYcLxdsqSrpSkBk425LwL0Z61loNfS0dBVCcEKVhMyTT
oe3oWikDJ/AJjKEkYBg+q3VUQ5hWgrGVf7MjfDrm5mum6yI"Stop OpenDJ.Edit config/config.ldif, replacing the
userPassword value on the entry for
cn=Directory Manager,cn=Root DNs,cn=config with
the encoded password, taking care not to leave any whitespace at the
end of the line.Start OpenDJ.Configuring Default SettingsPortsSettings for toolsYou can use ~/.opendj/tools.properties to set
the defaults for bind DN, host name, and port number as in the following
example.hostname=directory.example.com
port=1389
bindDN=uid=kvaughan,ou=People,dc=example,dc=com
ldapcompare.port=1389
ldapdelete.port=1389
ldapmodify.port=1389
ldappasswordmodify.port=1389
ldapsearch.port=1389The location on Windows is
%UserProfile%/.opendj/tools.properties.Configuring Proxied AuthorizationProxied authorizationProxied authorization provides a standard control as defined in RFC 4370 (and an
earlier Internet-Draft) for binding with the user credentials of a proxy, who
carries out LDAP operations on behalf of other users. You might use proxied
authorization, for example, to have your application bind with its
credentials, and then carry out operations as the users who login to the
application.Suppose you have an administrative directory client application that
has an entry in the directory with DN
cn=My App,ou=Apps,dc=example,dc=com. You can give that
application the access rights and privileges to use proxied authorization.
The default access control for OpenDJ permits authenticated users to use
the proxied authorization control.Suppose also that when directory administrator, Kirsten Vaughan, logs
in to your application to change Babs Jensen's entry, your application looks
up Kirsten's entry, and finds that she has DN
uid=kvaughan,ou=People,dc=example,dc=com. For the example
commands in the following procedure. My App uses proxied authorization to
make a change to Babs's entry as Kirsten.To Set Up Proxied AuthorizationGrant access to applications that can use proxied authorization.$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
dn: dc=example,dc=com
changetype: modify
add: aci
aci: (target="ldap:///dc=example,dc=com") (targetattr ="*
")(version 3.0; acl "Allow apps proxied auth"; allow(all, proxy
)(userdn = "ldap:///cn=*,ou=Apps,dc=example,dc=com");)
Processing MODIFY request for dc=example,dc=com
MODIFY operation successful for DN dc=example,dc=comGrant the privilege to use proxied authorization to My App.$ ldapmodify
--port 1389
--bindDN "cn=Directory Manager"
--bindPassword password
dn: cn=My App,ou=Apps,dc=example,dc=com
changetype: modify
add: ds-privilege-name
ds-privilege-name: proxied-auth
Processing MODIFY request for cn=My App,ou=Apps,dc=example,dc=com
MODIFY operation successful for DN cn=My App,ou=Apps,dc=example,dc=comTest that My App can use proxied authorization.$ ldapmodify
--port 1389
--bindDN "cn=My App,ou=Apps,dc=example,dc=com"
--bindPassword password
--proxyAs "dn:uid=kvaughan,ou=People,dc=example,dc=com"
dn: uid=bjensen,ou=People,dc=example,dc=com
changetype: modify
replace: description
description: Changed through proxied auth
Processing MODIFY request for uid=bjensen,ou=People,dc=example,dc=com
MODIFY operation successful for DN uid=bjensen,ou=People,dc=example,dc=com