Displaying Users
Prerequisites
You have imported the required interfaces and gotten the required factories.
More information: User Management Functions for Users .
Context
This procedure describes how you can get a user and read an attribute of that user. Use this procedure when you need to display user data and no existing application suits your needs. Once your custom application has read the data, you must decide how to display it.
Procedure
Example
This example gets the user demo_user and reads the attribute myAttributeName in the com.example namespace.
public static void showUser(String logonID, String nameSpace,
String attributeName) {
try {
// Get the user.
IUser user = userFactory.getUserByLogonID(logonID);
// Show basic data.
String firstname = user.getFirstName();
String lastname = user.getLastName();
String email = user.getEmail();
/*
* Check the attribute type and read the attribute content with the
* corresponding method.
*/
String attributeType = user.getAttributeType(nameSpace, attributeName);
if (attributeType == IPrincipal.STRING_TYPE) {
// Read the content of a multi-value string attribute.
String[] attributeValues = user.getAttribute(nameSpace,
attributeName);
} else if (attributeType == IPrincipal.BYTE_TYPE) {
// Read the content of a single-value binary attribute.
byte[] attributeValue = user.getBinaryAttribute(nameSpace,
attributeName);
} else {
// TODO: Handle attribute not available or does not exist.
}
} catch (NoSuchUserException nsuex) {
// TODO: Handle NoSuchUserException.
} catch (NoSuchUserAccountException nsauex) {
// TODO: Handle NoSuchUserAccountException.
} catch (UMException umex) {
// TODO: Handle UMException,
} catch (UMRuntimeException umrex) {
// TODO: Handle UMRuntimeException.
}
}