[jboss-cvs] JBossAS SVN: r112741 - in tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788: cluster/src/main/org/jboss/ha/framework/server and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 8 13:07:28 EST 2012
Author: mbenitez
Date: 2012-03-08 13:07:26 -0500 (Thu, 08 Mar 2012)
New Revision: 112741
Added:
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/HARMIServerGuard.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/NamingUtil.java
Modified:
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/component-matrix/pom.xml
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/main/src/bin/run.sh
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/pom.xml
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/cluster/multicfg/test/HAJndiTestCase.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/security/test/LoginModulesUnitTestCase.java
Log:
Merge tags/JBPAPP_5_1_2_GA_CVE_JBWEB209/ branches/JBPAPP_5_1_2_GA_JBPAPP-7788
Property changes on: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JBPAPP_5_1:112274,112285,112323
+ /branches/JBPAPP_5_1:112274,112285,112323
/branches/JBPAPP_5_1_2_GA_JBPAPP-7788:112572-112740
/tags/JBPAPP_5_1_2_GA:112570-112571
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/framework/server/HARMIServerImpl.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.naming.NoPermissionException;
import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
import org.jboss.ha.framework.interfaces.HAPartition;
@@ -43,6 +44,8 @@
import org.jboss.invocation.MarshalledInvocation;
import org.jboss.logging.Logger;
import org.jboss.net.sockets.DefaultSocketFactory;
+import org.jboss.ha.jndi.HARMIServerGuard;
+import org.jnp.server.NamingServerGuard;
/**
* This class is a <em>server-side</em> proxy for replicated RMI objects.
@@ -197,6 +200,14 @@
mi.setMethodMap(invokerMap);
Method method = mi.getMethod();
+ log.info("RMI local invocation =" + mi.isLocal());
+ if (NamingServerGuard.GUARDED_JNDI_METHOD_NAMES.indexOf(method.getName()) != -1)
+ {
+ throw new NoPermissionException(method.getName() +
+ " JNDI operation not allowed when on non-local invocation.");
+ }
+
+
try
{
HARMIResponse rsp = new HARMIResponse();
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/DetachedHANamingService.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -42,6 +42,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import javax.naming.NoPermissionException;
import javax.management.ObjectName;
import javax.net.ServerSocketFactory;
@@ -57,6 +58,7 @@
import org.jboss.util.threadpool.ThreadPool;
import org.jnp.interfaces.Naming;
import org.jnp.interfaces.NamingContext;
+import org.jnp.server.NamingServerGuard;
/**
* Management Bean for the protocol independent HA-JNDI service. This allows the
@@ -443,6 +445,14 @@
Method method = invocation.getMethod();
Object[] args = invocation.getArguments();
Object value = null;
+
+ log.info("DETACHED local invocation =" + invocation.isLocal());
+ if (!invocation.isLocal()
+ && NamingServerGuard.GUARDED_JNDI_METHOD_NAMES.indexOf(method.getName()) != -1) {
+ throw new NoPermissionException(method.getName() +
+ " JNDI operation not allowed when on non-local invocation.");
+ }
+
try
{
value = method.invoke(this.theServer, args);
Copied: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/HARMIServerGuard.java (from rev 112740, branches/JBPAPP_5_1_2_GA_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/HARMIServerGuard.java)
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/HARMIServerGuard.java (rev 0)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/cluster/src/main/org/jboss/ha/jndi/HARMIServerGuard.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -0,0 +1,90 @@
+ /*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., 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.ha.jndi;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.rmi.server.RemoteStub;
+import java.util.List;
+
+import javax.naming.NoPermissionException;
+
+import org.jboss.ha.framework.interfaces.HARMIResponse;
+import org.jboss.ha.framework.interfaces.HARMIServer;
+import org.jboss.invocation.MarshalledInvocation;
+import org.jboss.logging.Logger;
+import org.jnp.server.NamingServerGuard;
+
+
+/**
+ * Object to register instead of original object.
+ * It will guard certain invocations see invoke method.
+ *
+ * @author <a href="mailto:pskopek at redhat.com">Peter Skopek</a>
+ *
+ */
+public class HARMIServerGuard implements HARMIServer, Serializable
+{
+
+ private static Logger log = Logger.getLogger(HARMIServerGuard.class);
+
+ private HARMIServer guardedHARMIServer;
+
+ public HARMIServerGuard(HARMIServer guardedHARMIServer)
+ {
+ this.guardedHARMIServer = guardedHARMIServer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ha.framework.interfaces.HARMIServer#invoke(long, org.jboss.invocation.MarshalledInvocation)
+ */
+ public HARMIResponse invoke(long tag, MarshalledInvocation mi)
+ throws Exception
+ {
+ log.info("RMI local invocation =" + mi.isLocal());
+ Method method = mi.getMethod();
+ if (NamingServerGuard.GUARDED_JNDI_METHOD_NAMES.indexOf(method.getName()) != -1) {
+ throw new NoPermissionException(method.getName() +
+ " JNDI operation not allowed when on non-local invocation.");
+ }
+
+ return guardedHARMIServer.invoke(tag, mi);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ha.framework.interfaces.HARMIServer#getReplicants()
+ */
+ public List getReplicants() throws Exception
+ {
+ return guardedHARMIServer.getReplicants();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ha.framework.interfaces.HARMIServer#getLocal()
+ */
+ public Object getLocal() throws Exception
+ {
+ return guardedHARMIServer.getLocal();
+ }
+
+}
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/component-matrix/pom.xml
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/component-matrix/pom.xml 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/component-matrix/pom.xml 2012-03-08 18:07:26 UTC (rev 112741)
@@ -44,8 +44,8 @@
<version.jboss.jbossws>3.1.2.SP11</version.jboss.jbossws>
<version.jboss.jms-integration-tests>1.0.1.GA</version.jboss.jms-integration-tests>
<version.jboss.messaging>1.4.8.SP5</version.jboss.messaging>
- <version.hornetq>2.2.10.GA</version.hornetq>
- <version.jboss.web>2.1.12.GA-patch-03</version.jboss.web>
+ <version.hornetq>2.2.8.GA</version.hornetq>
+ <version.jboss.web>2.1.12.GA-patch-01</version.jboss.web>
<version.jgroups>2.6.20.Final</version.jgroups>
<version.junit>3.8.2</version.junit>
<version.org.hibernate.annotations>3.4.0.GA_CP04</version.org.hibernate.annotations>
Property changes on: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/main/src/bin/run.sh
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/JBPAPP_4_2_0_GA_CP/system/src/bin/run.sh:108548
/branches/JBPAPP_5_1/main/src/bin/run.sh:112274,112285,112323
+ /branches/JBPAPP_4_2_0_GA_CP/system/src/bin/run.sh:108548
/branches/JBPAPP_5_1/main/src/bin/run.sh:112274,112285,112323
/branches/JBPAPP_5_1_2_GA_JBPAPP-7788/main/src/bin/run.sh:112572-112740
/tags/JBPAPP_5_1_2_GA/main/src/bin/run.sh:112570-112571
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/pom.xml
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/pom.xml 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/pom.xml 2012-03-08 18:07:26 UTC (rev 112741)
@@ -296,7 +296,7 @@
<repository>
<id>mead-repository.redhat.com</id>
<name>JBoss Production Releases MEAD Repository</name>
- <url>http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-5.1.2-repo/latest/maven</url>
+ <url>http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-5-rhel-6-build/latest/maven</url>
<releases>
<enabled>true</enabled>
</releases>
@@ -400,7 +400,7 @@
<repository>
<id>mead-repository.redhat.com</id>
<name>JBoss Production Releases MEAD Repository</name>
- <url>http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-5.1.2-errata-repo/latest/maven</url>
+ <url>http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-5-rhel-6-build/latest/maven</url>
<releases>
<enabled>true</enabled>
</releases>
Copied: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/NamingUtil.java (from rev 112740, branches/JBPAPP_5_1_2_GA_JBPAPP-7788/testsuite/src/main/org/jboss/test/NamingUtil.java)
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/NamingUtil.java (rev 0)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/NamingUtil.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -0,0 +1,197 @@
+ /*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., 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.test;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.security.auth.login.LoginContext;
+
+import org.apache.log4j.Logger;
+import org.jboss.test.util.AppCallbackHandler;
+
+/**
+ * Utility class for tests using naming in a special way.
+ *
+ * @author <a href="mailto:pskopek at redhat.com">Peter Skopek</a>
+ *
+ */
+public class NamingUtil
+{
+
+ public static Logger log = Logger.getLogger(NamingUtil.class);
+
+ public static final String JNDI_INVOKER = "invoker/JNDIFactory";
+ public static final String HAJNDI_INVOKER = "invoker/HAJNDIFactory";
+
+ /**
+ * Create test data. It needs to use org.jboss.naming.HttpNamingContextFactory since JNDI through RMI
+ * is already secured and disallow bind/unbind/rebind operations.
+ *
+ *
+ *
+ * @param jndiName JNDI path where to bind data.
+ * @param data Data object to bind. In case data is null last path element is considered subContext.
+ * @throws Exception
+ */
+ public static void createTestJNDIBinding(String jndiName, Object data, String serverHost)
+ throws Exception
+ {
+
+ Context ctx = NamingUtil.getFullInitialContext(serverHost);
+
+ String[] path = jndiName.split("/");
+ String subPath = "";
+ for (int i = 0; i < path.length; i++)
+ {
+
+ if (path[i].equals(""))
+ {
+ continue;
+ }
+
+ subPath = subPath + "/" + path[i];
+
+ if (i < path.length - 1)
+ {
+ ctx.createSubcontext(subPath);
+ }
+ else
+ {
+ if (data != null)
+ {
+ ctx.bind(subPath, data);
+ }
+ else
+ {
+ ctx.createSubcontext(subPath);
+ }
+
+ }
+ }
+
+ ctx.close();
+
+ }
+
+ /**
+ * Returns initial context which is able to perform all JNDI operations.
+ * @param serverHost - use getServerHostForURL() from inside JBoss Testsuite
+ * @param jndiFactoryUrlSuffix - URL suffix to get proper invoker invoker/JNDIFactory or invoker/HAJNDIFactory
+ * @return
+ * @throws Exception
+ */
+ public static InitialContext getFullInitialContext(String serverHost, String jndiFactoryUrlSuffix)
+ throws Exception
+ {
+
+ if (jndiFactoryUrlSuffix == null) {
+ jndiFactoryUrlSuffix = JNDI_INVOKER;
+ }
+
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
+
+ env.setProperty(Context.PROVIDER_URL, "http://" + serverHost + ":8080/" + jndiFactoryUrlSuffix);
+ log.debug("Creating InitialContext with env="+env);
+ InitialContext ctx = new InitialContext(env);
+
+ return ctx;
+ }
+
+
+
+ /**
+ * Returns initial context which is able to perform all JNDI operations.
+ * @param serverHost - use getServerHostForURL() from inside JBoss Testsuite
+ * @return
+ * @throws Exception
+ */
+ public static InitialContext getFullInitialContext(String serverHost)
+ throws Exception
+ {
+ return getFullInitialContext(serverHost, JNDI_INVOKER);
+ }
+
+ /**
+ * Returns initial context which is able to perform all JNDI operations.
+ * @param serverHost - use getServerHostForURL() from inside JBoss Testsuite
+ * @return
+ * @throws Exception
+ */
+ public static InitialContext getFullHAInitialContext(String serverHost)
+ throws Exception
+ {
+ return getFullInitialContext(serverHost, HAJNDI_INVOKER);
+ }
+
+ /**
+ * Extract hostname from jndiURL parameter and get InitialContext using @see getFullInitialContext
+ * @param jndiUrl
+ * @return
+ * @throws Exception
+ */
+ public static InitialContext getFullInitialContextFromUrl(String jndiUrl)
+ throws Exception
+ {
+ log.debug("jndiUrl = " + jndiUrl);
+ URI uri = new URI(jndiUrl);
+ log.debug("host="+uri.getHost());
+ return NamingUtil.getFullInitialContext(uri.getHost());
+ }
+
+ /**
+ * Extract hostname from jndiURL parameter and get InitialContext using @see getFullInitialContext
+ * @param jndiUrl
+ * @return
+ * @throws Exception
+ */
+ public static InitialContext getFullHAInitialContextFromUrl(String jndiUrl)
+ throws Exception
+ {
+ log.debug("jndiUrl = " + jndiUrl);
+ URI uri = new URI(jndiUrl);
+ log.debug("host="+uri.getHost());
+ return NamingUtil.getFullHAInitialContext(uri.getHost());
+ }
+
+ /**
+ * Returns URL string for given resource.
+ *
+ * @param resource
+ * @return
+ * @throws MalformedURLException
+ */
+ private static String getResourceURL(final String resource)
+ throws MalformedURLException
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL resURL = loader.getResource(resource);
+ return resURL != null ? resURL.toString() : null;
+ }
+
+}
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/cluster/multicfg/test/HAJndiTestCase.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/cluster/multicfg/test/HAJndiTestCase.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/cluster/multicfg/test/HAJndiTestCase.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -29,6 +29,7 @@
import junit.framework.Test;
+import org.jboss.test.NamingUtil;
import org.jboss.test.cluster.ejb2.crossserver.CalledHome;
import org.jboss.test.cluster.ejb2.crossserver.CalledRemote;
import org.jnp.interfaces.NamingContext;
@@ -86,8 +87,8 @@
getLog().debug("HAJndiTestCase.testLocalBinding()");
validateUrls();
- // bind to node0 locally
- Context naming = getContext(NODE0_JNDI);
+ // bind to node0 locally using different JNDI connector because of disabling bind operation from non-local JVMs
+ Context naming = NamingUtil.getFullInitialContextFromUrl(NODE0_JNDI);
naming.bind(LOCAL0_KEY, LOCAL0_VALUE);
closeContext(naming);
@@ -128,7 +129,7 @@
validateUrls();
// bind to node0 using HA-JNDI
- Context naming = getContext(NODE0_HAJNDI);
+ Context naming = NamingUtil.getFullHAInitialContextFromUrl(NODE0_HAJNDI);
naming.bind(GLOBAL0_KEY, GLOBAL0_VALUE);
closeContext(naming);
@@ -170,7 +171,7 @@
validateUrls();
// bind to node0 using HA-JNDI
- Context naming = getContext(NODE0_HAJNDI);
+ Context naming = NamingUtil.getFullHAInitialContextFromUrl(NODE0_HAJNDI);
naming.bind(JNDI_KEY, JNDI_VALUE1);
// lookup binding using HA-JNDI on Node0 - should succeed
@@ -201,7 +202,7 @@
// lookup binding - should fail with NamingException
value = (String)lookup(naming, JNDI_KEY, false);
assertNull("lookup after HA-JNDI unbind operation", value);
-
+
closeContext(naming);
}
@@ -217,7 +218,7 @@
validateUrls();
// create subcontexts
- Context naming = getContext(NODE0_HAJNDI);
+ Context naming = NamingUtil.getFullHAInitialContextFromUrl(NODE0_HAJNDI);
Context sub1 = naming.createSubcontext(SUBCON1);
Context sub2 = naming.createSubcontext(SUBCON2);
Context sub1a = sub1.createSubcontext(SUBCON1A);
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -29,14 +29,17 @@
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.NoPermissionException;
import javax.rmi.PortableRemoteObject;
import javax.security.auth.login.LoginContext;
+import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.security.SecurityAssociation;
import org.jboss.test.JBossTestCase;
+import org.jboss.test.NamingUtil;
import org.jboss.test.naming.interfaces.TestENC;
import org.jboss.test.naming.interfaces.TestENCHome;
import org.jboss.test.util.AppCallbackHandler;
@@ -65,6 +68,9 @@
suite.addTest(new SecurityUnitTestCase("testLoginInitialContext"));
suite.addTest(new SecurityUnitTestCase("testSecureEJBViaLoginInitialContextFactory"));
suite.addTest(new SecurityUnitTestCase("testSecureEJBViaJndiLoginInitialContextFactory"));
+ suite.addTest(new SecurityUnitTestCase("testNamingOperationBindSecurity"));
+ suite.addTest(new SecurityUnitTestCase("testNamingOperationUnBindSecurity"));
+ suite.addTest(new SecurityUnitTestCase("testNamingOperationCreateSubcontextSecurity"));
return suite;
}
@@ -171,17 +177,9 @@
/* Try without a login to ensure that a lookup against "readonly" works.
*First create the readonly context using the standard JNDI factory
*/
- InitialContext bootCtx = new InitialContext();
- try
- {
- bootCtx.unbind("readonly");
- }
- catch(NamingException ignore)
- {
- }
- Context readonly = bootCtx.createSubcontext("readonly");
- readonly.bind("data", "somedata");
+ NamingUtil.createTestJNDIBinding("readonly/data", "somedata", getServerHost());
+
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
env.setProperty(Context.PROVIDER_URL, INVOKER_BASE + "ReadOnlyJNDIFactory");
@@ -250,9 +248,16 @@
}
catch(NamingException ignore)
{
+ getLog().error("Caught exception, but will be ignored", ignore);
}
getLog().debug("Creating readonly context");
- bootCtx.createSubcontext("readonly");
+ try {
+ bootCtx.createSubcontext("readonly");
+ }
+ catch (Exception e) {
+ getLog().debug(e);
+ throw new Exception(e);
+ }
bootCtx.bind("readonly/data", "somedata");
// Test access through the readonly proxy
@@ -425,4 +430,83 @@
super.undeploy("naming.jar");
}
}
+
+ public void testNamingOperationBindSecurity() throws Exception
+ {
+ getLog().debug("+++ testNamingOperationBindSecurity");
+
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ // JBPAPP-2997
+ env.setProperty(Context.PROVIDER_URL, "jnp://" + getServerHost() + ":1099/");
+
+ getLog().debug("Creating InitialContext with env="+env);
+ InitialContext ctx = new InitialContext(env);
+ getLog().debug("Created InitialContext, ctx="+ctx);
+ getLog().info("ctx="+ctx.getClass().getName());
+
+ try
+ {
+ ctx.bind("fruit", "lemon");
+ Assert.fail("binding is expected to fail with javax.naming.NoPermissionException");
+ }
+ catch (NoPermissionException npe)
+ {
+ // expected
+ getLog().debug("Caught exception as expected");
+ }
+ }
+
+ public void testNamingOperationUnBindSecurity() throws Exception
+ {
+ getLog().debug("+++ testNamingOperationUnBindSecurity");
+
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ // JBPAPP-2997
+ env.setProperty(Context.PROVIDER_URL, "jnp://" + getServerHost() + ":1099/");
+
+ getLog().debug("Creating InitialContext with env="+env);
+ InitialContext ctx = new InitialContext(env);
+ getLog().debug("Created InitialContext, ctx="+ctx);
+ getLog().info("ctx="+ctx.getClass().getName());
+
+ try
+ {
+ ctx.unbind("/queue/D");
+ Assert.fail("unbinding is expected to fail with javax.naming.NoPermissionException");
+ }
+ catch (NoPermissionException npe)
+ {
+ // expected
+ getLog().debug("Caught exception as expected");
+ }
+ }
+
+ public void testNamingOperationCreateSubcontextSecurity() throws Exception
+ {
+ getLog().debug("+++ testNamingOperationCreateSubcontextSecurity");
+
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ // JBPAPP-2997
+ env.setProperty(Context.PROVIDER_URL, "jnp://" + getServerHost() + ":1099/");
+
+ getLog().debug("Creating InitialContext with env="+env);
+ InitialContext ctx = new InitialContext(env);
+ getLog().debug("Created InitialContext, ctx="+ctx);
+ getLog().info("ctx="+ctx.getClass().getName());
+
+ try
+ {
+ ctx.createSubcontext("/never_should_be_created_subcontext");
+ Assert.fail("createSubcontext is expected to fail with javax.naming.NoPermissionException");
+ }
+ catch (NoPermissionException npe)
+ {
+ // expected
+ getLog().debug("Caught exception as expected");
+ }
+ }
+
}
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/naming/test/SimpleUnitTestCase.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -23,6 +23,9 @@
import java.util.Properties;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.NamingUtil;
+
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
@@ -58,7 +61,7 @@
public void testCreateSubcontext() throws Exception
{
getLog().debug("+++ testCreateSubcontext");
- InitialContext ctx = getInitialContext();
+ InitialContext ctx = NamingUtil.getFullInitialContext(getServerHost());
ctx.createSubcontext("foo");
try
{
@@ -103,12 +106,13 @@
count ++;
}
assertTrue("list count > 0 ", count > 0);
+ ctx.close();
}
public void testNameChanges() throws Exception
{
getLog().debug("+++ testNameChanges");
- InitialContext ctx = getInitialContext();
+ InitialContext ctx = NamingUtil.getFullInitialContext(getServerHost());
Name name = ctx.getNameParser("").parse("jnp://" + getServerHost() + "/jmx");
Name copy = (Name) name.clone();
Object obj = ctx.lookup(name);
@@ -181,13 +185,8 @@
public void testCreateHaJndiSubcontext() throws Exception
{
getLog().debug("+++ testCreateHaJndiSubcontext");
- // Lookup a name that does not exist
- java.util.Properties env = new java.util.Properties();
- env.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
- env.setProperty(javax.naming.Context.PROVIDER_URL, "jnp://" + getServerHost() + ":1100/");
- getLog().debug("Creating InitialContext with env="+env);
-
- InitialContext ctx = new javax.naming.InitialContext(env);
+ // Look a name that does not exist
+ InitialContext ctx = NamingUtil.getFullHAInitialContext(getServerHost());
Object obj = ctx.lookup("");
getLog().debug("lookup('') against HA-JNDI succeeded as expected, obj="+obj);
Modified: tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/security/test/LoginModulesUnitTestCase.java
===================================================================
--- tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/security/test/LoginModulesUnitTestCase.java 2012-03-08 16:52:13 UTC (rev 112740)
+++ tags/JBPAPP_5_1_2_GA_CVE_JBPAPP-7788/testsuite/src/main/org/jboss/test/security/test/LoginModulesUnitTestCase.java 2012-03-08 18:07:26 UTC (rev 112741)
@@ -68,6 +68,7 @@
import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
import org.jboss.security.plugins.JaasSecurityDomain;
import org.jboss.test.JBossTestCase;
+import org.jboss.test.NamingUtil;
/** Tests of the LoginModule classes.
@@ -984,8 +985,9 @@
public void testCertLogin() throws Exception
{
log.info("testCertLogin");
- InitialContext ctx = new InitialContext();
+ InitialContext ctx = NamingUtil.getFullInitialContext(getServerHost());
ctx.rebind("testCertLogin", new TestSecurityDomain());
+ ctx.close();
KeyStore store = KeyStore.getInstance("JKS");
ClassLoader loader = Thread.currentThread().getContextClassLoader();
@@ -1005,9 +1007,10 @@
public void testCertRoles() throws Exception
{
log.info("testCertRoles");
- InitialContext ctx = new InitialContext();
+ InitialContext ctx = NamingUtil.getFullInitialContext(getServerHost());
ctx.rebind("testCertRoles", new TestSecurityDomain());
-
+ ctx.close();
+
KeyStore store = KeyStore.getInstance("JKS");
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL resURL = loader.getResource("security/tst.keystore");
@@ -1064,8 +1067,9 @@
Class.forName("org.hsqldb.jdbcDriver");
// Create a DataSource binding
TestDS ds = new TestDS();
- InitialContext ctx = new InitialContext();
+ InitialContext ctx = NamingUtil.getFullInitialContext(getServerHost());
ctx.rebind("testJdbc", ds);
+ ctx.close();
// Start database and setup tables
Connection conn = ds.getConnection("sa", "");
More information about the jboss-cvs-commits
mailing list