HTTP Basic Authentication
을 통해서 아이디와 비밀번호를 제공하도록 설정의존성 설정
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
프로퍼티 설정(Config Server - discoveryservice.yml)
http://localhost:8012/encrypt
를 통해서 비밀번호 암호화spring:
security:
user:
name: {username}
password: '{cipher}{encrypted_password}'
Config Server 연결(bootstrap.yml)
spring:
cloud:
config:
uri: http://localhost:8012
name: discoveryservice
ApplicationSecurityConfig 설정
@EnableWebSecurity
public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
}
Eureka URL 수정(Config Server - application.yml)
myEureka:
password: '{cipher}{encrypted_password}'
eureka:
client:
serviceUrl:
defaultZone: http://{username}:${myEureka.password}@localhost:8010/eureka