Community articleUser SPI
Added by IBM contributorIBM on June 26, 2014
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

You can use the IBM® Connections User SPIs to access information about the users in your IBM Connections deployment.



You can use the IBM® Connections User SPIs to access information about the users in your IBM Connections deployment.

You can use the User SPI to learn the following things about users:
  • Unique user ID as it is populated by the user registry. This is also known as the external ID.
  • Login IDs which are the one or more IDs used by a person to log into the application.
  • Display name, which is the name that is displayed in the user interface to represent the person. This might be a nickname instead of the person's full name, for example.
  • Email address, if email is configured and email addresses are not being kept private.
  • Status. This value indicates whether the person is an active or inactive employee.
You must have one of the following pieces of information about the person before you can retrieve more information:
  • Unique user ID
  • Login ID
  • Email address
If you attempt to retrieve information for a user who is not found in the directory, a UserNotFoundException message is displayed.

The lc.spi.jar file contains the Server and User SPIs and is stored in the EAR file in the root installation directory of the following IBM Connections applications: Activities, Blogs, Communities, Bookmarks, Files, Forums, News, and Wikis.

The following code sample retrieves all available information about a user based on first, the person's email address, then her user ID, and lastly, her login ID.

import java.util.List;
 
import com.ibm.connections.spi.user.User;
import com.ibm.connections.spi.user.UserHelper;
import com.ibm.connections.spi.user.UserNotFoundException;
 
 
public class UserSPIExample {
 
	public void lookupUserByEmail(String emailAddress) {
		try { 
			User user = 
        UserHelper.INSTANCE().getUserByEmailAddress(emailAddress);
			
			printUser(user);
		} catch (UserNotFoundException unfe) {
			// User doesn't exist
		}
	}
	
	public void lookupUserByUserID(String userID) {
		try { 
			User user = UserHelper.INSTANCE().getUserByExtID(userID);
			
			printUser(user);
		} catch (UserNotFoundException unfe) {
			// User doesn't exist
		}
	}
	
	public void lookupUserByLoginID(String loginID) {
		try { 
			User user = 
       UserHelper.INSTANCE().getUserByLoginID(loginID);
			
			printUser(user);
		} catch (UserNotFoundException unfe) {
			// User doesn't exist
		}
	}
	
	private void printUser(User user) {
		System.out.println("User (Ext) ID: " + user.getExtID());
		System.out.println("User display name: " + user.getDisplayName());
		System.out.println("User Email address: " + user.getEmailAddress());
		System.out.print("Login IDs: ");
		List<String> loginIDs = user.getLoginIDs();
		for(String loginID : loginIDs) {
			System.out.print(loginID + " ");
		}
		System.out.println("User status: " + user.getStatus());
	}
}


You can either: