- 유레카 기본은 peer1 active

- 이벤트, 회원 서비스에 OAuth2 권한 재설정 (편의를 위해 모두 호출 가능하도록)
This commit is contained in:
assu10
2020-11-01 21:47:43 +09:00
parent 1c4a15599a
commit 66e067ea44
4 changed files with 21 additions and 83 deletions

View File

@@ -1,78 +1,3 @@
spring:
application:
name: eurekaserver-peer1 # 서비스 ID (컨피그 클라이언트가 어떤 서비스를 조회하는지 매핑)
profiles: peer1
server:
port: 8762 # 유레카 서버가 수신 대기할 포트
your.name: "EUREKA peer-1"
#spring:
# rabbitmq:
# host: localhost
# port: 5672
# username: guest
# password: '{cipher}17b3128621cb4e71fbb5a85ef726b44951b62fac541e1de6c2728c6e9d3594ec'
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
eureka:
instance:
hostname: peer1
metadataMap:
instanceId: peer1_${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true # 유레카 서비스에 (자신을) 등록하지 않는다. (클러스터 모드가 아니므로)
fetch-registry: true # 레지스트리 정보를 로컬에 캐싱하지 않는다. (클러스터 모드가 아니므로)
serviceUrl:
dafaultZone: http://peer2:8763/eureka/,http://peer1:8762/eureka/
#server:
#wait-time-in-ms-when-sync-empty: 5 # 서버가 요청을 받기 전 대기할 초기 시간 (5ms, 운영 환경에선 삭제 필요)
# 일시적인 네트워크 장애로 인한 서비스 해제 막기 위한 보호모드 해제 (디폴트 60초, 운영에선 삭제 필요)
# 원래는 해당 시간안에 하트비트가 일정 횟수 이상 들어오지 않아야 서비스 해제하는데 false 설정 시 하트비트 들어오지 않으면 바로 서비스 제거
#enable-self-preservation: false
logging:
level:
com.netflix: WARN
org.springframework.web: WARN
com.assu.cloud: DEBUG
#server:
# port: 8761 # 유레카 서버가 수신 대기할 포트
#
#your.name: "EUREKA DEFAULT"
##spring:
## rabbitmq:
## host: localhost
## port: 5672
## username: guest
## password: '{cipher}17b3128621cb4e71fbb5a85ef726b44951b62fac541e1de6c2728c6e9d3594ec'
#management:
# endpoints:
# web:
# exposure:
# include: "*"
# endpoint:
# shutdown:
# enabled: true
#eureka:
# client:
# register-with-eureka: false # 유레카 서비스에 (자신을) 등록하지 않는다. (클러스터 모드가 아니므로)
# fetch-registry: false # 레지스트리 정보를 로컬에 캐싱하지 않는다. (클러스터 모드가 아니므로)
# service-url:
# # dafaultZone: http://peer2:8762/eureka/
# dafaultZone: http://localhost:8761/eureka/
# server:
# wait-time-in-ms-when-sync-empty: 5 # 서버가 요청을 받기 전 대기할 초기 시간 (5ms, 운영 환경에선 삭제 필요)
# # 일시적인 네트워크 장애로 인한 서비스 해제 막기 위한 보호모드 해제 (디폴트 60초, 운영에선 삭제 필요)
# # 원래는 해당 시간안에 하트비트가 일정 횟수 이상 들어오지 않아야 서비스 해제하는데 false 설정 시 하트비트 들어오지 않으면 바로 서비스 제거
# enable-self-preservation: false
#logging:
# level:
# com.netflix: WARN
# org.springframework.web: WARN
# com.assu.cloud: DEBUG
profiles:
active: peer1

View File

@@ -24,10 +24,16 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
// 회원 서비스의 모든 URL 에 대해 인증된 사용자만 접근하도록 제한
//http.authorizeRequests().anyRequest().authenticated();
http.authorizeRequests()
// 편의성을 위해 주석 처리
/*http.authorizeRequests()
.antMatchers(HttpMethod.PUT, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.hasRole("ADMIN") // ADMIN 권한을 가진 사용자만 PUT 호출 가능
.anyRequest() // 서비스의 모든 엔드포인트도 인증된 사용자만 접근 가능하도록 설정
.authenticated();
.authenticated();*/
// 편의성을 위해 DELETE 메서드만 인증된 사용자가 호출가능하도록 수정
http.authorizeRequests()
.antMatchers(HttpMethod.DELETE, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.hasRole("ADMIN"); // ADMIN 권한을 가진 사용자만 PUT 호출 가능
}
}

View File

@@ -17,7 +17,7 @@ public class EventRestTemplateClient {
this.customConfig = customConfig;
}
String URL_PREFIX = "/api/evt/event/"; // 이벤트 서비스의 주울 라우팅경로와 이벤트 클래스 주소
String ZUUL_URL_PREFIX = "/api/evt/event/"; // 이벤트 서비스의 주울 라우팅경로와 이벤트 클래스 주소
public String gift(String name) {
/*ResponseEntity<EventGift> restExchange =
@@ -28,7 +28,7 @@ public class EventRestTemplateClient {
);*/
ResponseEntity<String> restExchange =
restTemplate.exchange(
"http://" + customConfig.getServiceIdZuul() + URL_PREFIX + "gift/{name}", // http://localhost:5555/api/mb/member/gift/flower
"http://" + customConfig.getServiceIdZuul() + ZUUL_URL_PREFIX + "gift/{name}", // http://localhost:5555/api/mb/member/gift/flower
HttpMethod.GET,
null, String.class, name
);

View File

@@ -24,11 +24,18 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
// 회원 서비스의 모든 URL 에 대해 인증된 사용자만 접근하도록 제한
//http.authorizeRequests().anyRequest().authenticated();
http.authorizeRequests()
// 편의성을 위해 주석 처리
/*http.authorizeRequests()
//.antMatchers(HttpMethod.PUT, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.antMatchers(HttpMethod.DELETE, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.hasRole("ADMIN") // ADMIN 권한을 가진 사용자만 PUT 호출 가능
.anyRequest() // 서비스의 모든 엔드포인트도 인증된 사용자만 접근 가능하도록 설정
.authenticated();
.authenticated();*/
// 편의성을 위해 DELETE 메서드만 인증된 사용자가 호출가능하도록 수정
http.authorizeRequests()
//.antMatchers(HttpMethod.PUT, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.antMatchers(HttpMethod.DELETE, "/member/**") // 쉼표로 구분하여 엔드 포인트 목록 받음
.hasRole("ADMIN"); // ADMIN 권한을 가진 사용자만 PUT 호출 가능
}
}