Implementing Spring Boot security
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.
Securing microservices with basic security
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>
Open Application.java
and add @EnableGlobalMethodSecurity
to the Application
class. This annotation will enable method-level security:
@EnableGlobalMethodSecurity @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
The default basic authentication assumes the user as being user
. The default password...