How to do it...

  1. Let's first define our roles list:
public class Roles {    public static final String ADMIN = "admin";    public static final String USER = "user";}
  1. Then, let's define a list of tasks to be done 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 for validating the user's identity:
@ApplicationScopedpublic class UserIdentityStore implements IdentityStore ...

Get Java EE 8 Cookbook 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.