Securing REST Services with Spring Security
All the services we have created up until now are unsecured. A consumer does not need to provide any credentials to access these services. However, all services in the real world are usually secured.
In this section, we will discuss two ways of authenticating REST services:
Basic authentication
OAuth 2.0 authentication
We will implement these two types of authentication with Spring Security.
Spring Boot provides a starter for Spring Security using spring-boot-starter-security
. We will start with adding Spring Security starter to our pom.xml
file.
Adding Spring Security Starter
Add the following dependency to your file pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
The Spring-boot-starter-security
dependency brings in three important Spring Security dependencies:
spring-security-config
spring-security-core
spring...