Implementing security
It is important to secure the microservices. This will be more significant when there are many microservices communicating with each other. Each service needs to be secured, but at the same time, security shouldn't surface as an overhead. In this section, we will learn some basic measures to secure microservices.
Note
The full source code of this example is available as the chapter3.security
project in the code files of this book under the following Git repository:https://github.com/rajeshrv/Spring5Microservice
Perform the following steps for building this example:
- Create a new Spring Starter project, and select
Web
andSecurity
(under core) - Name the project as
chapter3.security
- Copy rest endpoint from
chapter3.bootrest
Securing a microservice with basic security
Adding basic authentication to Spring Boot is pretty simple. The pom.xml
file will have the following dependency. This will include the necessary Spring security library files:
<dependency> <groupId...