1 22 package org.jboss.ejb3.test.security; 23 24 import java.rmi.RemoteException ; 25 import java.security.Principal ; 26 import javax.ejb.EJB ; 27 import javax.ejb.EJBs ; 28 import javax.annotation.Resource; 29 import javax.annotation.security.RolesAllowed; 30 import javax.ejb.Remote ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.Stateless ; 33 import javax.naming.InitialContext ; 34 import javax.naming.NamingException ; 35 import org.jboss.annotation.ejb.RemoteBinding; 36 import org.jboss.annotation.security.SecurityDomain; 37 import org.jboss.ejb3.Container; 38 39 43 @Stateless (name="PublicSessionFacade") 44 @Remote (org.jboss.ejb3.test.security.SessionFacade.class) 45 @RemoteBinding(jndiBinding = "spec.PublicSessionFacade") 46 @SecurityDomain("spec-test") 47 @RolesAllowed({"Echo"}) 48 @EJBs ({@EJB (name="TargetEJB", beanInterface=org.jboss.ejb3.test.security.Session.class, beanName="PublicSession")}) 49 public class PublicSessionFacade 50 { 51 @Resource SessionContext sessionContext; 52 53 public String callEcho(String arg) 54 throws RemoteException 55 { 56 Principal user = sessionContext.getCallerPrincipal(); 57 String echoMsg = null; 58 try 59 { 60 InitialContext ctx = new InitialContext (); 61 Session bean = (Session) ctx.lookup(Container.ENC_CTX_NAME + "/env/TargetEJB"); 62 echoMsg = bean.echo("Hello, arg="+arg); 63 echoMsg = bean.echo("Hello 2, arg="+arg); 64 } 65 catch (NamingException e) 66 { 67 throw new RemoteException ("callEcho failed", e); 68 } 69 70 return echoMsg; 71 } 72 } 73 | Popular Tags |