1 22 package org.jboss.ejb3.test.security; 23 24 import java.security.Principal ; 25 import javax.ejb.CreateException ; 26 import javax.ejb.Local ; 27 import javax.ejb.Remote ; 28 import javax.ejb.SessionContext ; 29 import javax.ejb.Stateless ; 30 31 import javax.annotation.Resource; 32 import javax.annotation.security.RunAs; 33 34 import org.jboss.logging.Logger; 35 import org.jboss.annotation.ejb.LocalBinding; 36 import org.jboss.annotation.ejb.RemoteBinding; 37 import org.jboss.annotation.security.SecurityDomain; 38 39 import javax.annotation.security.RolesAllowed; 40 41 47 @Stateless (name="CalleeBean") 48 @Local (org.jboss.ejb3.test.security.StatelessSessionLocal.class) 49 @Remote (org.jboss.ejb3.test.security.StatelessSessionLocal.class) 50 @LocalBinding(jndiBinding = "spec.CalleeBean") 51 @RemoteBinding(jndiBinding = "spec.CalleeBeanRemote") 52 @SecurityDomain("spec-test") 53 public class CalleeBean 54 { 55 private static Logger log = Logger.getLogger(CalleeBean.class); 56 57 @Resource SessionContext sessionContext; 58 59 @RolesAllowed({"Echo"}) 60 public String echo(String arg) 61 { 62 log.info("------------ CalleeBean.echo"); 63 log.info("echo, arg="+arg); 64 Principal p = sessionContext.getCallerPrincipal(); 65 log.info("echo, callerPrincipal="+p); 66 boolean isCaller = sessionContext.isCallerInRole("Echo"); 67 log.info("echo, isCallerInRole('Echo')="+isCaller); 68 isCaller = sessionContext.isCallerInRole("InternalRole"); 69 log.info("echo, isCallerInRole('InternalRole')="+isCaller); 70 71 log.info("------------ CalleeBean.echo done"); 72 return arg; 73 } 74 75 public void noop() 76 { 77 log.info("noop"); 78 } 79 } 80 | Popular Tags |