[jboss-svn-commits] JBoss Portal SVN: r5487 - in trunk/wsrp: . src/main/org/jboss/portal/test/wsrp/portlet src/main/org/jboss/portal/test/wsrp/v1/producer src/main/org/jboss/portal/wsrp src/main/org/jboss/portal/wsrp/producer src/resources/tests src/resources/tests/test-usercontext-portlet-war src/resources/tests/test-usercontext-portlet-war/WEB-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 19 18:05:46 EDT 2006


Author: chris.laprun at jboss.com
Date: 2006-10-19 18:05:43 -0400 (Thu, 19 Oct 2006)
New Revision: 5487

Added:
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/portlet/UserContextPortlet.java
   trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/
   trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/
   trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/portlet.xml
   trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/web.xml
Modified:
   trunk/wsrp/build.xml
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
Log:
JBPORTAL-1086:
- Now should correctly propagate userContextKey.
- Added test.

Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/build.xml	2006-10-19 22:05:43 UTC (rev 5487)
@@ -469,6 +469,9 @@
 
       <!-- Encode URL test portlet -->
       <package-test-portlet archiveName="encodeurl" portletName="EncodeURL"/>
+
+      <!-- UserContext test portlet -->
+      <package-test-portlet archiveName="usercontext" portletName="UserContext"/>
    </target>
 
    <!-- Packages all the test related artifacts. Note that compilation should have be-->

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/portlet/UserContextPortlet.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/portlet/UserContextPortlet.java	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/portlet/UserContextPortlet.java	2006-10-19 22:05:43 UTC (rev 5487)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+
+package org.jboss.portal.test.wsrp.portlet;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision: 5440 $
+ * @since 2.4
+ */
+public class UserContextPortlet extends GenericPortlet
+{
+
+   protected void doView(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException
+   {
+      response.setContentType("text/html");
+      Writer writer = response.getWriter();
+      writer.write("user: " + request.getRemoteUser());
+   }
+
+}

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2006-10-19 22:05:43 UTC (rev 5487)
@@ -405,6 +405,21 @@
       undeploy(encodeURLPortletArchive);
    }
 
+   public void testGetMarkupWithUserContext() throws Exception
+   {
+      undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+      String userContextPortletArchive = "test-usercontext-portlet.war";
+      deploy(userContextPortletArchive);
+
+      GetMarkup getMarkup = createMarkupRequest(userContextPortletArchive);
+      getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
+
+      MarkupResponse response = markupService.getMarkup(getMarkup);
+      checkMarkupResponse(response, "user: johndoe");
+
+      undeploy(userContextPortletArchive);
+   }
+
    private MarkupContext checkMarkupResponse(MarkupResponse response, String markupString)
    {
       assertNotNull(response);

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java	2006-10-19 22:05:43 UTC (rev 5487)
@@ -170,6 +170,7 @@
       private Map infos;
       private String[] desiredLocales;
       private Locale locale;
+      private String id;
 
       public WSRPMappedUserContext(org.jboss.portal.wsrp.core.UserContext userContext, String[] desiredLocales, String preferredLocale)
       {
@@ -213,6 +214,13 @@
                   infos.put(P3PConstants.INFO_USER_JOB_TITLE, employerInfo.getJobtitle());
                }
             }
+
+            String key = userContext.getUserContextKey();
+            if (key == null)
+            {
+               throw new IllegalArgumentException("Missing required userContextKey in UserContext!");
+            }
+            id = key;
          }
          else
          {
@@ -222,7 +230,7 @@
 
       public String getId()
       {
-         return null;
+         return id;
       }
 
       public Map getInformations()

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java	2006-10-19 22:05:43 UTC (rev 5487)
@@ -89,7 +89,6 @@
 import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType;
 import org.jboss.portal.wsrp.invocation.WSRPActionContext;
 import org.jboss.portal.wsrp.invocation.WSRPRenderContext;
-import org.jboss.portal.wsrp.servlet.ServletAccess;
 
 import javax.activation.MimeTypeParseException;
 import javax.portlet.PortletModeException;
@@ -635,7 +634,11 @@
 
          public String getRemoteUser()
          {
-            return ServletAccess.getRequest().getRemoteUser(); // todo: check if this is correct
+            if (wsrpUserContext != null)
+            {
+               return wsrpUserContext.getUserContextKey();
+            }
+            return null;
          }
 
          public Principal getUserPrincipal()
@@ -645,13 +648,17 @@
 
          public boolean isUserInRole(String roleName)
          {
-            List userCategories = Arrays.asList(wsrpUserContext.getUserCategories());
-            return userCategories.contains(roleName);
+            if (wsrpUserContext != null)
+            {
+               List userCategories = Arrays.asList(wsrpUserContext.getUserCategories());
+               return userCategories.contains(roleName);
+            }
+            return false;
          }
 
          public boolean isAuthenticated()
          {
-            return false;
+            return wsrpUserContext != null;
          }
       };
    }

Added: trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/portlet.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/portlet.xml	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/portlet.xml	2006-10-19 22:05:43 UTC (rev 5487)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ JBoss, a division of Red Hat                                              ~
+  ~ Copyright 2006, Red Hat Middleware, LLC, and individual                   ~
+  ~ contributors as indicated by the @authors tag. See the                    ~
+  ~ copyright.txt in the distribution for a full listing of                   ~
+  ~ individual contributors.                                                  ~
+  ~                                                                           ~
+  ~ This is free software; you can redistribute it and/or modify it           ~
+  ~ under the terms of the GNU Lesser General Public License as               ~
+  ~ published by the Free Software Foundation; either version 2.1 of          ~
+  ~ the License, or (at your option) any later version.                       ~
+  ~                                                                           ~
+  ~ This software is distributed in the hope that it will be useful,          ~
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of            ~
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU          ~
+  ~ Lesser General Public License for more details.                           ~
+  ~                                                                           ~
+  ~ You should have received a copy of the GNU Lesser General Public          ~
+  ~ License along with this software; if not, write to the Free               ~
+  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA        ~
+  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.                  ~
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0">
+   <portlet>
+      <portlet-name>UserContext Test Portlet</portlet-name>
+      <portlet-class>org.jboss.portal.test.wsrp.portlet.UserContextPortlet</portlet-class>
+
+      <supports>
+         <mime-type>text/html</mime-type>
+         <portlet-mode>view</portlet-mode>
+      </supports>
+
+      <portlet-info>
+         <title>title</title>
+      </portlet-info>
+   </portlet>
+
+</portlet-app>
\ No newline at end of file

Added: trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/web.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/web.xml	2006-10-19 22:04:06 UTC (rev 5486)
+++ trunk/wsrp/src/resources/tests/test-usercontext-portlet-war/WEB-INF/web.xml	2006-10-19 22:05:43 UTC (rev 5487)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ JBoss, a division of Red Hat                                              ~
+  ~ Copyright 2006, Red Hat Middleware, LLC, and individual                   ~
+  ~ contributors as indicated by the @authors tag. See the                    ~
+  ~ copyright.txt in the distribution for a full listing of                   ~
+  ~ individual contributors.                                                  ~
+  ~                                                                           ~
+  ~ This is free software; you can redistribute it and/or modify it           ~
+  ~ under the terms of the GNU Lesser General Public License as               ~
+  ~ published by the Free Software Foundation; either version 2.1 of          ~
+  ~ the License, or (at your option) any later version.                       ~
+  ~                                                                           ~
+  ~ This software is distributed in the hope that it will be useful,          ~
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of            ~
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU          ~
+  ~ Lesser General Public License for more details.                           ~
+  ~                                                                           ~
+  ~ You should have received a copy of the GNU Lesser General Public          ~
+  ~ License along with this software; if not, write to the Free               ~
+  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA        ~
+  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.                  ~
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<web-app version="2.4"
+         xmlns="http://java.sun.com/xml/ns/j2ee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+</web-app>
\ No newline at end of file




More information about the jboss-svn-commits mailing list