Portlet Factory, Version 6.1.2


 

The UserInfo.java interface

The UserInfo.java interface is the one you implement to provide access to additional/custom user attributes.

The interface itself is shown in the Javadoc documentation supplied with the IBM® WebSphere Portlet Factory API documentation. A default implementation for J2EE security, which provides nothing but the username/user id, is shown below:

public class WebAppUserInfo implements UserInfo private HttpServletRequest request = null; private static final String[] supportedAttrs = {UserInfo.USER_ID}; private static final List supportedAttrList= Arrays.asList(supportedAttrs);
/**
* getUserID
*
* Get a String representation of the userID/username - the primary
* identity key that the caller is authenticated with.
*
* @return String username / userid or null if user not authenticated
*/ public String getUserID() return request.getRemoteUser();
/**
* getKnownAttributeNames
*
* Return an iterator over a list of strings representing the known
* (to the particular custom instance of the handler) attribute
* types/names to be used with getAttribute(String attributeName) below.
*
* The list will likely be specific to each custom handler, but should
* always include at least "username" (which can represent a requestor id
* if this is a server to server scenario with no users), so modelers can
* rely on at least one common piece of information across all user
* registries and all UserInfo handlers.
*
* @return java.util.Iterator
*/ public Iterator getKnownAttributeNames() return supportedAttrList.iterator();
/**
* getAttribute
*
* Return the attribute value for the specified attribute name.
*
* In most cases, the return value will always be a java.lang.String,
* but the interface allows for the return value to be any Object
* derivation, to allow for custom handlers to pass back custom objects
* (eg, X509Certificate object in a PKI implementation) where callers
* can make use of such data.
*
* @param String attribute name (eg, "username")
* @return java.lang.Object usually a string value but may be a custom object
*/ public Object getAttribute(String attributeName)
// Only username supported in the default handler if (attributeName.equals(UserInfo.USER_ID)) return getUserID(); else return null;
/**
* setRequest
*
* Allow calling infrastructure to give the handler a reference to the
* HttpServletRequest, from which user info, session info and other
* related info may be obtained by the above methods.
*/ public void setRequest(HttpServletRequest request) this.request = request;
}

Parent topic: Gathering user information


Library | Support |