1 22 package org.jboss.ejb3.test.security; 23 24 import java.security.Principal ; 25 import javax.ejb.EJB ; 26 import javax.ejb.EJBs ; 27 import javax.annotation.Resource; 28 import javax.annotation.security.RolesAllowed; 29 import javax.ejb.Remote ; 30 import javax.ejb.SessionContext ; 31 import javax.ejb.Stateless ; 32 import javax.naming.InitialContext ; 33 import org.jboss.annotation.ejb.RemoteBinding; 34 import org.jboss.annotation.security.SecurityDomain; 35 import org.jboss.ejb3.Container; 36 37 43 @Stateless (name="PublicSession") 44 @Remote (org.jboss.ejb3.test.security.Session.class) 45 @RemoteBinding(jndiBinding = "spec.PublicSession") 46 @SecurityDomain("spec-test") 47 @RolesAllowed({"Echo"}) 48 @EJBs ({@EJB (name="PrivateSession", beanInterface=org.jboss.ejb3.test.security.Session.class, beanName="PrivateSession")}) 49 public class PublicSessionBean 50 { 51 @Resource SessionContext sessionContext; 52 53 public String echo(String arg) 54 { 55 System.out.println("PublicSessionBean.echo, arg="+arg); 56 Principal p = sessionContext.getCallerPrincipal(); 57 System.out.println("PublicSessionBean.echo, callerPrincipal="+p); 58 System.out.println("PublicSessionBean.echo, isCallerInRole('EchoUser')="+sessionContext.isCallerInRole("EchoUser")); 59 try 60 { 61 InitialContext ctx = new InitialContext (); 62 Session bean = (Session) ctx.lookup(Container.ENC_CTX_NAME + "/env/PrivateSession"); 63 System.out.println("PublicSessionBean.echo, created PrivateSession"); 64 arg = bean.echo(arg); 65 } 66 catch(Exception e) 67 { 68 } 69 return arg; 70 } 71 public void noop() 72 { 73 System.out.println("PublicSessionBean.noop"); 74 Principal p = sessionContext.getCallerPrincipal(); 75 System.out.println("PublicSessionBean.noop, callerPrincipal="+p); 76 } 77 public void restricted() 78 { 79 System.out.println("PublicSessionBean.restricted"); 80 Principal p = sessionContext.getCallerPrincipal(); 81 System.out.println("PublicSessionBean.restricted, callerPrincipal="+p); 82 } 83 } 84 | Popular Tags |