Securing your REST API with basic authentication

To be able to authenticate and authorize users, we will add basic authentication implementation. By default, Spring will handle /login as a web page and that is something we don't want for our REST API. Create a new class inside the security package and call it WebSecurityEntryPoint.

This class must implement the AuthenticationEntryPoint interface whose purpose is to commence an authentication scheme. The implementation will look like this:

package com.journaler.api.security import org.springframework.security.core.AuthenticationException import org.springframework.security.web.AuthenticationEntryPoint import org.springframework.stereotype.Component import javax.servlet.http.HttpServletRequest ...

Get Building Applications with Spring 5 and Kotlin 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.