@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public int add(int x, int y) { return x + y; }
The javax.annotation.security.RolesAllowed and javax.annotation.security.PermitAll are the EJB 3.0 security annotations. You can attach a MethodPermission to any method and define which roles are allowed to invoke on that method. The javax.ejb.RunAs annotation can also be applied at the class level. There is also an additional JBoss specific annotation that you must supply at the class level. org.jboss.ejb3.security.SecurityDomain. The SecurityDomain specifies the JAAS repository which will be used by JBoss to authenticate and authorize. See the JBoss Application Server documentation for more details. In this particular example, the "other" domain is used. The "other" domain corresponds to a users.properties and roles.properties files that contain cleartext user, password, and user/role associations. If you open the built tutorial.jar file you will see these two files in there.
Unix: $ export JBOSS_HOME=<where your jboss 4.0 distribution is> Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is> $ ant $ ant run run: [java] Kabir is a student. [java] Kabir types in the wrong password [java] 2004-10-07 15:32:50,916 INFO org.jboss.remoting.InvokerRegistry[main] - Failed to load soap remoting transpo rt: org/apache/axis/AxisFault [java] Authentication exception, principal=kabir [java] Kabir types in correct password. [java] Kabir does unchecked addition. [java] 1 + 1 = 2 [java] Kabir is not a teacher so he cannot do division [java] Insufficient method permissions, principal=kabir, interface=org.jboss.ejb3.EJBContainerInvocation, requiredR oles=[teacher], principalRoles=[student] [java] Students are allowed to do subtraction [java] 1 - 1 = 0
The INFO message you can ignore. It will be fixed in later releases of JBoss 4.0.