Using declarative security
When building your application's security features, you can basically use two approaches: programmatic security and declarative security:
- The programmatic approach is when you define the security policy of your application using code.
- The declarative approach is when you do it by declaring the policies and then applying them accordingly.
This recipe will show you the declarative approach.
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...
- 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"; }
- Then we create a list of tasks that could be performed by only one of the roles, one task that everyone...