User Management Guide

CHAPTER 8

Accessing User Attributes

This chapter discusses profiling with user attributes and has these sections:

For more information    For background information, see Managing User Profiles.

 
Top of page

About attributes

Attributes are individual data items within a user profile. Each attribute corresponds to a column or field (in database terminology).

Attributes can be any data that you want to associate with a user. The User subsystem has a set of built-in attributes and you can create and use your own user attributes for user profiling.

 
Top of section

Built-in attributes

The following built-in string attributes are present in each user profile regardless of realm configuration:

The values of the User ID and User UUID attributes are used by many of the exteNd Director API packages to identify users.

New User portlet   The New User portlet is a core portlet used in a Portal application in exteNd Director projects. It allows anonymous users to add themselves to the writable realm and automatically creates a profile for each new user. This profile includes the built-in attributes.

For more information    For more information, see About the New User portlet.

 
Top of section

Attributes and non-LDAP realms

Applications that use a writable non-LDAP realm use the application database to store profile information. By default, the profiles in the database contain only built-in attributes. These applications can create custom attributes as needed.

For more information    For an example, see Creating an attribute (non-LDAP).

 
Top of section

Attributes and LDAP realms

Applications that use an LDAP realm use the LDAP directory to store profile information. LDAP provides a rich set of attributes that are intended to be sufficient to meet the requirements of most Web applications. Use the LDAP administration console to add new (custom) attributes to the directory.

NOTE:   You cannot add custom attributes to an LDAP directory from an exteNd Director application.

The User API provides a way for an application to retrieve a list of all available LDAP attributes. The User LDAP Options panel in the EAR Wizard allows you to make specific attributes available to the User API and to exclude others. It also allows you to exclude certain syntax definitions.

For more information    For more information, see the section on LDAP user options in Developing exteNd Director Applications.

 
Top of page

Attribute properties

Each attribute has a name, a description, a display property, and a data type.

 
Top of section

Display properties

Each attribute has a display property that can have either of two values:

Attribute usage

Description

Displayable

Information you collect directly from a user, such as personal data or preferences. The user typically specifies this information on a registration form.

Hidden

Information you store that is not explicitly provided by the user—for example, buying patterns or click stream counts.

 
Top of section

Data types

There are two types of attribute data values:

BLOB attributes are used to store binary data (such as large documents and images) in the form of a byte array. Separate API methods are provided for using BLOB attributes.

NOTE:   The User API supports multivalued attributes for applications that use an LDAP realm. The Director Administration Console (DAC) also allows the display and modification of existing values for these attributes.

 
Top of page

Accessing attributes using the API

You can define whatever attributes you need and use them in your code to personalize content. This section describes how to access attributes and how to create and set custom attributes.

For more information    For an overview of the User API, see Accessing profiles using the API.

Accessing attributes using the DAC   You can also use the Director Administration Console (DAC) to access user attributes.

For more information    For more information, see Using the Profiles Section of the DAC.

 
Top of section

Getting a list of attributes (non-LDAP)

This code shows how to obtain a user profile and display all the custom attributes. Note that the EbiUserInfo object has a specific method for each built-in attribute:

  import com.sssw.fw.usermgr.api.*;
  import com.sssw.fw.usermgr.client.*;
  
  try {
      //
      // Get the user identifier.
      //
      String userUUID = EboUserHelper.getUserUUID(context);
      //
      // Get a user delegate object from the factory.
      //
      EbiUserDelegate userDelegate = EboFactory.getUserDelegate();
      //
      // Get a user info object.
      //
      EbiUserInfo userInfo =
          (EbiUserInfo)userDelegate.
              getUserInfoByUserUUID(context,userUUID);
      //
      // Get the registration info and add to output buffer.
      //
      sb.append("UserID: " + userInfo.getUserID() + "<br>");
      sb.append("UserUUID: " + userInfo.getUserUUID() + "<br>");
      sb.append("UserFirstName: " + 
          userInfo.getUserFirstName() + "<br>");
      sb.append("UserLastName: " + 
          userInfo.getUserLastName() + "<br>");
      sb.append("UserEmailAddress: " + 
          userInfo.getUserEmailAddress() + "<br>");
      //
      // Get a user metadelegate object from the factory.
      //
      EbiUserMetaDelegate userMetaDelegate =                 EboFactory.getUserMetaDelegate();
      //
      // Get the current user's metadata.
      //
      EbiUserMeta userMeta = userMetaDelegate.getUserMeta(context);
      if (userMeta == null) {
          userMeta = userMetaDelegate.createUserMeta();
          userMetaDelegate.addUserMeta(context, userMeta);
      }
      else {
          //
          // Get all custom attribute names and values. 
          // Add to output buffer.
          //
          String[] attributes = userMeta.getUserAttributes();
          if (attributes == null) {
              sb.append("No attributes - string array is null");
          }
          else {
              for (int i=0;i<attributes.length;i++) {
                  String attributeValue =
                   userInfo.getAttributeValue(context,attributes[i]);
                  sb.append(attributes[i] + ": " + 
                      attributeValue + "<br>");
              }
          }
      }
  }
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }

NOTE:   When you run this on a profile that has no custom attributes, the EbiUserMeta object is null.

 
Top of section

Getting a list of attributes (LDAP)

To retrieve specific attribute values directly from an LDAP directory, use:

  EboUserHelper.getDirectoryUserAttributes(context, userdn, String[] names)

This method inputs the context, the user DN string, and an array of strings naming the attributes for which to return values. The return value is a Map (object array) containing values for each requested user attribute.

NOTE:   This method returns only the first value of a multivalued attribute.

Identifying multivalued attributes

When using an LDAP directory, attributes can have multiple values. To check for this type of attribute, use:

  EbiUserMeta.isUserAttributeSingleValued(attrname)

This method returns a boolean value indicating whether or not the specified attribute is limited to a single value.

 
Top of section

Creating an attribute (non-LDAP)

This code adds a custom attribute to a user profile:

  import com.sssw.fw.usermgr.api.*;
  
  try {
      //
      // Get a user metadelegate object from the factory.
      //
      EbiUserMetaDelegate userMetaDelegate =         com.sssw.fw.usermgr.client.
              EboFactory.getUserMetaDelegate();
      //
      // Get a writable copy of the user metadata.
      //
      EbiUserMeta userMeta =         userMetaDelegate.getClonedUserMeta(context);
      //
      // Add a custom attribute.
      //
      String attrib_name = "Employer";
      userMeta.addUserAttribute(attrib_name,"Name of employer",true);
      //
      // Save the modified metadata including the new attribute.
      //
      userMetaDelegate.modifyUserMeta(context,userMeta);
      //
      // Return the attribute name and value.
      //
      sb.append("Added attribute: " + attrib_name);
  } 
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }

 
Top of section

Setting an attribute value

This code sets the value of a custom attribute:

  import com.sssw.fw.usermgr.api.*;
  
  try {        
      //
      // Get a user delegate object from the factory.
      //
      EbiUserDelegate userDelegate = 
          com.sssw.fw.usermgr.client.EboFactory.getUserDelegate();
      //
      // Get a user info object from the factory.
      //
      EbiUserInfo userInfo =         com.sssw.fw.usermgr.client.EboUserHelper.
              getUserInfo(context);
      //
      // Set the value of the attribute to Novell.
      //
      String attrib_name = "Employer";
      userInfo.setAttributeValue(context, attrib_name, "Novell");
      //
      // Write the new value into the user info object.
      //
      userDelegate.modifyUser(context,userInfo);
      //
      // Get the new attribute value and append to output buffer.
      //
      sb.append(attrib_name + ": " + 
          userInfo.getAttributeValue(context, attrib_name));        
  } 
  catch (EboFactoryException e) { sb.append( e.getMessage() ); }        
  catch (EboSecurityException e) { sb.append( e.getMessage() ); }


Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...