You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ed...@apache.org on 2008/03/19 02:12:24 UTC
svn commit: r638670 - in /portals/pluto/trunk/pluto-container: ./
src/main/java/org/apache/pluto/internal/impl/
src/main/java/org/apache/pluto/spi/optional/
src/test/java/org/apache/pluto/internal/impl/
Author: edalquist
Date: Tue Mar 18 18:12:22 2008
New Revision: 638670
URL: http://svn.apache.org/viewvc?rev=638670&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.
Added:
portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java
Modified:
portals/pluto/trunk/pluto-container/pom.xml
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
Modified: portals/pluto/trunk/pluto-container/pom.xml
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/pom.xml?rev=638670&r1=638669&r2=638670&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/pom.xml (original)
+++ portals/pluto/trunk/pluto-container/pom.xml Tue Mar 18 18:12:22 2008
@@ -119,6 +119,12 @@
<version>${jmock.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>jmock</groupId>
+ <artifactId>jmock-cglib</artifactId>
+ <version>${jmock.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java?rev=638670&r1=638669&r2=638670&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java Tue Mar 18 18:12:22 2008
@@ -54,6 +54,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pluto.Constants;
+import org.apache.pluto.OptionalContainerServices;
import org.apache.pluto.PortletContainer;
import org.apache.pluto.PortletContainerException;
import org.apache.pluto.descriptors.common.SecurityRoleRefDD;
@@ -65,6 +66,8 @@
import org.apache.pluto.internal.InternalPortletWindow;
import org.apache.pluto.internal.PortletEntity;
import org.apache.pluto.spi.PortletURLProvider;
+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;
@@ -476,15 +479,21 @@
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.getUserAttribute().iterator();
while(i.hasNext()) {
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java?rev=638670&r1=638669&r2=638670&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/spi/optional/UserInfoService.java Tue Mar 18 18:12:22 2008
@@ -36,16 +36,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;
}
Added: portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java?rev=638670&view=auto
==============================================================================
--- portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java (added)
+++ portals/pluto/trunk/pluto-container/src/test/java/org/apache/pluto/internal/impl/PortletRequestImplTest.java Tue Mar 18 18:12:22 2008
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.CCPPProfileService;
+import org.apache.pluto.spi.optional.UserInfoService;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: esm
+ * Date: Mar 5, 2008
+ * Time: 9:50:43 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PortletRequestImplTest extends MockObjectTestCase
+{
+ // Mock Objects
+ private Mock mockContainer = null;
+ private Mock mockServices = null;
+ private Mock mockCCPPProfileService = null;
+ private Mock mockOptionalServices = null;
+ private Mock mockUserInfoService = null;
+ private Mock mockPortalContext = null;
+ private Mock mockPortletContext = null;
+ private Mock mockHttpServletRequest = null;
+
+ private InternalPortletWindow window = null;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp( ) throws Exception
+ {
+ super.setUp();
+
+ // Create mocks
+ mockServices = mock( RequiredContainerServices.class );
+ mockCCPPProfileService = mock( CCPPProfileService.class );
+ mockOptionalServices = mock( OptionalContainerServices.class );
+ mockUserInfoService = mock( UserInfoService.class );
+ mockPortalContext = mock( PortalContext.class );
+ mockPortletContext = mock( PortletContext.class );
+ mockContainer = mock( PortletContainerImpl.class,
+ new Class[] { String.class, RequiredContainerServices.class, OptionalContainerServices.class },
+ new Object[] { "Mock Pluto Container", (RequiredContainerServices) mockServices.proxy(), null } );
+ window = (InternalPortletWindow) mock( InternalPortletWindow.class ).proxy();
+ mockHttpServletRequest = mock( HttpServletRequest.class );
+
+ // Constructor expectations for RenderRequestImpl
+ mockContainer.expects( once() ).method( "getRequiredContainerServices" ).will( returnValue( mockServices.proxy() ) );
+ mockServices.expects( once() ).method( "getPortalContext" ).will( returnValue( mockPortalContext.proxy() ) );
+ }
+
+ /**
+ * Test for PLUTO-474.
+ */
+ public void testInvalidateSessionWithUnititializedLastAccessTime() throws Exception
+ {
+ // maximum inactive interval of the underlying PortletRequest's HttpSession
+ int maxInactiveInterval = 5; // in seconds
+
+ // last accessed time of the underlying PortletRequest's HttpSession
+ // A 'lastAccessedTime' of 0 emulates the behavior
+ // of a servlet container that doesn't initialize
+ // its value.
+ long lastAccessedTime = 0L; // in milliseconds
+
+ mockCCPPProfileService.expects(once()).method("getCCPPProfile").will(returnValue( null ));
+
+ mockServices.expects(once()).method("getCCPPProfileService").will(returnValue( mockCCPPProfileService.proxy() ));
+
+ mockContainer.expects(once()).method("getRequiredContainerServices").will(returnValue( mockServices.proxy() ));
+
+ mockHttpServletRequest.expects(once()).method("removeAttribute");
+ mockHttpServletRequest.expects(once()).method("setAttribute");
+
+ // Create the render request that is under test, and initialize its state
+ RenderRequestImpl request = new RenderRequestImpl( (PortletContainer)mockContainer.proxy(), window, (HttpServletRequest)mockHttpServletRequest.proxy() );
+ request.init( (PortletContext)mockPortletContext.proxy(), ( HttpServletRequest)mockHttpServletRequest.proxy() );
+
+ // Mock the HttpSession, and set its expectations: it will return 0 for the last accessed time, and 5
+ // for the maximum inactive interval
+ Mock mockHttpSession = mock( HttpSession.class );
+ mockHttpSession.expects( once() ).method( "getLastAccessedTime" ).will( returnValue( lastAccessedTime ) );
+ // Prior to applying PLUTO-474, this expectation is invoked exactly twice, not once
+ mockHttpSession.expects( once() ).method( "getMaxInactiveInterval" ).will( returnValue( maxInactiveInterval ) );
+
+ // Set the expectation for the servlet request - it will return the mock http session
+ // Prior to applying PLUTO-474, this expectation is invoked exactly twice, not once
+ mockHttpServletRequest.expects( once() ).method( "getSession" ).will( returnValue( mockHttpSession.proxy() ) );
+
+ // this is the important expectation -
+ // Prior to applying PLUTO-474, the HttpSession was
+ // incorrectly determined to be invalid, and thus the
+ // HttpSession's invalidate() method was invoked.
+ //
+ // After applying PLUTO-474, invalidate() should never be called
+ 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;
+ }
+ }
+}