How to do it...

Follow these steps to complete this recipe:

  1. First, let's create a list of roles for our application:
public class Roles {    public static final String ADMIN = "admin";    public static final String USER = "user";}
  1. Now, we need to create a list of tasks that can be performed by only one of the roles – one task that everyone can do and another task that no one can do:
@Statefulpublic class UserBean {        @RolesAllowed({Roles.ADMIN})    public void adminOperation(){        System.out.println("adminOperation executed");    }        @RolesAllowed({Roles.USER})    public void userOperation(){        System.out.println("userOperation executed");    }    @PermitAll    public void everyoneCanDo(){        System.out.println("everyoneCanDo executed");    }    @DenyAll public void noneCanDo(){ ...

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.