How to do it...

Follow these steps to complete this recipe:

  1. First, let's define our roles list:
public class Roles {    public static final String ADMIN = "admin";    public static final String USER = "user";}
  1. Now, let's define a list of tasks to be completed based on the role:
@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");    }}
  1. Now, let's implement the IndentityStore interface. Here, we define our policy so that we can validate the user's identity:
@ApplicationScoped ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.