OpenDJ: Custom data types

OpenDJ logo OpenDJ comes with many object classes and attribute types already defined. But what if your data uses custom attributes?

You can customize the data types available by extending directory schema, even while OpenDJ is running, and then add your new data without restarting the server. Here’s how to get started.

When you open OpenDJ Control Panel in the Schema list you see Manage Schema. Click Manage Schema to open the window that you can use to view and update the directory schema, which define object classes, attribute types, matching rules, and attribute syntaxes.

  • Object classes govern which attributes a directory entry must include and may optionally include.
  • Attribute types define the individual attributes.
  • Matching rules how to sort and compare attribute values for different syntaxes and languages.
  • Attribute syntaxes identify syntax rules for attribute values.
OpenDJ includes many, many standard schema definitions. You may be able to find a definition close to what you need.
Manage Schema window

If you cannot find a standard definition that fits your needs, you can use the New Attribute… and New Object Class… buttons to add your own definitions.

For example, assume you want to add an attribute called blogURL, an optional attribute attached to entries that correspond to people in your directory.

To define the attribute type, click New Attribute… and fill in the fields, then click OK.

  • Name: blogURL
  • OID: my-blog-url-temp-oid
  • Description: Link to a blog
If you want to share this definition, you will want to get a real OID (object identifier). But for now, just use a fake, temporary oid.

As the object class for an entry defines what attributes the entry can  have, you need to define not only the attribute type blogURL, but also the object class that tells the directory, “This entry can have a blogURL attribute.” Call the object class blogAuthor. Since a person might have a blogURL, but blogURL does not warrant its own, standalone object, this object class is going to be an Auxiliary object class, rather than a Structural object class.

To define the object class, click New Object Class… and fill in the fields, then click OK.

  • Name: blogAuthor
  • OID: my-blog-author-temp-oid
  • Description: A blogger
  • Optional Attributes: blogURL
  • Extra options > Type: Auxiliary

Now if you search for blog in the Manage Schema window, you can see your attribute type and object class.

To try it out, go back to OpenDJ Control Panel and open the Manage Entries window.

Find a person who has a blog, and click the Edit… button next to the list of object classes on the entry, so you can use the Edit Object Class window to add the blogAuthor auxiliary object class.

Clear Only Show Attributes with Values to display a number of fields for optional attributes, including blogURL. Then add the blogURL in the field provided and click Save Changes.

Here’s a representation of my result in LDIF format.

$ ./OpenDJ/bin/ldapsearch -p 1389 -b dc=example,dc=com uid=mark
dn: uid=mark,ou=People,dc=example,dc=com
tomcatRole: Admin
uid: mark
facsimileTelephoneNumber: +1 408 555 4661
blogURL: https://marginnotes2.wordpress.com/
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
objectClass: tomcatRoleAllowed
objectClass: blogAuthor
givenName: Mark
cn: Mark Craig
sn: Craig
telephoneNumber: +1 408 555 1846
roomNumber: 3819
homeDirectory: /home/mark
mail: mark@example.com
l: Santa Clara
ou: Accounting
ou: People
uidNumber: 1000
gidNumber: 119

That’s it. Oh, by the way, you can of course do all of this on the command line, too. Have a good weekend.

Advertisements

7 thoughts on “OpenDJ: Custom data types

  1. Thank you but after I add a custom attribute to person in extended opendj, I can’t create a new user. I wonder why?

    1. Person is a standard object class, so rather than override it you can create an object class that derives from person, add that object class to the entry that needs a custom attribute, and then add the custom attribute.

  2. heyy I am looking to have key value pair entries in a ldap server(i am using opendj). Can you point me tell me how I can accomplish this.

    1. LDAP entries are themselves basically key-value maps, if you consider the attribute name as the key and the attribute value as the value.

      Because directory servers have traditionally been central sources of shared data, OpenDJ by default enforces schema. In other words, OpenDJ does not by default let you add arbitrary attribute names (keys) into entries. If you want to do that, you can turn off schema checking, but I’d only do that if no other applications are using the directory.

  3. Can you please explain how to make the new class as the default object class for all new entries that are going to be created?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s