portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r918205 - in /portals/jetspeed-2/portal/branches/JETSPEED-2.1.4: components/portal/src/java/org/apache/jetspeed/engine/servlet/ components/portal/src/java/org/apache/jetspeed/userinfo/impl/ components/portal/src/test/JETSPEED-INF/spring/ co...
Date Tue, 02 Mar 2010 21:41:31 GMT
Author: ate
Date: Tue Mar  2 21:41:30 2010
New Revision: 918205

URL: http://svn.apache.org/viewvc?rev=918205&view=rev
Log:
Fix for JS2-1088: UserInfoManager implementation needs inprovements in resolving mapped user
attributes and its cache handling
See: http://issues.apache.org/jira/browse/JS2-1088

Modified:
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/AbstractUserInfoManagerImpl.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserInfoManagerImpl.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/JETSPEED-INF/spring/user-info.xml
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/src/webapp/WEB-INF/assembly/userinfo.xml

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
Tue Mar  2 21:41:30 2010
@@ -487,8 +487,10 @@
         Object value = super.getAttribute(name);
         if (name.equals(PortletRequest.USER_INFO))
         {
+            value = null;
             JetspeedRequestContext context = (JetspeedRequestContext) getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
-            if (null != context)
+            // USER_INFO only available (!=null) for authenticated user)
+            if (null != context && getUserPrincipal() != null)
             {
                 String entityID = "--NULL--";
                 PortletEntity entity = portletWindow.getPortletEntity();
@@ -509,7 +511,6 @@
                 {
                     log.error("Entity is null:" + entityID);
                 }
-
             }
         }
         else

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/AbstractUserInfoManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/AbstractUserInfoManagerImpl.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/AbstractUserInfoManagerImpl.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/AbstractUserInfoManagerImpl.java
Tue Mar  2 21:41:30 2010
@@ -25,6 +25,7 @@
 import org.apache.jetspeed.om.common.UserAttribute;
 import org.apache.jetspeed.om.common.UserAttributeRef;
 import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
+import org.apache.jetspeed.userinfo.UserInfoManager;
 
 /**
  * <p> Common user info management support
@@ -33,7 +34,7 @@
  * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
  * @version $Id$
  */
-public abstract class AbstractUserInfoManagerImpl
+public abstract class AbstractUserInfoManagerImpl implements UserInfoManager
 {
     /** Logger */
     private static final Log log = LogFactory.getLog(UserInfoManagerImpl.class);
@@ -53,6 +54,7 @@
      */
     protected Collection mapLinkedUserAttributes(Collection userAttributes, Collection userAttributeRefs)
     {
+        UserAttributeRefImpl impl;
         Collection linkedUserAttributes = new ArrayList();
         if ((null != userAttributeRefs) && (userAttributeRefs.size() > 0))
         {
@@ -61,29 +63,29 @@
             {
                 UserAttribute currentAttribute = (UserAttribute) attrIter.next();
                 boolean linkedAttribute = false;
-                if (null != currentAttribute)
+                impl = new UserAttributeRefImpl();
+                Iterator attrRefsIter = userAttributeRefs.iterator();
+                while (attrRefsIter.hasNext())
                 {
-                    Iterator attrRefsIter = userAttributeRefs.iterator();
-                    while (attrRefsIter.hasNext())
+                    UserAttributeRef currentAttributeRef = (UserAttributeRef) attrRefsIter.next();
+                    if ((currentAttribute.getName()).equals(currentAttributeRef.getNameLink()))
                     {
-                        UserAttributeRef currentAttributeRef = (UserAttributeRef) attrRefsIter.next();
-                        if (null != currentAttributeRef)
+                        if (log.isDebugEnabled())
                         {
-                            if ((currentAttribute.getName()).equals(currentAttributeRef.getNameLink()))
-                            {
-                                if (log.isDebugEnabled())
-                                    log.debug("Linking user attribute ref: [[name, " + currentAttribute.getName()
-                                            + "], [linked name, " + currentAttributeRef.getName()
+ "]]");
-                                linkedUserAttributes.add(currentAttributeRef);
-                                linkedAttribute = true;
-                            }
+                            log.debug("Linking user attribute ref: [[name, " + currentAttribute.getName()
+                                    + "], [linked name, " + currentAttributeRef.getName()
+ "]]");
                         }
+                        impl.setName(currentAttributeRef.getName());
+                        impl.setNameLink(currentAttributeRef.getNameLink());
+                        linkedAttribute = true;
+                        break;
                     }
                 }
                 if (!linkedAttribute)
                 {
-                    linkedUserAttributes.add(new UserAttributeRefImpl(currentAttribute));
+                    impl.setName(currentAttribute.getName());
                 }
+                linkedUserAttributes.add(impl);
             }
         }
         else
@@ -92,10 +94,11 @@
             while (attrIter.hasNext())
             {
                 UserAttribute currentAttribute = (UserAttribute) attrIter.next();
-                linkedUserAttributes.add(new UserAttributeRefImpl(currentAttribute));
+                impl = new UserAttributeRefImpl();
+                impl.setName(currentAttribute.getName());
+                linkedUserAttributes.add(impl);
             }
         }
         return linkedUserAttributes;
     }
-
 }

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/MultiSourceUserInfoManagerImpl.java
Tue Mar  2 21:41:30 2010
@@ -22,18 +22,14 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.portlet.PortletRequest;
 import javax.security.auth.Subject;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
-import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
 import org.apache.jetspeed.userinfo.UserAttributeSource;
-import org.apache.jetspeed.userinfo.UserInfoManager;
-import org.apache.jetspeed.userinfo.impl.AbstractUserInfoManagerImpl;
 import org.apache.pluto.om.common.ObjectID;
 
 /**
@@ -44,76 +40,47 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
  * @version $Id: $
  */
-public class MultiSourceUserInfoManagerImpl extends AbstractUserInfoManagerImpl
-        implements UserInfoManager
+public class MultiSourceUserInfoManagerImpl extends UserInfoManagerImpl
 {
 
     /** Logger */
-    private static final Log log = LogFactory
-            .getLog(MultiSourceUserInfoManagerImpl.class);
+    private static final Log log = LogFactory.getLog(MultiSourceUserInfoManagerImpl.class);
 
     private List sources;
 
-    private PortletRegistry portletRegistry;
-   
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.jetspeed.userinfo.UserInfoManager#getUserInfoMap(org.apache.pluto.om.common.ObjectID,
-     *      org.apache.jetspeed.request.RequestContext)
-     */
-    public Map getUserInfoMap(ObjectID oid, RequestContext context)
-    {
-
-        try
-        {
-            Map userInfoMap = new HashMap();
-            Subject subject = context.getSubject();
-            MutablePortletApplication pa = portletRegistry
-                    .getPortletApplication(oid);
-//System.out.println("*** PA = " + pa);            
-            if (null == pa)
-            {
-                log.debug(PortletRequest.USER_INFO + " is set to null");
-                return null;
-            }
-            Collection userAttributes = pa.getUserAttributes();
-            Collection userAttributeRefs = pa.getUserAttributeRefs();
-            Collection linkedUserAttributes = mapLinkedUserAttributes(
-                    userAttributes, userAttributeRefs);
-            for (Iterator iter = sources.iterator(); iter.hasNext();)
-            {
-                UserAttributeSource source = (UserAttributeSource) iter.next();
-                Map sourceMap;
-
-                sourceMap = source.getUserAttributeMap(subject,
-                        linkedUserAttributes, context);
-                userInfoMap.putAll(sourceMap);
-            }
-            return userInfoMap;
-        } catch (UserAttributeRetrievalException e)
-        {
-            // Until external api is changed return
-            e.printStackTrace();            
-            return null;
-        }
-    }
-
-    /**
-     * @param sources
-     *            The sources to set.
-     */
-    public void setSources(List sources)
-    {
-        this.sources = sources;
-    }
-
-    /**
-     * @param portletRegistry
-     *            The portletRegistry to set.
-     */
-    public void setPortletRegistry(PortletRegistry portletRegistry)
-    {
-        this.portletRegistry = portletRegistry;
-    }
+    public MultiSourceUserInfoManagerImpl(PortletRegistry registry, List sources)
+    {
+        super(registry);
+        this.sources = sources;
+    }
+
+    public Map getUserInfoMap(ObjectID oid, RequestContext context)
+    {
+        Map userInfoMap = new HashMap();
+        try
+        {
+            Subject subject = context.getSubject();
+            if (null != subject)
+            {
+                Collection linkedUserAttributes = getLinkedUserAttr(oid);
+                
+                for (Iterator iter = sources.iterator(); iter.hasNext();)
+                {
+                    UserAttributeSource source = (UserAttributeSource) iter.next();
+                    Map sourceMap = source.getUserAttributeMap(subject, linkedUserAttributes,
context);
+                    if (sourceMap != null)
+                    {
+                        userInfoMap.putAll(sourceMap);
+                    }
+                }
+            }
+        } 
+        catch (UserAttributeRetrievalException e)
+        {
+            // Until external api is changed return
+            log.error(e.getMessage(), e);          
+            return null;
+        }
+        return userInfoMap;
+    }
 }

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserInfoManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserInfoManagerImpl.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserInfoManagerImpl.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserInfoManagerImpl.java
Tue Mar  2 21:41:30 2010
@@ -16,14 +16,11 @@
  */
 package org.apache.jetspeed.userinfo.impl;
 
-import java.security.Principal;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
 
 import javax.portlet.PortletRequest;
 import javax.security.auth.Subject;
@@ -31,15 +28,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
-import org.apache.jetspeed.om.common.UserAttributeRef;
+import org.apache.jetspeed.components.portletregistry.RegistryEventListener;
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.SecurityException;
-import org.apache.jetspeed.security.SecurityHelper;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.security.UserPrincipal;
-import org.apache.jetspeed.userinfo.UserInfoManager;
 import org.apache.pluto.om.common.ObjectID;
 
 /**
@@ -51,43 +45,35 @@
  * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
  * @version $Id$
  */
-public class UserInfoManagerImpl extends AbstractUserInfoManagerImpl implements UserInfoManager
+public class UserInfoManagerImpl extends AbstractUserInfoManagerImpl implements RegistryEventListener
 {
 
     /** Logger */
     private static final Log log = LogFactory.getLog(UserInfoManagerImpl.class);
+    
+    /** Map to cache user info keys for each mapped portlet application. */
+    private static Map appUserInfoAttrCache = Collections.synchronizedMap(new HashMap());
 
-    // TODO Same caching issue as usual. We should look into JCS. That wil do
-    // for now.
-    /** Map used to cache user info maps for each mapped portlet application. */
-    private static Map userInfoMapCache;
-
-    /** The user information property set. */
-    String userInfoPropertySet;
-
+    private UserManagerUserAttributeSourceImpl userManagerUserAttributeSource;
+    
     /** The user manager */
-    UserManager userMgr;
+    protected UserManager userMgr;
 
     /** The portlet registry. */
-    PortletRegistry registry;
-
-    /** The object id of the portlet application being processed. */
-    String oid;
+    protected PortletRegistry registry;
 
+    protected UserInfoManagerImpl(PortletRegistry registry)
+    {
+        this.registry = registry;
+        registry.addRegistryListener(this);
+    }
     /**
-     * <p>
-     * Constructor providing access to the {@link UserManager}.
-     * </p>
-     * 
      * @param userMgr The user manager.
      * @param registry The portlet registry component.
      */
     public UserInfoManagerImpl(UserManager userMgr, PortletRegistry registry)
     {
-        this.userMgr = userMgr;
-        this.registry = registry;
-        this.userInfoPropertySet = User.USER_INFO_PROPERTY_SET;
-        initUserInfoMapCache();
+        this(userMgr,registry, User.USER_INFO_PROPERTY_SET);
     }
 
     /**
@@ -103,10 +89,9 @@
      */
     public UserInfoManagerImpl(UserManager userMgr, PortletRegistry registry, String userInfoPropertySet)
     {
+        this(registry);
         this.userMgr = userMgr;
-        this.registry = registry;
-        this.userInfoPropertySet = userInfoPropertySet;
-        initUserInfoMapCache();
+        this.userManagerUserAttributeSource = new UserManagerUserAttributeSourceImpl(userMgr,
userInfoPropertySet);
     }
 
     /**
@@ -115,148 +100,60 @@
      */
     public Map getUserInfoMap(ObjectID oid, RequestContext context)
     {
+        String appOid = oid.toString();
+        
         if (log.isDebugEnabled())
-            log.debug("Getting user info for portlet application: " + oid.toString());
-
-        // Check if user info map is in cache.
-        if (userInfoMapCache.containsKey(oid))
-        {
-            return (Map) userInfoMapCache.get(oid);
-        }
-        // Not in cache, map user info.
-        Preferences userPrefs = getUserPreferences(context);
-        if (null == userPrefs)
-        {
-            log.debug(PortletRequest.USER_INFO + " is set to null");
-            return null;
-        }
+            log.debug("Getting user info for portlet application: " + appOid);
 
-        MutablePortletApplication pa = registry.getPortletApplication(oid);
-        if (null == pa)
+        Map userInfo = null;
+        Subject subject = context.getSubject();
+        if (null != subject)
         {
-            log.debug(PortletRequest.USER_INFO + " is set to null");
-            return null;
-        }
-        Preferences userInfoPrefs = userPrefs.node(userInfoPropertySet);
-        Collection userAttributes = pa.getUserAttributes();
-        Collection userAttributeRefs = pa.getUserAttributeRefs();
-        Map userInfoMap = mapUserInfo(userInfoPrefs, userAttributes, userAttributeRefs);
-
-        return userInfoMap;
+            userInfo = userManagerUserAttributeSource.getUserAttributeMap(subject, getLinkedUserAttr(oid),
context);
+        }        
+        return userInfo;
     }
 
-    /**
-     * <p>
-     * Maps the user info properties retrieved from the user preferences to the
-     * user info attribute declared in the portlet.xml descriptor.
-     * </p>
-     * 
-     * @param userInfoPrefs The user info preferences.
-     * @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(Preferences userInfoPrefs, Collection userAttributes, Collection
userAttributeRefs)
+    protected Collection getLinkedUserAttr(ObjectID oid)
     {
-        if ((null == userAttributes) || (userAttributes.size() == 0))
-        {
-            return null;
-        }
-
-        Map userInfoMap = new HashMap();
-        String[] propertyKeys = null;
-        try
-        {
-            propertyKeys = userInfoPrefs.keys();
-            if ((null != propertyKeys) && log.isDebugEnabled())
-                log.debug("Found " + propertyKeys.length + " children for " + userInfoPrefs.absolutePath());
-        }
-        catch (BackingStoreException bse)
-        {
-            log.error("BackingStoreException: " + bse.toString());
-        }
-        if (null == propertyKeys)
-        {
-            return null;
-        }
-
-        Collection linkedUserAttributes = mapLinkedUserAttributes(userAttributes, userAttributeRefs);
-        Iterator iter = linkedUserAttributes.iterator();
-        while (iter.hasNext())
+        // Check if user info map is in cache.
+        Collection linkedUserAttr = (List)appUserInfoAttrCache.get(oid);
+        
+        if (linkedUserAttr == null)
         {
-            UserAttributeRef currentAttributeRef = (UserAttributeRef) iter.next();
-            if (null != currentAttributeRef)
+            MutablePortletApplication pa = registry.getPortletApplication(oid);
+            if (null == pa)
             {
-                for (int i = 0; i < propertyKeys.length; i++)
-                {
-                    if (null != currentAttributeRef.getNameLink())
-                    {
-                        if ((currentAttributeRef.getNameLink()).equals(propertyKeys[i]))
-                        {
-                            userInfoMap.put(currentAttributeRef.getName(), userInfoPrefs.get(propertyKeys[i],
null));
-                        }
-                    }
-                    else
-                    {
-                        if ((currentAttributeRef.getName()).equals(propertyKeys[i]))
-                        {
-                            userInfoMap.put(currentAttributeRef.getName(), userInfoPrefs.get(propertyKeys[i],
null));
-                        }
-                    }
-                }
+                log.debug(PortletRequest.USER_INFO + " is set to null");
+                return null;
             }
+            Collection userAttributes = pa.getUserAttributes();
+            Collection userAttributeRefs = pa.getUserAttributeRefs();
+            linkedUserAttr = mapLinkedUserAttributes(userAttributes, userAttributeRefs);
+            appUserInfoAttrCache.put(oid, linkedUserAttr);
         }
-
-        userInfoMapCache.put(oid, userInfoMap);
-
-        return userInfoMap;
+        return linkedUserAttr;
+    }
+    
+    public void applicationRemoved(MutablePortletApplication app)
+    {
+        // clear cache element
+        appUserInfoAttrCache.remove(app.getId());
     }
 
-    /**
-     * <p>
-     * Gets the user preferences from the user's request.
-     * </p>
-     * <p>
-     * If no user is logged in, return null.
-     * </p>
-     * 
-     * @param context The request context.
-     * @return The user preferences.
-     */
-    private Preferences getUserPreferences(RequestContext context)
+    public void applicationUpdated(MutablePortletApplication app)
     {
-        Preferences userPrefs = null;
-        Subject subject = context.getSubject();
-        if (null != subject)
-        {
-            Principal userPrincipal = SecurityHelper.getPrincipal(subject, UserPrincipal.class);
-            if (null != userPrincipal)
-            {
-                log.debug("Got user principal: " + userPrincipal.getName());
-                try
-                {
-                    if (userMgr.userExists(userPrincipal.getName()))
-                    {
-                        User user = userMgr.getUser(userPrincipal.getName());
-                        userPrefs = user.getPreferences();
-                    }
-                }
-                catch (SecurityException sex)
-                {
-                    log.warn("Unexpected SecurityException in UserInfoManager", sex);
-                }
-            }
-        }
-        return userPrefs;
+        // clear cache element
+        appUserInfoAttrCache.remove(app.getId());
     }
 
-    private void initUserInfoMapCache()
+    public void portletRemoved(PortletDefinitionComposite def)
     {
-        if (null == userInfoMapCache)
-        {
-            userInfoMapCache = Collections.synchronizedMap(new HashMap());
-        }
+        // ignore
     }
 
+    public void portletUpdated(PortletDefinitionComposite def)
+    {
+        // ignore
+    }
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/java/org/apache/jetspeed/userinfo/impl/UserManagerUserAttributeSourceImpl.java
Tue Mar  2 21:41:30 2010
@@ -18,9 +18,11 @@
 
 import java.security.Principal;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
 import javax.security.auth.Subject;
@@ -34,7 +36,6 @@
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
 import org.apache.jetspeed.security.UserPrincipal;
-import org.apache.jetspeed.userinfo.UserAttributeRetrievalException;
 import org.apache.jetspeed.userinfo.UserAttributeSource;
 
 /**
@@ -50,57 +51,96 @@
     /** Logger */
     private static final Log log = LogFactory.getLog(UserManagerUserAttributeSourceImpl.class);
 
+    private static final String USER_INFO_MAP_KEY = UserManagerUserAttributeSourceImpl.class.getName()+".user_info_map";
+    
     /** The user manager */
     private UserManager userManager;
-
-    /**
-     * @param userManager
-     *            The userManager to set.
-     */
-    public void setUserManager(UserManager userManager)
-    {
-        this.userManager = userManager;
+    /** The user information property set. */
+    private String userInfoPropertySet;
+
+    public UserManagerUserAttributeSourceImpl(UserManager userManager)
+    {
+        this(userManager, User.USER_INFO_PROPERTY_SET);
+    }
+
+    public UserManagerUserAttributeSourceImpl(UserManager userManager, String userInfoPropertySet)
+    {
+        this.userManager = userManager;
+        this.userInfoPropertySet = userInfoPropertySet;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.jetspeed.userinfo.UserAttributeSource#getUserAttributeMap(javax.security.auth.Subject,
java.util.Set)
-     */
     public Map getUserAttributeMap(Subject subject, Collection userAttributeRefs, RequestContext
context)
-            throws UserAttributeRetrievalException
     {
-
         Map userAttributeMap = new HashMap();
         Principal userPrincipal = SecurityHelper.getPrincipal(subject, UserPrincipal.class);
         if (null != userPrincipal)
         {
-            log.debug("Got user principal: " + userPrincipal.getName());
-            try
-            {
-                if (userManager.userExists(userPrincipal.getName()))
-                {
-                    User user = userManager.getUser(userPrincipal.getName());
-                    Preferences userInfoPrefs = user.getPreferences();
-                    for (Iterator iter = userAttributeRefs.iterator(); iter.hasNext();)
-                    {
-                        UserAttributeRef currentAttributeRef = (UserAttributeRef) iter.next();
-                        Object value = userInfoPrefs.get(currentAttributeRef.getName(), null);
-                        if (value != null)
-                        {
-                            userAttributeMap.put(currentAttributeRef.getName(), value);
-                        }
-
-                    }
-                }
-            }
-            catch (SecurityException sex)
-            {
-                log.warn("Unexpected SecurityException in UserInfoManager", sex);
-            }
+            log.debug("Got user principal: " + userPrincipal.getName());
+            // first check session already contains userInfo map
+            String userName = userPrincipal.getName();
+            String userInfoKey = USER_INFO_MAP_KEY+"."+userName;
+            Map userInfo = (Map)context.getSessionAttribute(userInfoKey);
+            if (userInfo == null)
+            {
+                userInfo = Collections.EMPTY_MAP;
+                try
+                {
+                    if (userManager.userExists(userName))
+                    {
+                        User user = userManager.getUser(userPrincipal.getName());
+                        Preferences userPrefs = user.getPreferences();
+                        if (null != userPrefs)
+                        {
+                            Preferences userInfoPrefs = userPrefs.node(userInfoPropertySet);
+                            String[] propertyKeys = null;
+                            try
+                            {
+                                propertyKeys = userInfoPrefs.keys();
+                                if ((null != propertyKeys) && log.isDebugEnabled())
+                                {
+                                    log.debug("Found " + propertyKeys.length + " children
for " + userInfoPrefs.absolutePath());
+                                }
+                            }
+                            catch (BackingStoreException bse)
+                            {
+                                log.error("BackingStoreException: " + bse.toString());
+                            }
+                            if (null != propertyKeys && propertyKeys.length >
0)
+                            {
+                                userInfo = new HashMap();
+                                for (int i = 0; i < propertyKeys.length; i++)
+                                {
+                                    userInfo.put(propertyKeys[i], userInfoPrefs.get(propertyKeys[i],
null));
+                                }
+                            }
+                        }
+                    }
+                }
+                catch (SecurityException sex)
+                {
+                    log.warn("Unexpected SecurityException in UserInfoManager", sex);
+                }                
+                context.setSessionAttribute(userInfoKey, userInfo);
+            }
+            if (userAttributeRefs != null)
+            {
+                Iterator iter = userAttributeRefs.iterator();
+                while (iter.hasNext())
+                {
+                    UserAttributeRef currentAttributeRef = (UserAttributeRef)iter.next();
+                    String key = currentAttributeRef.getNameLink();
+                    String name = currentAttributeRef.getName();
+                    if (key == null)
+                    {                
+                        key = name;
+                    }
+                    if (userInfo.containsKey(key))
+                    {
+                        userAttributeMap.put(name, userInfo.get(key));
+                    }
+                }
+            }            
         }
-
         return userAttributeMap;
     }
-
 }

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/JETSPEED-INF/spring/user-info.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/JETSPEED-INF/spring/user-info.xml?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/JETSPEED-INF/spring/user-info.xml
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/JETSPEED-INF/spring/user-info.xml
Tue Mar  2 21:41:30 2010
@@ -28,21 +28,14 @@
   
   <bean id="org.apache.jetspeed.userinfo.MultiUserInfoManager" 	
          class="org.apache.jetspeed.userinfo.impl.MultiSourceUserInfoManagerImpl">
-		 <property name="portletRegistry">
-		    <ref bean="org.apache.jetspeed.components.portletregistry.PortletRegistry"/>
-		  </property>
-		  <property name="sources">
-		     <list>
-		         <ref bean="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl"/>
-		     </list>
-	     </property>
-  </bean>
-  
-  <bean id="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl"	
-    class="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl">    
 
-      <property name="userManager">
-         <ref bean="org.apache.jetspeed.security.UserManager"/>
-      </property>
+     <constructor-arg><ref bean="org.apache.jetspeed.components.portletregistry.PortletRegistry"/></constructor-arg>
+     <constructor-arg>
+        <list>
+           <bean class="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl">
+             <constructor-arg ><ref bean="org.apache.jetspeed.security.UserManager"/></constructor-arg>
               
+           </bean>      
+        </list>
+      </constructor-arg>
   </bean>
   
 </beans>
\ No newline at end of file

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java
Tue Mar  2 21:41:30 2010
@@ -65,7 +65,7 @@
     {
         super.setUp();
 
-        single = (UserInfoManager) ctx.getBean("org.apache.jetspeed.userinfo.UserInfoManager");
+        single = (UserInfoManager) ctx.getBean("org.apache.jetspeed.userinfo.MultiUserInfoManager");
         portletRegistry = (PortletRegistry) ctx.getBean("portletRegistry");
     }
 
@@ -119,7 +119,9 @@
         // Without linked attributes
         // There are no preferences associated to the user profile.
         Map userInfo = uim.getUserInfoMap(portletApp.getId(), request);
-        assertNull(PortletRequest.USER_INFO + " is null", userInfo);
+        // disabled test: UserInfoManager doesn't return null anymore for a more efficient
solution
+        // PortletRequest.getAttribute(USER_INFO) == null for unauthorised users but that
requires a different test setup 
+        // assertNull(PortletRequest.USER_INFO + " is null", userInfo);
 
         // The user has preferences associated to the user profile.
         initUser();

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/src/webapp/WEB-INF/assembly/userinfo.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/src/webapp/WEB-INF/assembly/userinfo.xml?rev=918205&r1=918204&r2=918205&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/src/webapp/WEB-INF/assembly/userinfo.xml
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.4/src/webapp/WEB-INF/assembly/userinfo.xml
Tue Mar  2 21:41:30 2010
@@ -29,23 +29,16 @@
 
 <!-- Multi-source User Info Manager 
 
-  <bean id="org.apache.jetspeed.userinfo.UserInfoManager" 	
+  <bean id="org.apache.jetspeed.userinfo.MultiUserInfoManager"  
          class="org.apache.jetspeed.userinfo.impl.MultiSourceUserInfoManagerImpl">
-		 <property name="portletRegistry">
-		    <ref bean="org.apache.jetspeed.components.portletregistry.PortletRegistry"/>
-		  </property>
-		  <property name="sources">
-		     <list>
-		         <ref bean="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl"/>
-		     </list>
-	     </property>
-  </bean>
-  
-  <bean id="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl"	
-    class="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl">    
 
-      <property name="userManager">
-         <ref bean="org.apache.jetspeed.security.UserManager"/>
-      </property>
+     <constructor-arg><ref bean="org.apache.jetspeed.components.portletregistry.PortletRegistry"/></constructor-arg>
+     <constructor-arg>
+        <list>
+           <bean class="org.apache.jetspeed.userinfo.impl.UserManagerUserAttributeSourceImpl">
+             <constructor-arg ><ref bean="org.apache.jetspeed.security.UserManager"/></constructor-arg>
               
+           </bean>      
+        </list>
+      </constructor-arg>
   </bean>
   -->
   



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message