taylor 2004/08/11 16:59:11
Modified: fusion/src/java/org/apache/jetspeed/fusion/userinfo/impl
FusionUserInfoManagerImpl.java
Log:
Fusion User Attribute Manager implementation
Gets user attributes from JetspeedUser
You can add attributes by storing them in TurbineUser's "Perm" storage and giving
them a "user." prefix that corresponds with the portlet api's user attributes
definitions in appendex D
Also supports J2's user attribute ref feature (defined extended attributes in the
jetspeed-portlet.xml)
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.2 +113 -9
jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/userinfo/impl/FusionUserInfoManagerImpl.java
Index: FusionUserInfoManagerImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/userinfo/impl/FusionUserInfoManagerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FusionUserInfoManagerImpl.java 11 Aug 2004 21:24:59 -0000 1.1
+++ FusionUserInfoManagerImpl.java 11 Aug 2004 23:59:11 -0000 1.2
@@ -14,14 +14,22 @@
*/
package org.apache.jetspeed.fusion.userinfo.impl;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
+import org.apache.jetspeed.om.common.UserAttributeRef;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
import org.apache.jetspeed.userinfo.UserInfoManager;
+import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
import org.apache.pluto.om.common.ObjectID;
import org.apache.turbine.services.rundata.RunDataService;
import org.apache.turbine.services.TurbineServices;
@@ -37,12 +45,18 @@
* @author <a href="mailto:taylorapache.org">David Sean Taylor</a>
* @version $Id$
*/
-public class FusionUserInfoManagerImpl implements UserInfoManager
+public class FusionUserInfoManagerImpl extends AbstractUserInfoManagerImpl
implements UserInfoManager
{
+ private static final Log log =
LogFactory.getLog(FusionUserInfoManagerImpl.class);
+
+ private final static String FUSION_USER_INFO =
"org.apache.jetspeed.fusion.userinfo";
+
private JetspeedRunDataService runDataService = null;
+ private PortletRegistryComponent registry;
- public FusionUserInfoManagerImpl()
- {
+ public FusionUserInfoManagerImpl(PortletRegistryComponent registry)
+ {
+ this.registry = registry;
}
/* (non-Javadoc)
@@ -50,7 +64,6 @@
*/
public Map getUserInfoMap(ObjectID oid, RequestContext context)
{
- System.out.println("-- Getting User INFO via Fusion/JetspeedUser");
JetspeedRunData rundata = getRunDataService().getCurrentRunData();
JetspeedUser user = rundata.getJetspeedUser();
@@ -59,13 +72,104 @@
return null;
}
- Map map = new HashMap();
- map.put("user.name.given", "Taylor");
- map.put("user.name.family", "Family");
- map.put("user.name.nickName", "Nick");
+ Map map = (Map)context.getAttribute(FUSION_USER_INFO);
+ if (map == null)
+ {
+ Map j1Map = createJetspeedUserMap(user);
+ MutablePortletApplication pa = registry.getPortletApplication(oid);
+ if (null == pa)
+ {
+ return null;
+ }
+ Collection userAttributes = pa.getUserAttributes();
+ Collection userAttributeRefs = pa.getUserAttributeRefs();
+ map = mapUserInfo(j1Map, userAttributes, userAttributeRefs);
+
+ }
return map;
}
+ /**
+ * <p>
+ * Maps the user info properties retrieved from the user preferences to the
+ * user info attribute declared in the portlet.xml descriptor.
+ * </p>
+ *
+ * @param j1Map
+ * The J1 user attributes.
+ * @param userAttributes
+ * The declarative portlet user attributes.
+ * @param userAttributeRefs
+ * The declarative jetspeed portlet extension user attributes
+ * reference.
+ * @return The user info map.
+ */
+ private Map mapUserInfo(Map j1Map, Collection userAttributes, Collection
userAttributeRefs)
+ {
+ if ((null == userAttributes) || (userAttributes.size() == 0))
+ {
+ return null;
+ }
+
+ Map userInfoMap = new HashMap();
+ Object[] propertyKeys = j1Map.keySet().toArray();
+
+ Collection linkedUserAttributes = mapLinkedUserAttributes(userAttributes,
userAttributeRefs);
+ Iterator iter = linkedUserAttributes.iterator();
+ while (iter.hasNext())
+ {
+ UserAttributeRef currentAttributeRef = (UserAttributeRef) iter.next();
+ if (null != currentAttributeRef)
+ {
+ for (int ix = 0; ix < propertyKeys.length; ix++)
+ {
+ if (null != currentAttributeRef.getNameLink())
+ {
+ if
((currentAttributeRef.getNameLink()).equals(propertyKeys[ix]))
+ {
+ userInfoMap.put(currentAttributeRef.getName(),
j1Map.get(propertyKeys[ix]));
+ }
+ }
+ else
+ {
+ if
((currentAttributeRef.getName()).equals(propertyKeys[ix]))
+ {
+ userInfoMap.put(currentAttributeRef.getName(),
j1Map.get(propertyKeys[ix]));
+ }
+ }
+ }
+ }
+ }
+
+ return userInfoMap;
+ }
+
+
+ /**
+ * Get the Jetspeed User Map -- override this to support extended Jetspeed User
info
+ *
+ * @param user
+ * @return map of jetspeed user attributes mapped to portlet api user attributes
+ */
+ protected Map createJetspeedUserMap(JetspeedUser user)
+ {
+ Map map = new HashMap();
+ map.put("user.name.given", user.getFirstName());
+ map.put("user.name.family", user.getLastName());
+ map.put("user.home-info.online.email", user.getEmail());
+ map.put("user.business-info.online.email", user.getEmail());
+ Iterator props = user.getPermStorage().entrySet().iterator();
+ while (props.hasNext())
+ {
+ Map.Entry entry = (Map.Entry)props.next();
+ if (entry.getKey().toString().startsWith("user."))
+ {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ }
+ return map;
+ }
+
private JetspeedRunDataService getRunDataService()
{
if (runDataService == null)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]