How to do it...

Follow these steps to complete this recipe:

  1. First, we will 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";}
  1. Then, we need to 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(){ ...

Get Jakarta EE Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.