1 22 package org.jboss.ejb3.test.security; 23 24 import java.security.Principal ; 25 26 import javax.annotation.Resource; 27 import javax.annotation.security.RolesAllowed; 28 import javax.ejb.Remote ; 29 import javax.ejb.SessionContext ; 30 import javax.ejb.Stateless ; 31 32 import org.jboss.annotation.ejb.RemoteBinding; 33 import org.jboss.annotation.security.SecurityDomain; 34 35 41 @Stateless (name="PrivateSession") 42 @Remote (org.jboss.ejb3.test.security.Session.class) 43 @RemoteBinding(jndiBinding = "spec.PrivateSession") 44 @SecurityDomain("spec-test") 45 @RolesAllowed({"InternalUser"}) 46 public class PrivateSessionBean 47 { 48 @Resource SessionContext sessionContext; 49 50 public String echo(String arg) 51 { 52 System.out.println("PrivateSessionBean.echo, arg="+arg); 53 Principal p = sessionContext.getCallerPrincipal(); 54 System.out.println("PrivateSessionBean.echo, callerPrincipal="+p); 55 System.out.println("PrivateSessionBean.echo, isCallerInRole('InternalUser')="+sessionContext.isCallerInRole("InternalUser")); 56 return arg; 57 } 58 public void noop() 59 { 60 System.out.println("PrivateSessionBean.noop"); 61 Principal p = sessionContext.getCallerPrincipal(); 62 System.out.println("PrivateSessionBean.noop, callerPrincipal="+p); 63 } 64 public void restricted() 65 { 66 System.out.println("PrivateSessionBean.restricted"); 67 Principal p = sessionContext.getCallerPrincipal(); 68 System.out.println("PrivateSessionBean.restricted, callerPrincipal="+p); 69 } 70 } 71 | Popular Tags |