User: starksm
Date: 02/03/02 23:40:50
Modified: src/main/org/jboss/test/security/test
EJBSpecUnitTestCase.java
Log:
Add test of a stateless session bean accessing getCallerPrincipal
in ejbCreate
Revision Changes Path
1.10 +65 -47
jbosstest/src/main/org/jboss/test/security/test/EJBSpecUnitTestCase.java
Index: EJBSpecUnitTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/security/test/EJBSpecUnitTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EJBSpecUnitTestCase.java 15 Feb 2002 06:15:56 -0000 1.9
+++ EJBSpecUnitTestCase.java 3 Mar 2002 07:40:50 -0000 1.10
@@ -43,13 +43,11 @@
deployment unit. These test the basic role based access model.
@author [EMAIL PROTECTED]
- @version $Revision: 1.9 $
+ @version $Revision: 1.10 $
*/
public class EJBSpecUnitTestCase
extends JBossTestCase
{
- org.apache.log4j.Category log = getLog();
-
static String username = "scott";
static char[] password = "echoman".toCharArray();
static String QUEUE_FACTORY = "ConnectionFactory";
@@ -73,13 +71,13 @@
public void testGetCallerPrincipal() throws Exception
{
logout();
- getLog().debug("+++ testGetCallerPrincipal()");
+ log.debug("+++ testGetCallerPrincipal()");
Object obj = getInitialContext().lookup("spec.UnsecureStatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found Unsecure StatelessSessionHome");
+ log.debug("Found Unsecure StatelessSessionHome");
StatelessSession bean = home.create();
- getLog().debug("Created spec.UnsecureStatelessSession2");
+ log.debug("Created spec.UnsecureStatelessSession2");
try
{
@@ -89,7 +87,7 @@
}
catch(RemoteException e)
{
- getLog().debug("echo failed as expected");
+ log.debug("echo failed as expected");
}
bean.remove();
@@ -97,12 +95,12 @@
obj = getInitialContext().lookup("spec.StatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
home = (StatelessSessionHome) obj;
- getLog().debug("Found spec.StatelessSession2");
+ log.debug("Found spec.StatelessSession2");
bean = home.create();
- getLog().debug("Created spec.StatelessSession2");
+ log.debug("Created spec.StatelessSession2");
// Test that the Entity bean sees username as its principal
String echo = bean.echo(username);
- getLog().debug("bean.echo(username) = "+echo);
+ log.debug("bean.echo(username) = "+echo);
assertTrue("username == echo", echo.equals(username));
bean.remove();
}
@@ -111,16 +109,16 @@
*/
public void testPrincipalPropagation() throws Exception
{
- getLog().debug("+++ testPrincipalPropagation");
+ log.debug("+++ testPrincipalPropagation");
logout();
login();
Object obj = getInitialContext().lookup("spec.UnsecureStatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found Unsecure StatelessSessionHome");
+ log.debug("Found Unsecure StatelessSessionHome");
StatelessSession bean = home.create();
- getLog().debug("Created spec.UnsecureStatelessSession2");
- getLog().debug("Bean.forward('Hello') -> "+bean.forward("Hello"));
+ log.debug("Created spec.UnsecureStatelessSession2");
+ log.debug("Bean.forward('Hello') -> "+bean.forward("Hello"));
bean.remove();
}
@@ -131,15 +129,15 @@
*/
public void testMethodAccess() throws Exception
{
- getLog().debug("+++ testMethodAccess");
+ log.debug("+++ testMethodAccess");
login();
Object obj = getInitialContext().lookup("spec.StatelessSession");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found StatelessSessionHome");
+ log.debug("Found StatelessSessionHome");
StatelessSession bean = home.create();
- getLog().debug("Created spec.StatelessSession");
- getLog().debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+ log.debug("Created spec.StatelessSession");
+ log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
try
{
@@ -149,7 +147,7 @@
}
catch(RemoteException e)
{
- getLog().debug("StatelessSession.noop failed as expected");
+ log.debug("StatelessSession.noop failed as expected");
}
bean.remove();
}
@@ -179,20 +177,20 @@
*/
public void testUnchecked() throws Exception
{
- getLog().debug("+++ testUnchecked");
+ log.debug("+++ testUnchecked");
// Login as scott to create the bean
login();
Object obj = getInitialContext().lookup("spec.StatelessSession");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found spec.StatelessSession Home");
+ log.debug("Found spec.StatelessSession Home");
StatelessSession bean = home.create();
- getLog().debug("Created spec.StatelessSession");
+ log.debug("Created spec.StatelessSession");
// Logout and login back in as stark to test access to the unchecked method
logout();
login("stark", "javaman".toCharArray());
bean.unchecked();
- getLog().debug("Called Bean.unchecked()");
+ log.debug("Called Bean.unchecked()");
logout();
}
@@ -204,14 +202,14 @@
*/
public void testExcluded() throws Exception
{
- getLog().debug("+++ testExcluded");
+ log.debug("+++ testExcluded");
login();
Object obj = getInitialContext().lookup("spec.StatelessSession2");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found spec.StatelessSession2 Home");
+ log.debug("Found spec.StatelessSession2 Home");
StatelessSession bean = home.create();
- getLog().debug("Created spec.StatelessSession2");
+ log.debug("Created spec.StatelessSession2");
try
{
bean.excluded();
@@ -219,7 +217,7 @@
}
catch(Exception e)
{
- getLog().debug("Bean.excluded() failed as expected");
+ log.debug("Bean.excluded() failed as expected");
// This is what we expect
}
logout();
@@ -238,17 +236,17 @@
*/
public void testRunAs() throws Exception
{
- getLog().debug("+++ testRunAs");
+ log.debug("+++ testRunAs");
login();
Object obj = getInitialContext().lookup("spec.RunAsStatelessSession");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found RunAsStatelessSession Home");
+ log.debug("Found RunAsStatelessSession Home");
StatelessSession bean = home.create();
- getLog().debug("Created spec.RunAsStatelessSession");
- getLog().debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+ log.debug("Created spec.RunAsStatelessSession");
+ log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
bean.noop();
- getLog().debug("Bean.noop(), ok");
+ log.debug("Bean.noop(), ok");
try
{
@@ -258,7 +256,7 @@
}
catch(RemoteException e)
{
- getLog().debug("StatelessSession.forward failed as expected");
+ log.debug("StatelessSession.forward failed as expected");
}
bean.remove();
}
@@ -268,7 +266,7 @@
*/
public void testMDBRunAs() throws Exception
{
- getLog().debug("+++ testMDBRunAs");
+ log.debug("+++ testMDBRunAs");
logout();
QueueConnectionFactory queueFactory = (QueueConnectionFactory)
getInitialContext().lookup(QUEUE_FACTORY);
Queue que = (Queue) getInitialContext().lookup("queue/A");
@@ -279,10 +277,10 @@
QueueSender sender = session.createSender(que);
sender.send(msg);
sender.close();
- getLog().debug("Sent msg to queue/A");
+ log.debug("Sent msg to queue/A");
QueueReceiver recv = session.createReceiver(que);
msg = recv.receive(5000);
- getLog().debug("Recv msg: "+msg);
+ log.debug("Recv msg: "+msg);
recv.close();
session.close();
queueConn.close();
@@ -293,19 +291,19 @@
*/
public void testHandle() throws Exception
{
- getLog().debug("+++ testHandle");
+ log.debug("+++ testHandle");
login();
Object obj = getInitialContext().lookup("spec.StatelessSession");
obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
StatelessSessionHome home = (StatelessSessionHome) obj;
- getLog().debug("Found StatelessSessionHome");
+ log.debug("Found StatelessSessionHome");
StatelessSession bean = home.create();
- getLog().debug("Created spec.StatelessSession");
+ log.debug("Created spec.StatelessSession");
Handle h = bean.getHandle();
- getLog().debug("Obtained handle: "+h);
+ log.debug("Obtained handle: "+h);
bean = (StatelessSession) h.getEJBObject();
- getLog().debug("Obtained bean from handle: "+bean);
- getLog().debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+ log.debug("Obtained bean from handle: "+bean);
+ log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
logout();
/* Attempting to obtain the EJB fron the handle without security
@@ -318,7 +316,7 @@
}
catch(Exception e)
{
- getLog().debug("Obtaining bean from handle failed as expected,
e="+e.getMessage());
+ log.debug("Obtaining bean from handle failed as expected,
e="+e.getMessage());
}
// One should be able to obtain a handle without a login
@@ -326,11 +324,31 @@
login();
// Now we should be able to obtain and use the secure bean
bean = (StatelessSession) h.getEJBObject();
- getLog().debug("Obtained bean from handle: "+bean);
- getLog().debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+ log.debug("Obtained bean from handle: "+bean);
+ log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
logout();
}
+ /** Test the use of getCallerPrincipal from within the ejbCreate
+ */
+ public void testCreateCaller() throws Exception
+ {
+ log.debug("+++ testCreateCaller");
+ login();
+ InitialContext jndiContext = new InitialContext();
+ Object obj = jndiContext.lookup("spec.SecureCreateSession");
+ obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
+ StatelessSessionHome home = (StatelessSessionHome) obj;
+ System.out.println("Found StatelessSessionHome");
+ for(int i = 0; i < 1000; i ++)
+ {
+ StatelessSession bean = home.create();
+ bean.remove();
+ }
+ logout();
+ }
+
+
/** Login as user scott using the conf.name login config or
'spec-test' if conf.name is not defined.
*/
@@ -346,10 +364,10 @@
lc = null;
String confName = System.getProperty("conf.name", "spec-test");
AppCallbackHandler handler = new AppCallbackHandler(username, password);
- getLog().debug("Creating LoginContext("+confName+")");
+ log.debug("Creating LoginContext("+confName+")");
lc = new LoginContext(confName, handler);
lc.login();
- getLog().debug("Created LoginContext, subject="+lc.getSubject());
+ log.debug("Created LoginContext, subject="+lc.getSubject());
loggedIn = true;
}
private void logout() throws Exception
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development