portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edalqu...@apache.org
Subject svn commit: r638649 - in /portals/pluto/branches/pluto-1.1.x/pluto-container/src: main/java/org/apache/pluto/internal/impl/ main/java/org/apache/pluto/spi/optional/ test/java/org/apache/pluto/internal/impl/
Date Wed, 19 Mar 2008 00:06:09 GMT
Author: edalquist
Date: Tue Mar 18 17:06:08 2008
New Revision: 638649

URL: http://svn.apache.org/viewvc?rev=638649&view=rev
Log:
PLUTO-477 Allow the UserInfoService to return a null map
Added unit test to verify fix
Cleaned up javadocs on UserInfoService to more accurately describe the implementation contract.

Modified:
    portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
    portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
    portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java

Modified: portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java?rev=638649&r1=638648&r2=638649&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
(original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
Tue Mar 18 17:06:08 2008
@@ -44,6 +44,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.OptionalContainerServices;
 import org.apache.pluto.PortletContainer;
 import org.apache.pluto.PortletContainerException;
 import org.apache.pluto.descriptors.common.SecurityRoleRefDD;
@@ -54,6 +55,8 @@
 import org.apache.pluto.internal.InternalPortletRequest;
 import org.apache.pluto.internal.InternalPortletWindow;
 import org.apache.pluto.internal.PortletEntity;
+import org.apache.pluto.spi.optional.PortletRegistryService;
+import org.apache.pluto.spi.optional.UserInfoService;
 import org.apache.pluto.util.ArgumentUtility;
 import org.apache.pluto.util.Enumerator;
 import org.apache.pluto.util.NamespaceMapper;
@@ -436,19 +439,24 @@
     }
 
     public Map createUserInfoMap() {
-
         Map userInfoMap = new HashMap();
         try {
 
-            PortletAppDD dd = container.getOptionalContainerServices()
-                .getPortletRegistryService()
-                .getPortletApplicationDescriptor(internalPortletWindow.getContextPath());
-
-            Map allMap = container.getOptionalContainerServices()
-            	//PLUTO-388 fix:
-            	//The PortletWindow is currently ignored in the implementing class
-            	// See: org.apache.pluto.core.DefaultUserInfoService
-            	.getUserInfoService().getUserInfo( this, this.internalPortletWindow );
+            final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
+            final UserInfoService userInfoService = optionalContainerServices.getUserInfoService();
+            
+            //PLUTO-388 fix:
+            //The PortletWindow is currently ignored in the implementing class
+            // See: org.apache.pluto.core.DefaultUserInfoService
+            final Map allMap = userInfoService.getUserInfo( this, this.internalPortletWindow
);
+            
+            //PLUTO-477 null attribute maps are ok
+            if (null == allMap) {
+                return null;
+            }
+            
+            final PortletRegistryService portletRegistryService = optionalContainerServices.getPortletRegistryService();
+            final PortletAppDD dd = portletRegistryService.getPortletApplicationDescriptor(internalPortletWindow.getContextPath());
 
             Iterator i = dd.getUserAttributes().iterator();
             while(i.hasNext()) {

Modified: portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java?rev=638649&r1=638648&r2=638649&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
(original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
Tue Mar 18 17:06:08 2008
@@ -35,16 +35,22 @@
      * To access user information attributes as defined in PLT.17
      * of JSR-168.
      *
-     * @param request Used to extract the authenticated user name.
-     * @return A map of names and values of user information attributes
-     *         for a particular authenticated user.
      * @deprecated use {@link #getUserInfo(PortletRequest, PortletWindow)}
      */
     Map getUserInfo(PortletRequest request) throws PortletContainerException;
 
     /**
      * Retrieve the user attribues associated with the given
-     * request and window.
+     * request and window. This can return null if the user associated with the
+     * request is un-authenticated.
+     * 
+     * The results of this call will be filtered using the the UserAttributeDDs
+     * from the PortletAppDD for the PortletWindow.
+     *  
+     * @param request Used to extract the authenticated user name.
+     * @param window The portlet window to get user attributes for.
+     * @return A map of names and values of user information attributes
+     *         for a particular authenticated user. null if the user is not authenticated.
      */
     Map getUserInfo(PortletRequest request, PortletWindow window) throws PortletContainerException;
 }

Modified: portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java?rev=638649&r1=638648&r2=638649&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java
(original)
+++ portals/pluto/branches/pluto-1.1.x/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java
Tue Mar 18 17:06:08 2008
@@ -16,20 +16,25 @@
  */
 package org.apache.pluto.internal.impl;
 
+import java.util.Map;
+
+import javax.portlet.PortalContext;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletSession;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
 import org.apache.pluto.OptionalContainerServices;
 import org.apache.pluto.PortletContainer;
 import org.apache.pluto.RequiredContainerServices;
 import org.apache.pluto.core.PortletContainerImpl;
+import org.apache.pluto.internal.InternalPortletRequest;
 import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.spi.optional.UserInfoService;
 import org.jmock.Mock;
 import org.jmock.cglib.MockObjectTestCase;
 
-import javax.portlet.PortalContext;
-import javax.portlet.PortletContext;
-import javax.portlet.PortletSession;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
 /**
  * Created by IntelliJ IDEA.
  * User: esm
@@ -42,6 +47,8 @@
     // Mock Objects
     private Mock mockContainer = null;
     private Mock mockServices = null;
+    private Mock mockOptionalServices = null;
+    private Mock mockUserInfoService = null;
     private Mock mockPortalContext = null;
     private Mock mockPortletContext = null;
     private Mock mockHttpServletRequest = null;
@@ -57,6 +64,8 @@
 
         // Create mocks
         mockServices = mock( RequiredContainerServices.class );
+        mockOptionalServices = mock( OptionalContainerServices.class );
+        mockUserInfoService = mock( UserInfoService.class );
         mockPortalContext = mock( PortalContext.class );
         mockPortletContext = mock( PortletContext.class );
         mockContainer = mock( PortletContainerImpl.class,
@@ -108,5 +117,36 @@
         mockHttpSession.expects( never() ).method( "invalidate" );
         
         PortletSession s = request.getPortletSession( true );
+    }
+    
+    /**
+     * Test for PLUTO-477
+     */
+    public void testUnAuthenticatedCreateUserInfoMap() throws Exception {
+        this.mockUserInfoService.expects(once()).method("getUserInfo").will(returnValue(null));
+        
+        this.mockOptionalServices.expects(once()).method("getUserInfoService").will(returnValue(this.mockUserInfoService.proxy()));
+        
+        this.mockContainer.expects(once()).method("getOptionalContainerServices").will(returnValue(this.mockOptionalServices.proxy()));
+        
+        final TestPortletRequestImpl portletRequest = new TestPortletRequestImpl((PortletContainer)this.mockContainer.proxy(),

+                                                                                 this.window,

+                                                                                 (HttpServletRequest)this.mockHttpServletRequest.proxy());
+        final Map userInfoMap = portletRequest.createUserInfoMap();
+        assertNull(userInfoMap);
+    }
+    
+    private static class TestPortletRequestImpl extends PortletRequestImpl {
+        public TestPortletRequestImpl(InternalPortletRequest internalPortletRequest) {
+            super(internalPortletRequest);
+        }
+
+        public TestPortletRequestImpl(PortletContainer container, InternalPortletWindow internalPortletWindow,
HttpServletRequest servletRequest) {
+            super(container, internalPortletWindow, servletRequest);
+        }
+
+        public PortletPreferences getPreferences() {
+            return null;
+        }
     }
 }



Mime
View raw message