Securing access to the discovery server
Previously, we learned how to protect external communication with HTTPS. Now we will use HTTP Basic authentication to restrict access to the APIs and web pages on the discovery server, Netflix Eureka. This means that we will require a user to supply a username and password to get access. Changes are required both on the Eureka server and in the Eureka clients, described as follows.
Changes in the Eureka server
To protect the Eureka server, the following changes have been applied in the source code:
- In
build.gradle
, a dependency has been added for Spring Security:
implementation 'org.springframework.boot:spring-boot-starter-security'
- Security configuration has been added to the
SecurityConfig
class:- The user is defined as follows:
@Bean
public InMemoryUserDetailsManager userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder()
.username(username)
.password(password)
.roles("USER"...