Pages

Friday, 10 June 2016

A Quick & Easy Way to Create Test Users in OpenAM

More often then not we need ways to create test users and this isn't something that we want to spend large amounts of time doing. Helpfully OpenAM comes bundled with a script which can quickly let you do this.

There is a script named make-ldif that can be found here: openam/opends/bin


This script generates an ldif file that contains a set of test users which randomly generate names, email addresses and other attributes. An example of this output is below:


 dn: uid=user.41,ou=People,dc=example,dc=com  
 objectClass: top  
 objectClass: person  
 objectClass: organizationalperson  
 objectClass: inetorgperson  
 givenName: Addie  
 sn: Achille  
 cn: Addie Achille  
 initials: AJA  
 employeeNumber: 41  
 uid: user.41  
 mail: user.41@example.com  
 userPassword: password  
 telephoneNumber: +1 892 829 0033  
 homePhone: +1 307 295 8896  
 pager: +1 397 006 1503  
 mobile: +1 168 140 0201  
 street: 86587 Hillcrest Street  
 l: Santa Fe  
 st: NJ  
 postalCode: 76090  
 postalAddress: Addie Achille$86587 Hillcrest Street$Santa Fe, NJ 76090  
 description: This is the description for Addie Achille.  
To run the script, you need to configure the example.template file to match your environment and user attributes.
 define suffix=dc=example,dc=com  
 define maildomain=example.com  
 define numusers=10001  
 branch: [suffix]  
 branch: ou=People,[suffix]  
 subordinateTemplate: person:[numusers]  
 template: person  
 rdnAttr: uid  
 objectClass: top  
 objectClass: person  
 objectClass: organizationalPerson  
 objectClass: inetOrgPerson  
 givenName: <first>  
 sn: <last>  
 cn: {givenName} {sn}  
 initials: {givenName:1}<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}  
 employeeNumber: <sequential:0>  
 uid: user.{employeeNumber}  
 mail: {uid}@[maildomain]  
 userPassword: password  
 telephoneNumber: <random:telephone>  
 homePhone: <random:telephone>  
 pager: <random:telephone>  
 mobile: <random:telephone>  
 street: <random:numeric:5> <file:streets> Street  
 l: <file:cities>  
 st: <file:states>  
 postalCode: <random:numeric:5>  
 postalAddress: {cn}${street}${l}, {st} {postalCode}  
 description: This is the description for {cn}.  
The key attributes to change are:
define suffix=dc=example,dc=com  
define maildomain=example.com  
define numusers=10001  
Set the suffix and maildomain to match the installation of your OpenAM instance. 
Set numusers to the number of test users you want to generate. I usually use about 500.

You will also need to add any attributes that you need users in the schema to have by default. 



To save time, I have attached an example.template that will work perfectly with a clean installation of OpenAM that has the default out of the box domain suffix and attribute schema. Download it from here.

Once you have an example.template. You can run the make-ldif script using the command below, users.ldif is the desired output file:

 ./make-ldif -t ../config/MakeLDIF/example.template -o /usr/local/tools/users.ldif  
Finally, you can use the ldapadd tool to process users.ldif and create the users:
 ldapadd -h localhost -p 50389 -D "cn=Directory Manager" -w cangetinam -f /usr/local/tools/users.ldif -c  
The ldapadd tool will connect to the embedded DJ directory, ensure you update the host (-h), port (-p), bindDN (-D) and password (-w) to match your installation.

This should result with an OpenAM instance fully populated with users.






No comments:

Post a Comment