저는 스프링 보안에 익숙하지 않아 REST 서비스를 보호하기 위해 인증 시스템을 설정해야합니다.스프링 보안을 사용하여 동적으로 IP 주소를 구성하는 방법은 무엇입니까?
내 경우에는 "사용자"가 다른 부서와 회사의 일부 서버입니다. 그래서 UserDetails의 하위 클래스 인 MyUser로 서버를 설정하려고했습니다.
하지만 서버의 IP 주소를 승인하도록 요청 받았을 때 문제가 발생했습니다. WebSecurityConfigurerAdapter.configure (HttpSecurity http)에 IP 주소 권한이 있다는 것을 알았고 configure (AuthenticationManagerBuilder auth) {auth.userDetailsService (myUserDetailsService);}를 사용하여 구성을 검색 할 수 있습니다. 그러나 configure (HttpSecurity http) 메소드는 시스템이 부팅 될 때 한 번만 실행되는 것 같습니다.
그럼 어떻게해야합니까? IP 주소를 확인하기 위해 사용자 정의 검사기 또는 무언가를 추가 할 수있는 방법이 있습니까?
이이 내 코드입니다 :public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.httpBasic().and()
.authorizeRequests()
.antMatchers("/order/**").hasAuthority("read_order") //(1)
.antMatchers("/order/**").hasIpAddress("192.168.1.45") //(2)
.anyRequest().denyAll();
// @formatter:on
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService);
}
}
사용자 정의 userService
으로 UserDetailsService
를 구현, 나는 데이터베이스의 구성으로 (1) 라인을 교체 할 수 있습니다. 즉, 구성을 변경하면 스프링 보안이 데이터베이스에서로드합니다. 시스템을 다시 시작할 필요가 없습니다.
어떻게하면 (2) 줄과 비슷한 작업을 수행 할 수 있습니까?