• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

There was an unexpected error (type=Forbidden, status=403). Access Denied 에러

22.06.12 15:55 작성 조회수 657

0

http://localhost:8000/user-service/welcome 으로 가면 There was an unexpected error (type=Forbidden, status=403).

Access Denied
 
오류가 나옵니다. 
 
WebSecurity 코드에 configure 메소드
@Override
protected void configure(HttpSecurity http) throws Exception { // <- 권한
http.csrf().disable();
// http.authorizeHttpRequests().antMatchers("/users/**").permitAll();
http.authorizeRequests().antMatchers("/error/**").permitAll()
.antMatchers("/**")
.access("hasIpAddress('" + "192.168.0.2" + "')") // IP_ADDRESS="x.x.x.x"
.and()
.addFilter(getAuthenticationFilter()); // 이 필터 통과한 데이터만
http.headers().frameOptions().disable();
}

192.168.0.2:포트번호/welcome 으로가면 정상적으로 나오는데 api gateway를 거쳐가면 항상 access denied가 됩니다.

 

스프링 버전은 2.7 사용중입니다

답변 3

·

답변을 작성해보세요.

0

안녕하세요, 이도워입니다. 

답변이 늦어 죄송합니다. api-gateway가 Servuce Discovery(Eureka)에 등록될 때, IP를 지정하지 않았는지 확인해 보시기 바랍니다. 

eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
# prefer-ip-address: true
# ip-address: ${server.address}

위의 속성에서처럼 ip-address가 지정되어 있다면, 주석처리 후에 다시 실행해 보시기 바랍니다. 

감사합니다.

0

조진수님의 프로필

조진수

질문자

2022.06.13

디버그로 확인해보니 api gateway service 를 통해서 갈때 (8000/user-service) 로 갈때 유저서비스에 요청들어온 ip 가 127.0.0.1 로 되어있던데 api gateway 서비스를 통해 갈때 ip가 왜 로컬일까요?? 다른분들은 사설 ip (192.168.x.x) 처럼 되는것 같던데

0

조진수님의 프로필

조진수

질문자

2022.06.12

WebSecurity 의 configure 에서 hasIpAddress를 192.168.0.2 가 아닌 127.0.0.1 로 하면 access denied가 되지 않습니다. 강사님 영상에서는 127.0.0.1 로 하지 않으셨는데 혹시 왜 이런 오류가 나오는지 아시나요?