Author: chris.laprun(a)jboss.com
Date: 2007-02-23 14:09:56 -0500 (Fri, 23 Feb 2007)
New Revision: 6384
Added:
trunk/common/src/main/org/jboss/portal/test/common/ToolsTestCase.java
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java
Log:
- JBPORTAL-1291: fix NPE in isUserInRole. SecurityContext needs more work to correctly
propagate user information...
- Added isContainedIn method in Tools and associated test case.
- Added URLToolsTestCase and ToolsTestCase in test suite for common.
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-02-23 15:29:49 UTC (rev 6383)
+++ trunk/common/build.xml 2007-02-23 19:09:56 UTC (rev 6384)
@@ -31,7 +31,7 @@
<!--| It also sets up the basic extention tasks amoung other things. |-->
<!--+====================================================================+-->
- &buildmagic;
+ &buildmagic;
&modules;
&defaults;
&tools;
@@ -97,8 +97,8 @@
<property name="javadoc.protected" value="false"/>
</target>
-
+
<!--+====================================================================+-->
<!--| Compile |-->
<!--| |-->
@@ -127,9 +127,9 @@
<!--| modules. |-->
<!--+====================================================================+-->
- <target name="output"
- description="Generate all target output."
- depends="compile">
+ <target name="output"
+ description="Generate all target output."
+ depends="compile">
<mkdir dir="${build.lib}"/>
@@ -142,18 +142,18 @@
</fileset>
</jar>
- <!-- Build the ant task that explodes archives -->
- <jar jarfile="${build.lib}/explode.jar">
+ <!-- Build the ant task that explodes archives -->
+ <jar jarfile="${build.lib}/explode.jar">
<fileset dir="${build.classes}">
<include name="org/jboss/portal/common/ant/**/*"/>
<include name="org/jboss/portal/common/junit/**/*"/>
</fileset>
</jar>
</target>
-
- <!-- generates artifacts used for tests, requires output to be previously run
- -->
- <target name="package-tests" depends="init">
+
+ <!-- generates artifacts used for tests, requires output to be previously run
+ -->
+ <target name="package-tests" depends="init">
<jar jarfile="${build.lib}/test.jar">
<fileset dir="${build.resources}/test/test-jar"/>
</jar>
@@ -226,6 +226,8 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.common.BufferedStreamTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.CharBufferTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.common.CopyOnWriteRegistryTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.URLToolsTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.common.ToolsTestCase"/>
</x-test>
<x-classpath>
<pathelement location="${build.classes}"/>
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-02-23 15:29:49 UTC
(rev 6383)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-02-23 19:09:56 UTC
(rev 6384)
@@ -64,6 +64,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.com">Boleslaw
Dawidowicz</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
public class Tools
@@ -1048,4 +1049,32 @@
return tmp.toString();
}
+
+ /**
+ * Determines if value is contained in array.
+ *
+ * @param value
+ * @param array
+ * @return
+ * @since 2.4.2
+ */
+ public static boolean isContainedIn(Object value, Object[] array)
+ {
+ if (value == null)
+ {
+ return false;
+ }
+
+ if (array != null)
+ {
+ for (int i = 0; i < array.length; i++)
+ {
+ if (value.equals(array[i]))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
\ No newline at end of file
Added: trunk/common/src/main/org/jboss/portal/test/common/ToolsTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/ToolsTestCase.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/ToolsTestCase.java 2007-02-23
19:09:56 UTC (rev 6384)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.common;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.util.Tools;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class ToolsTestCase extends TestCase
+{
+ public void testIsContainedIn()
+ {
+ String value = "value";
+ String[] array = new String[]{"foo", "bar", value,
"baz"};
+
+ assertTrue(Tools.isContainedIn(value, array));
+ assertFalse(Tools.isContainedIn(null, array));
+ assertFalse(Tools.isContainedIn(value, null));
+ assertFalse(Tools.isContainedIn(null, null));
+ assertFalse(Tools.isContainedIn("bat", array));
+ }
+}
Property changes on:
trunk/common/src/main/org/jboss/portal/test/common/ToolsTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java 2007-02-23
15:29:49 UTC (rev 6383)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java 2007-02-23
19:09:56 UTC (rev 6384)
@@ -24,6 +24,7 @@
package org.jboss.portal.wsrp.producer;
import org.jboss.portal.common.MediaType;
+import org.jboss.portal.common.util.Tools;
import org.jboss.portal.portlet.OpaqueStateString;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -429,12 +430,7 @@
public boolean isUserInRole(String roleName)
{
- if (wsrpUserContext != null)
- {
- List userCategories = Arrays.asList(wsrpUserContext.getUserCategories());
- return userCategories.contains(roleName);
- }
- return false;
+ return wsrpUserContext != null && Tools.isContainedIn(roleName,
wsrpUserContext.getUserCategories());
}
public boolean isAuthenticated()