Show TOC

Implementing a Custom User Photo ServiceLocate this document in the navigation structure

Use

If the default photo service does not suit your organization's requirements, you can develop and register a custom photo service.

The service should extend the AbstractPhoto interface, located in the com.sap.workspaces.workspace package.

import com.sap.security.api.IUser;
import com.sap.security.api.UMFactory;
import com.sap.workspaces.workspace.AbstractPhoto;
import com.sapportals.portal.prt.service.IService;
import com.sapportals.portal.prt.service.IServiceContext;

/**
 * A sample service that returns the URL of the specified user's photo 
 * 
 */
public class CustomPhoto extends AbstractPhoto implements IService {

	public String getURL(IUser user) {
		IUser loggedInUser = UMFactory.getAuthenticator().getLoggedInUser();

		// Custom logic for retrieving photos
 		if (isAuthorised(loggedInUser, user)) {
			if (user.isMemberOfGroup("group_x", true)) {
				// Photos of the group_x members are in the "johnsmith.jpg" format
				return "http://someserver/photo/"+user.getFirstName()+user.getLastName()+".jpg";
			} else {
				// Photos of all other users are in the "john.smith.png" format
				String email = user.getEmail();
				if (email != null) {
					return "http://someserver/photo/"+email.substring(0, email.indexOf("@"))+".png";
				}
			}
		}
		// Null is a valid return value
		return null;
	}

	 // If your organisation has a privacy policy regarding visibility of photos 
	 	private boolean isAuthorised(IUser loggedInUser, IUser user) {
		// Implement the privacy policy ...
		return true;
	}
}
Registering Your Service

To register your photo service:

  1. Finalize and deploy the service to the portal.

  2. Log on to the portal in the Workspaces System Administration role.

  3. Navigate to Start of the navigation path Workspace Administration Next navigation step  Configuration  Next navigation step Features End of the navigation path.

  4. In the User Photo Implementation field, enter prt_service:<your service key>. Ignore the URL Pattern field.

Note

After you have registered a custom photo service, it will replace the default one, and thus impact all user interfaces of enterprise workspaces that display user photos.