[jboss-cvs] JBossAS SVN: r60317 - in branches/Branch_4_2: testsuite/src/main/org/jboss/test/naming/ejb and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 6 00:22:04 EST 2007
Author: scott.stark at jboss.org
Date: 2007-02-06 00:22:04 -0500 (Tue, 06 Feb 2007)
New Revision: 60317
Modified:
branches/Branch_4_2/security/src/main/org/jboss/security/jndi/JndiLoginInitialContextFactory.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestENCBean.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestEjbLinkBean.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENC.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome2.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocal.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocalHome.java
branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java
branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/ejb-jar.xml
branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/jboss.xml
branches/Branch_4_2/testsuite/src/resources/naming/roles.properties
branches/Branch_4_2/testsuite/src/resources/naming/users.properties
Log:
JBAS-2523, multi-threaded and restoreIdentity options
Modified: branches/Branch_4_2/security/src/main/org/jboss/security/jndi/JndiLoginInitialContextFactory.java
===================================================================
--- branches/Branch_4_2/security/src/main/org/jboss/security/jndi/JndiLoginInitialContextFactory.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/security/src/main/org/jboss/security/jndi/JndiLoginInitialContextFactory.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -81,6 +81,7 @@
SecurityAssociationActions.setServer();
}
boolean restoreLoginIdentity = false;
+ flag = (String) env.get("jnp.restoreLoginIdentity");
if( flag != null )
restoreLoginIdentity = Boolean.parseBoolean(flag);
// See if the principal is a Principal or String
@@ -97,7 +98,7 @@
// Associate this security context
if( restoreLoginIdentity )
{
- SecurityAssociationActions.setPrincipalInfo(securityPrincipal, credentials);
+ SecurityAssociationActions.setPrincipalInfo(securityPrincipal, credentials, null);
}
else
{
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestENCBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestENCBean.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestENCBean.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.naming.ejb;
+import java.util.Properties;
+
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
@@ -31,8 +33,12 @@
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
import org.apache.log4j.Logger;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.test.naming.interfaces.TestEjbLinkLocal;
+import org.jboss.test.naming.interfaces.TestEjbLinkLocalHome;
/** A bean that does nothing but access resources from the ENC
to test ENC usage.
@@ -42,6 +48,7 @@
*/
public class TestENCBean implements SessionBean
{
+ private static final long serialVersionUID = 1;
Logger log = Logger.getLogger(getClass());
private SessionContext sessionContext;
@@ -127,6 +134,50 @@
}
}
+ public String testEjbLinkCallerLocalWithLogin(String jndiName,
+ String username, String password)
+ {
+ try
+ {
+ log.info("testEjbLinkCallerLocalWithLogin");
+ String incomingCaller = this.sessionContext.getCallerPrincipal().getName();
+ log.info("incomingCaller="+incomingCaller);
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
+ env.setProperty(Context.SECURITY_PRINCIPAL, username);
+ env.setProperty(Context.SECURITY_CREDENTIALS, password);
+ env.setProperty("jnp.restoreLoginIdentity", "true");
+ InitialContext initial = new InitialContext(env);
+ Object object = initial.lookup(jndiName);
+ log.debug("jndiName="+jndiName);
+
+ // TODO: caching in the ejb context does not following changes
+ //String newCaller = this.sessionContext.getCallerPrincipal().getName();
+ String newCaller = SecurityAssociation.getCallerPrincipal().getName();
+ if( newCaller.equals(username) == false )
+ return "False-newCaller,"+newCaller;
+ log.info("newCaller="+newCaller);
+
+ TestEjbLinkLocalHome home =
+ (TestEjbLinkLocalHome) PortableRemoteObject.narrow(object, TestEjbLinkLocalHome.class);
+ TestEjbLinkLocal bean = home.create();
+ String result = bean.testEjbLinkCalled();
+ initial.close();
+ // Validate that the incoming caller has been restored
+ String restoredCaller = this.sessionContext.getCallerPrincipal().getName();
+ if( restoredCaller.equals(incomingCaller) == false )
+ return "False-restoredCalled,"+restoredCaller;
+ log.info("restoredCaller="+restoredCaller);
+
+ return result;
+ }
+ catch (Exception e)
+ {
+ log.debug("failed", e);
+ return "Failed";
+ }
+ }
+
private void testEnvEntries(Context initCtx, Context myEnv) throws NamingException
{
// Basic env values
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestEjbLinkBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestEjbLinkBean.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/ejb/TestEjbLinkBean.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -25,11 +25,10 @@
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
-import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
+import org.jboss.logging.Logger;
import org.jboss.test.naming.interfaces.TestEjbLinkHome;
import org.jboss.test.naming.interfaces.TestEjbLink;
import org.jboss.test.naming.interfaces.TestEjbLinkLocalHome;
@@ -43,7 +42,8 @@
*/
public class TestEjbLinkBean implements SessionBean
{
- org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(getClass());
+ private static final long serialVersionUID = 1;
+ static Logger log = Logger.getLogger(TestEjbLinkBean.class);
public void ejbCreate() throws CreateException
{
@@ -62,7 +62,8 @@
{
}
- public void setSessionContext(SessionContext sessionContext) throws EJBException
+ public void setSessionContext(SessionContext sessionContext)
+ throws EJBException
{
}
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENC.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENC.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENC.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -22,6 +22,7 @@
package org.jboss.test.naming.interfaces;
import java.rmi.RemoteException;
+
import javax.ejb.EJBObject;
/**
@@ -41,4 +42,14 @@
* @throws RemoteException
*/
public void accessENC() throws RemoteException;
+
+ /**
+ * Call a bean with the passed jndi name bound using ejb-link
+ * using an identity based on using the JndiLoginInitialContextFactory
+ * @param jndiName the name of the bean specified in ejb-ref
+ * @return the result of the call or "Failed" on an error
+ */
+ public String testEjbLinkCallerLocalWithLogin(String jndiName,
+ String username, String password)
+ throws RemoteException;
}
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -27,7 +27,7 @@
/**
- at author Scott_Stark at displayscape.com
+ at author Scott.Stark@@jboss.org
@version $Revision$
*/
public interface TestENCHome extends EJBHome
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome2.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome2.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestENCHome2.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -27,7 +27,7 @@
/**
- at author Scott_Stark at displayscape.com
+ at author Scott.Stark@@jboss.org
@version $Revision$
*/
public interface TestENCHome2 extends EJBHome
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocal.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocal.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocal.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -42,4 +42,5 @@
* @return the string "Works"
*/
public String testEjbLinkCalled();
+
}
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocalHome.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocalHome.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/interfaces/TestEjbLinkLocalHome.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -21,7 +21,6 @@
*/
package org.jboss.test.naming.interfaces;
-import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/naming/test/SecurityUnitTestCase.java 2007-02-06 05:22:04 UTC (rev 60317)
@@ -380,7 +380,7 @@
}
/**
- * Use the LoginInitialContextFactory to access a secured ejb
+ * Use the JndiLoginInitialContextFactory to access a secured ejb
* @throws Exception
*/
public void testSecureEJBViaJndiLoginInitialContextFactory() throws Exception
@@ -414,4 +414,43 @@
super.undeploy("naming.jar");
}
}
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testEjbLinkLocalSecured() throws Exception
+ {
+
+ getLog().debug("+++ testEjbLinkLocalSecured");
+ Properties env = new Properties();
+ // Try with a login that should succeed
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
+ env.setProperty(Context.PROVIDER_URL, "jnp://" + getServerHost() + ":1099/");
+ env.setProperty(Context.SECURITY_CREDENTIALS, "theduke");
+ env.setProperty(Context.SECURITY_PRINCIPAL, "jduke");
+
+ getLog().debug("Creating InitialContext with env="+env);
+ InitialContext ctx = new InitialContext(env);
+ getLog().debug("Created InitialContext, ctx="+ctx);
+ super.redeploy("naming.jar");
+ Object obj = getInitialContext().lookup("ENCTests/ejbs/SecuredENCBean");
+ obj = PortableRemoteObject.narrow(obj, TestENCHome.class);
+ TestENCHome home = (TestENCHome)obj;
+ getLog().debug("Found SecuredENCBean");
+
+ try
+ {
+ TestENC bean = home.create();
+ getLog().debug("Created SecuredENCBean");
+ String result = bean.testEjbLinkCallerLocalWithLogin(
+ "java:comp/env/local/SecuredENCBean2", "jduke2", "theduke2");
+ assertEquals("testEjbLinkCallerLocalWithLogin.result", "Works", result);
+ bean.remove();
+ }
+ finally
+ {
+ super.undeploy("naming.jar");
+ }
+ }
}
Modified: branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/ejb-jar.xml 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/ejb-jar.xml 2007-02-06 05:22:04 UTC (rev 60317)
@@ -1,8 +1,4 @@
<?xml version="1.0"?>
-<!DOCTYPE ejb-jar PUBLIC
- "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
- "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
-
<ejb-jar version="2.1"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -256,6 +252,13 @@
<remote>org.jboss.test.naming.interfaces.TestENC</remote>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
+ <ejb-local-ref>
+ <ejb-ref-name>local/SecuredENCBean2</ejb-ref-name>
+ <ejb-ref-type>Session</ejb-ref-type>
+ <local-home>org.jboss.test.naming.interfaces.TestEjbLinkLocalHome</local-home>
+ <local>org.jboss.test.naming.interfaces.TestEjbLinkLocal</local>
+ <ejb-link>SecuredENCBean2</ejb-link>
+ </ejb-local-ref>
<env-entry>
<description>This bean should NOT have the same ENC as ENCBean</description>
<env-entry-name>hasFullENC</env-entry-name>
@@ -263,6 +266,21 @@
<env-entry-value>false</env-entry-value>
</env-entry>
</session>
+ <session>
+ <description>A deployment that is secured</description>
+ <ejb-name>SecuredENCBean2</ejb-name>
+ <ejb-class>org.jboss.test.naming.ejb.TestEjbLinkBean</ejb-class>
+ <local-home>org.jboss.test.naming.interfaces.TestEjbLinkLocalHome</local-home>
+ <local>org.jboss.test.naming.interfaces.TestEjbLinkLocal</local>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ <env-entry>
+ <description>This bean should NOT have the same ENC as ENCBean</description>
+ <env-entry-name>hasFullENC</env-entry-name>
+ <env-entry-type>java.lang.Boolean</env-entry-type>
+ <env-entry-value>false</env-entry-value>
+ </env-entry>
+ </session>
</enterprise-beans>
<assembly-descriptor>
@@ -270,7 +288,11 @@
<description>Users allowed to access SecuredENCBean</description>
<role-name>ENCUser</role-name>
</security-role>
-
+ <security-role>
+ <description>Users allowed to access SecuredENCBean2</description>
+ <role-name>ENCUser2</role-name>
+ </security-role>
+
<method-permission>
<role-name>ENCUser</role-name>
<method>
@@ -278,7 +300,14 @@
<method-name>*</method-name>
</method>
</method-permission>
-
+ <method-permission>
+ <role-name>ENCUser2</role-name>
+ <method>
+ <ejb-name>SecuredENCBean2</ejb-name>
+ <method-name>*</method-name>
+ </method>
+ </method-permission>
+
<message-destination>
<message-destination-name>TestQueue</message-destination-name>
</message-destination>
Modified: branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/jboss.xml 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/resources/naming/jar/META-INF/jboss.xml 2007-02-06 05:22:04 UTC (rev 60317)
@@ -64,9 +64,9 @@
<jndi-name>psuedo-url:/ejb/ENCBean2</jndi-name>
</session>
<session>
- <ejb-name>SecuredENCBean</ejb-name>
- <jndi-name>ENCTests/ejbs/SecuredENCBean</jndi-name>
- <configuration-name>Secured SessionBean</configuration-name>
+ <ejb-name>SecuredENCBean</ejb-name>
+ <jndi-name>ENCTests/ejbs/SecuredENCBean</jndi-name>
+ <configuration-name>Secured SessionBean</configuration-name>
</session>
</enterprise-beans>
@@ -82,15 +82,15 @@
</assembly-descriptor>
<resource-managers>
- <resource-manager res-class="">
+ <resource-manager>
<res-name>DefaultDS</res-name>
<res-jndi-name>java:/DefaultDS</res-jndi-name>
</resource-manager>
- <resource-manager res-class="">
+ <resource-manager>
<res-name>DefaultMail</res-name>
<res-jndi-name>java:/Mail</res-jndi-name>
</resource-manager>
- <resource-manager res-class="java.net.URL">
+ <resource-manager>
<res-name>SourceforgeHomePage</res-name>
<res-url>http://sourceforge.net/</res-url>
</resource-manager>
Modified: branches/Branch_4_2/testsuite/src/resources/naming/roles.properties
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/naming/roles.properties 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/resources/naming/roles.properties 2007-02-06 05:22:04 UTC (rev 60317)
@@ -1,3 +1,4 @@
jduke=ENCUser,Echo
jduke.CallerPrincipal=callerJduke
+jduke2=ENCUser2
invoker=HttpInvoker
\ No newline at end of file
Modified: branches/Branch_4_2/testsuite/src/resources/naming/users.properties
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/naming/users.properties 2007-02-06 04:15:19 UTC (rev 60316)
+++ branches/Branch_4_2/testsuite/src/resources/naming/users.properties 2007-02-06 05:22:04 UTC (rev 60317)
@@ -1,3 +1,4 @@
jduke=theduke
+jduke2=theduke2
jdukeman=anotherduke
invoker=invoker
More information about the jboss-cvs-commits
mailing list