Using Spring interceptors

Spring interceptors can be used to process any request before it reaches the controller. These could be used, for example, to implement security features (authentication and authorization). Like request mappers, interceptors can also be declared for specific URL patterns. Let's add the login page to our application, which should be displayed before any other page in the application if the user has not already logged in.

We will first create UserDTO in the packt.jee.course_management.dto package. This class contains the username, password, and any message to be displayed on the login page, for example, authentication errors:

public class UserDTO { private String userName; private String password; private String message; ...

Get Java EE 8 Development with Eclipse 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.