- First, we define some roles in a separate class so that we can reuse it:
public class Roles { public static final String ROLE1 = "role1"; public static final String ROLE2 = "role2"; public static final String ROLE3 = "role3";}
- Then we define some things that the application's users can do:
@Statefulpublic class UserActivity { @RolesAllowed({Roles.ROLE1}) public void role1Allowed(){ System.out.println("role1Allowed executed"); } @RolesAllowed({Roles.ROLE2}) public void role2Allowed(){ System.out.println("role2Allowed executed"); } @RolesAllowed({Roles.ROLE3}) public void role3Allowed(){ System.out.println("role3Allowed executed"); } @PermitAll public void anonymousAllowed(){ System.out.println("anonymousAllowed executed"); ...