It is important to secure microservices. In this section, some basic measures to secure Spring Boot microservices will be reviewed using
chapter2.bootrest to demonstrate the security features.
Adding basic authentication to Spring Boot is pretty simple. Add the following dependency to
pom.xml. This will include the necessary Spring security library files:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
Application.java and add
@EnableGlobalMethodSecurity to the
Application class. This annotation will enable method-level security:
@EnableGlobalMethodSecurity @SpringBootApplication public class ...