Author: julien(a)jboss.com
Date: 2007-01-17 16:32:24 -0500 (Wed, 17 Jan 2007)
New Revision: 6022
Added:
trunk/server/src/main/org/jboss/portal/test/server/request/
trunk/server/src/main/org/jboss/portal/test/server/request/URLContextTestCase.java
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicController.java
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPortletWindowCommand.java
trunk/server/build.xml
trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
Log:
- added URLContext test cases
- on the tab logout URL, do not use the authenticated servlet
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageCustomizerInterceptor.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -157,7 +157,7 @@
if
(controllerCtx.getServerInvocation().getServerContext().getClientRequest().getRemoteUser()
== null)
{
URLContext ctx =
controllerCtx.getServerInvocation().getServerContext().getURLContext();
- ctx = URLContext.newInstance(ctx.getSecure(), true);
+ ctx = URLContext.newInstance(ctx.isSecure(), true);
String loginURL = controllerCtx.renderURL(cc, ctx, null);
sb.append("<a
href=\"").append(loginURL).append("\">Login</a>");
}
@@ -253,7 +253,8 @@
}
SignOutCommand cmd = new SignOutCommand();
- String logoutURL = controllerCtx.renderURL(cmd, null, null);
+ URLContext urlContext =
controllerCtx.getServerInvocation().getServerContext().getURLContext();
+ String logoutURL = controllerCtx.renderURL(cmd, urlContext.asNonAuthenticated(),
null);
//
if (user != null)
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicController.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicController.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicController.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -134,7 +134,7 @@
}
else
{
- urlContext = URLContext.newInstance(urlContext.getSecure(), true);
+ urlContext = URLContext.newInstance(urlContext.isSecure(), true);
ServerURL serverURL = getURLFactory().doMapping(invocation, cmd);
String url = invocation.getResponse().renderURL(serverURL, urlContext,
null);
AbstractResponseHandler.sendRedirect(invocation, url);
@@ -200,8 +200,8 @@
}
else
{
- boolean currentSecure = currentURLCtx.getSecure();
- if (nextURLCtx != null && nextURLCtx.getSecure() &&
!currentSecure)
+ boolean currentSecure = currentURLCtx.isSecure();
+ if (nextURLCtx != null && nextURLCtx.isSecure() &&
!currentSecure)
{
return true;
}
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/controller/classic/ClassicResponseHandler.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -74,9 +74,8 @@
PortalObjectContainer portalObjectContainer =
ctx.getController().getPortalObjectContainer();
Portal portal = (Portal)portalObjectContainer.getObject(defaultPortalPath);
RenderPageCommand renderCmd = new RenderPageCommand(portal.getId());
- boolean secure = invocation.getServerContext().getURLContext().getSecure();
- URLContext urlContext = URLContext.newInstance(secure, false);
- location = ctx.renderURL(renderCmd, urlContext, null);
+ URLContext urlContext = invocation.getServerContext().getURLContext();
+ location = ctx.renderURL(renderCmd, urlContext.asNonAuthenticated(), null);
}
//
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletInvocationFactory.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -245,7 +245,7 @@
}
//
- boolean secure =
controllerContext.getServerInvocation().getServerContext().getURLContext().getSecure();
+ boolean secure =
controllerContext.getServerInvocation().getServerContext().getURLContext().isSecure();
if (wantSecure != null)
{
secure = wantSecure.booleanValue();
Modified:
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/controller/portlet/PortletResponseHandler.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -118,7 +118,7 @@
InvokePortletWindowActionCommand iwac =
(InvokePortletWindowActionCommand)cmd;
Page page = iwac.getPage();
RenderPageCommand renderCmd = new RenderPageCommand(page.getId());
- boolean secure =
invocation.getServerContext().getURLContext().getSecure();
+ boolean secure =
invocation.getServerContext().getURLContext().isSecure();
URLContext urlContext = URLContext.newInstance(secure, false);
location = ctx.renderURL(renderCmd, urlContext, null);
}
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPortletWindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPortletWindowCommand.java 2007-01-17
20:54:46 UTC (rev 6021)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPortletWindowCommand.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -353,7 +353,7 @@
InvokePortletWindowRenderCommand cmd = new
InvokePortletWindowRenderCommand(window.getId(), mode, windowState);
ControllerContext controllerContext = getControllerContext();
ServerInvocationContext serverContext =
controllerContext.getServerInvocation().getServerContext();
- boolean secure = serverContext.getURLContext().getSecure();
+ boolean secure = serverContext.getURLContext().isSecure();
boolean authenticated = serverContext.getURLContext().isAuthenticated();
URLContext urlContext = URLContext.newInstance(secure, authenticated);
return controllerContext.renderURL(cmd, urlContext, URLFormat.newInstance(true,
true));
Modified: trunk/server/build.xml
===================================================================
--- trunk/server/build.xml 2007-01-17 20:54:46 UTC (rev 6021)
+++ trunk/server/build.xml 2007-01-17 21:32:24 UTC (rev 6022)
@@ -310,10 +310,11 @@
</x-sysproperty>
<x-test>
<!-- Server side tests -->
- <!--<test todir="${test.reports}"
name="org.jboss.portal.test.server.CharsetTestCase"/>-->
- <!--<test todir="${test.reports}"
name="org.jboss.portal.test.server.ParametersTestCase"/>-->
- <!--<test todir="${test.reports}"
name="org.jboss.portal.test.server.ServletTestCase"/>-->
+ <test todir="${test.reports}"
name="org.jboss.portal.test.server.CharsetTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.server.ParametersTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.server.ServletTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.server.ResponseTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.server.request.URLContextTestCase"/>
</x-test>
<x-classpath>
<path refid="jboss.serialization.classpath"/>
Modified: trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2007-01-17
20:54:46 UTC (rev 6021)
+++ trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -31,10 +31,10 @@
public final class URLContext
{
- /** . */
+ /** Mask for secure bit. */
public static final int SEC_MASK = 0x01;
- /** . */
+ /** Mask for authenticated bit. */
public static final int AUTH_MASK = 0x02;
/** . */
@@ -62,7 +62,7 @@
this.authenticated = authenticated;
}
- public boolean getSecure()
+ public boolean isSecure()
{
return secure;
}
@@ -72,6 +72,30 @@
return authenticated;
}
+ public URLContext asSecured()
+ {
+ int newMask = mask | SEC_MASK;
+ return contexts[newMask];
+ }
+
+ public URLContext asNonSecured()
+ {
+ int newMask = mask & ~SEC_MASK;
+ return contexts[newMask];
+ }
+
+ public URLContext asAuthenticated()
+ {
+ int newMask = mask | AUTH_MASK;
+ return contexts[newMask];
+ }
+
+ public URLContext asNonAuthenticated()
+ {
+ int newMask = mask & ~AUTH_MASK;
+ return contexts[newMask];
+ }
+
public int getMask()
{
return mask;
Added: trunk/server/src/main/org/jboss/portal/test/server/request/URLContextTestCase.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/test/server/request/URLContextTestCase.java
(rev 0)
+++
trunk/server/src/main/org/jboss/portal/test/server/request/URLContextTestCase.java 2007-01-17
21:32:24 UTC (rev 6022)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * 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.server.request;
+
+import junit.framework.TestCase;
+import org.jboss.portal.server.request.URLContext;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class URLContextTestCase extends TestCase
+{
+
+ URLContext a = URLContext.newInstance(false, false);
+ URLContext b = URLContext.newInstance(true, false);
+ URLContext c = URLContext.newInstance(false, true);
+ URLContext d = URLContext.newInstance(true, true);
+
+ public void testFactory()
+ {
+ assertFalse(a.isSecure());
+ assertFalse(a.isAuthenticated());
+ assertEquals(0, a.getMask());
+
+ //
+ assertTrue(b.isSecure());
+ assertFalse(b.isAuthenticated());
+ assertEquals(URLContext.SEC_MASK, b.getMask());
+
+ //
+ assertFalse(c.isSecure());
+ assertTrue(c.isAuthenticated());
+ assertEquals(URLContext.AUTH_MASK, c.getMask());
+
+ //
+ assertTrue(d.isSecure());
+ assertTrue(d.isAuthenticated());
+ assertEquals(URLContext.AUTH_MASK | URLContext.SEC_MASK, d.getMask());
+ }
+
+ public void testTransformation()
+ {
+ assertEquals(a, a.asNonSecured());
+ assertEquals(a, a.asNonAuthenticated());
+ assertEquals(b, a.asSecured());
+ assertEquals(c, a.asAuthenticated());
+
+ //
+ assertEquals(a, b.asNonSecured());
+ assertEquals(b, b.asNonAuthenticated());
+ assertEquals(b, b.asSecured());
+ assertEquals(d, b.asAuthenticated());
+
+ //
+ assertEquals(c, c.asNonSecured());
+ assertEquals(a, c.asNonAuthenticated());
+ assertEquals(d, c.asSecured());
+ assertEquals(c, c.asAuthenticated());
+
+ //
+ assertEquals(c, d.asNonSecured());
+ assertEquals(b, d.asNonAuthenticated());
+ assertEquals(d, d.asSecured());
+ assertEquals(d, d.asAuthenticated());
+ }
+
+}