Granting rights through authorization
If authentication is the way to define who can access a particular resource, authorization is the way to define what a user can and cannot do once they have access to the domain.
It's like allowing someone to get into your house, but denying them access to the remote control for your TV (very important access, by the way). Or, allowing access to the remote control, but denying access to adult channels.
One way to do it is through profiles, and that's what we are going to do in this recipe.
Getting ready
Let's start by adding the dependency:
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>8.0</version> <scope>provided</scope> </dependency>
How to do it...
- 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...