From: Scott S. <sco...@jb...> - 2005-05-31 21:47:28
|
User: starksm Date: 05/05/31 17:47:05 Modified: src/main/org/jboss/test/security/ejb CallerBean.java Added: src/main/org/jboss/test/security/ejb CallerFacadeBean.java FacadeTargetBean.java Log: Additional run-as propagation/interaction tests Revision Changes Path 1.6 +45 -29 jbosstest/src/main/org/jboss/test/security/ejb/CallerBean.java (In the diff below, changes in quantity of whitespace are not shown.) Index: CallerBean.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/security/ejb/CallerBean.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- CallerBean.java 21 Feb 2005 02:15:34 -0000 1.5 +++ CallerBean.java 31 May 2005 21:47:05 -0000 1.6 @@ -1,5 +1,5 @@ /* - * JBoss, the OpenSource WebOS + * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. @@ -23,10 +23,10 @@ import org.jboss.test.security.interfaces.CalledSessionLocalHome; import org.jboss.test.security.interfaces.CalledSessionLocal; -/** A simple session bean that calls the CalleeBean - - @author Sco...@jb... - @version $Revision: 1.5 $ +/** + * A simple session bean that calls the CalleeBean + * @author Sco...@jb... + * @version $Revision: 1.6 $ */ public class CallerBean implements SessionBean { @@ -58,20 +58,21 @@ sessionContext = context; } - /** This method calls echo on a StatelessSessionLocal and asserts that - * the caller is in the EchoCaller role. + /** + * This method calls echo on a StatelessSessionLocal and asserts that the + * caller is in the EchoCaller role. */ public String invokeEcho(String arg) { - log.debug("echo, arg="+arg); + log.debug("echo, arg=" + arg); Principal p = sessionContext.getCallerPrincipal(); - log.debug("echo, callerPrincipal="+p); + log.debug("echo, callerPrincipal=" + p); boolean isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); - log.debug("echo, isCallerInRole('EchoCaller')="+isEchoCaller); + log.debug("echo, isCallerInRole('EchoCaller')=" + isEchoCaller); boolean isInternalRole = sessionContext.isCallerInRole("InternalRole"); - log.debug("echo, isCallerInRole('InternalRole')="+isInternalRole); + log.debug("echo, isCallerInRole('InternalRole')=" + isInternalRole); - if( isEchoCaller == false && isInternalRole == false ) + if (isEchoCaller == false && isInternalRole == false) throw new SecurityException("isEchoCaller == false && isInternalRole == false"); try { @@ -82,17 +83,30 @@ StatelessSessionLocalHome.class); StatelessSessionLocal localBean = localHome.create(); String echo2 = localBean.echo(arg); - log.debug("echo, callee.echo="+echo2); + log.debug("echo#1, callee.echo=" + echo2); + echo2 = localBean.echo(arg); + log.debug("echo#2, callee.echo=" + echo2); } - catch(Exception e) + catch (Exception e) { log.error("Failed to invoke Callee.echo", e); throw new EJBException("Failed to invoke Callee.echo", e); } + + isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); + log.debug("echo, isCallerInRole#2('EchoCaller')=" + isEchoCaller); + isInternalRole = sessionContext.isCallerInRole("InternalRole"); + log.debug("echo, isCallerInRole#2('InternalRole')=" + isInternalRole); + + if (isEchoCaller == false && isInternalRole == false) + throw new SecurityException("isEchoCaller == false && isInternalRole == false post calls"); + return arg; } - /** This method should call invokeEcho on another CalledSession */ + /** + * This method should call invokeEcho on another CalledSession + */ public void callEcho() { try @@ -103,17 +117,20 @@ CalledSessionHome home = (CalledSessionHome) PortableRemoteObject.narrow(ref, CalledSessionHome.class); CalledSession bean = home.create(); - String echo2 = bean.invokeEcho("Level1"); - log.debug("echo, callee.invokeEcho="+echo2); + String echo = bean.invokeEcho("Level1"); + log.debug("echo, callee.invokeEcho=" + echo); } - catch(Exception e) + catch (Exception e) { log.error("Failed to invoke Callee.invokeEcho", e); throw new EJBException("Failed to invoke Callee.invokeEcho", e); } } - /** This method should call invokeEcho on a CalledSession */ + + /** + * This method should call invokeEcho on a CalledSession + */ public String callLocalEcho(String arg) { try @@ -124,16 +141,15 @@ CalledSessionLocalHome home = (CalledSessionLocalHome) PortableRemoteObject.narrow(ref, CalledSessionLocalHome.class); CalledSessionLocal bean = home.create(); - String echo2 = bean.invokeEcho(arg+"Level1"); - log.debug("echo, callee.invokeEcho="+echo2); + String echo2 = bean.invokeEcho(arg + "Level1"); + log.debug("echo, callee.invokeEcho=" + echo2); return echo2; } - catch(Exception e) + catch (Exception e) { log.error("Failed to invoke Callee.invokeEcho", e); throw new EJBException("Failed to invoke Callee.invokeEcho", e); } - } public void noop() 1.1 date: 2005/05/31 21:47:05; author: starksm; state: Exp;jbosstest/src/main/org/jboss/test/security/ejb/CallerFacadeBean.java Index: CallerFacadeBean.java =================================================================== /* * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.security.ejb; import java.security.Principal; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import org.apache.log4j.Category; import org.jboss.test.security.interfaces.CalledSessionLocalHome; import org.jboss.test.security.interfaces.CalledSessionLocal; /** * A simple session bean that calls the CalleeBean * @author Sco...@jb... * @version $Revision: 1.1 $ */ public class CallerFacadeBean implements SessionBean { private static Category log = Category.getInstance(CallerFacadeBean.class); private SessionContext sessionContext; public void ejbCreate() throws CreateException { log.debug("ejbCreate() called"); } public void ejbActivate() { log.debug("ejbActivate() called"); } public void ejbPassivate() { log.debug("ejbPassivate() called"); } public void ejbRemove() { log.debug("ejbRemove() called"); } public void setSessionContext(SessionContext context) { sessionContext = context; } /** * This method calls echo on a StatelessSessionLocal and asserts that the * caller is in the EchoCaller role. */ public String invokeEcho(String arg) { log.debug("echo, arg=" + arg); Principal p = sessionContext.getCallerPrincipal(); log.debug("echo, callerPrincipal=" + p); boolean isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); log.debug("echo, isCallerInRole('EchoCaller')=" + isEchoCaller); boolean isInternalRole = sessionContext.isCallerInRole("InternalRole"); log.debug("echo, isCallerInRole('InternalRole')=" + isInternalRole); try { InitialContext ic = new InitialContext(); Context enc = (Context) ic.lookup("java:comp/env"); Object ref = enc.lookup("ejb/CalledSessionLocalHome"); CalledSessionLocalHome home = (CalledSessionLocalHome) PortableRemoteObject.narrow(ref, CalledSessionLocalHome.class); CalledSessionLocal localBean = home.create(); String echo2 = localBean.invokeEcho(arg); log.debug("echo#1, callee.invokeEcho=" + echo2); echo2 = localBean.invokeEcho(arg); log.debug("echo#2, callee.invokeEcho=" + echo2); } catch (Exception e) { log.error("Failed to invoke CalledSession.invokeEcho", e); throw new EJBException("Failed to invoke Callee.echo", e); } return arg; } /** * This method should call invokeEcho on another CalledSession */ public void callEcho() { try { InitialContext ic = new InitialContext(); Context enc = (Context) ic.lookup("java:comp/env"); Object ref = enc.lookup("ejb/CalledSessionLocalHome"); CalledSessionLocalHome home = (CalledSessionLocalHome) PortableRemoteObject.narrow(ref, CalledSessionLocalHome.class); CalledSessionLocal bean = home.create(); bean.callLocalEcho("callEcho#2"); log.debug("echo, callee.callLocalEcho#1"); bean.callLocalEcho("callEcho#2"); log.debug("echo, callee.callLocalEcho#2"); } catch (Exception e) { log.error("Failed to invoke Callee.invokeEcho", e); throw new EJBException("Failed to invoke Callee.invokeEcho", e); } } public void noop() { log.debug("noop"); } } 1.1 date: 2005/05/31 21:47:05; author: starksm; state: Exp;jbosstest/src/main/org/jboss/test/security/ejb/FacadeTargetBean.java Index: FacadeTargetBean.java =================================================================== /* * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.security.ejb; import java.security.Principal; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import org.apache.log4j.Category; import org.jboss.test.security.interfaces.StatelessSessionLocal; import org.jboss.test.security.interfaces.StatelessSessionLocalHome; /** * A simple session bean that calls the CalleeBean * @author Sco...@jb... * @version $Revision: 1.1 $ */ public class FacadeTargetBean implements SessionBean { private static Category log = Category.getInstance(FacadeTargetBean.class); private SessionContext sessionContext; public void ejbCreate() throws CreateException { log.debug("ejbCreate() called"); } public void ejbActivate() { log.debug("ejbActivate() called"); } public void ejbPassivate() { log.debug("ejbPassivate() called"); } public void ejbRemove() { log.debug("ejbRemove() called"); } public void setSessionContext(SessionContext context) { sessionContext = context; } /** * This method calls echo on a StatelessSessionLocal and asserts that the * caller is in the EchoCaller role. */ public String invokeEcho(String arg) { log.debug("echo, arg=" + arg); Principal p = sessionContext.getCallerPrincipal(); log.debug("echo, callerPrincipal=" + p); boolean isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); log.debug("echo, isCallerInRole('EchoCaller')=" + isEchoCaller); if (isEchoCaller == false) throw new SecurityException("isEchoCaller == false"); try { InitialContext ic = new InitialContext(); Context enc = (Context) ic.lookup("java:comp/env"); Object ref = enc.lookup("ejb/local/StatelessSessionLocalHome"); StatelessSessionLocalHome localHome = (StatelessSessionLocalHome) PortableRemoteObject.narrow(ref, StatelessSessionLocalHome.class); StatelessSessionLocal localBean = localHome.create(); String echo2 = localBean.echo(arg); log.debug("echo#1, callee.echo=" + echo2); echo2 = localBean.echo(arg); log.debug("echo#2, callee.echo=" + echo2); } catch (Exception e) { log.error("Failed to invoke Callee.echo", e); throw new EJBException("Failed to invoke Callee.echo", e); } isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); log.debug("echo, post calls isCallerInRole('EchoCaller')=" + isEchoCaller); if (isEchoCaller == false) throw new SecurityException("isEchoCaller == false post calls"); return arg; } /** * Unused */ public String callLocalEcho(String arg) { return arg; } } |