기본 인증과 OAuth2를 모두 사용하는 앱이 있습니다.내 기본 인증 구성을 통해 "/ api/**"를 스프링 보안의 oauth 구성으로 허용하는 방법
일부 인증은 기본 인증을 사용하며 "/ api/**"는 OAuth2를 사용하여 인증됩니다.
현재, 나는 두 개의 자바 설정 파일 (WebSecurityConfigurerAdapter
및 ResourceServerConfigurerAdapter
)
설정 파일의 각각은 public void configure(HttpSecurity http)
방법을 정의 할 수 있습니다.
내가 겪고있는 문제는 URL 요청을 받으면 기본 인증을 사용할지 아니면 oauth2를 사용할지 여부를 알기 쉽게 말해주는 것입니다. 나는이 일어날 수 있도록 requestMatchers
를 사용하고 현재
:
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.csrf().disable()
.requestMatchers()
.antMatchers("/*", "/login/**", "/reviews/**")
.and()
.authorizeRequests()
.antMatchers("/*").permitAll()
.antMatchers("/js/**").permitAll()
.antMatchers("/img/**").permitAll()
.formLogin()
.loginPage("/login")
.successHandler(loginSuccessPostHandler)
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/").permitAll()
.and()
.apply(getSpringSocialConfigurer());
}
}
@Configuration
public class OAuth2ServerConfig
{
@Configuration
@EnableResourceServer
protected static class Oauth2ServerConfig extends ResourceServerConfigurerAdapter
{
@Override
public void configure(HttpSecurity http) throws Exception
{
http.httpBasic().disable();
http.csrf().disable();
http.requestMatchers()
.antMatchers("/api/**")
.and()
.authorizeRequests()
.antMatchers("/api/v1/**").access("#oauth2.hasScope('read')");
}
}
}
문제는 때마다 내가 아니라 새로운 URL을 추가 할 것입니다 "/ API/**", 나는 그것을 추가해야합니다 내 WebSecurityConfig
의 requestMatcher 섹션에 ... 이것은 앞으로 바보 같은 버그가 될 수 있습니다.
negative lookahead regex에 기반한 requestMatcher 검색 방법이 있습니까? 나는이 정규식을 사용하여 시도 : ^(?!/api)
하지만 실제로 일치를 반환하지 않으며 "찾기 == 사실"을 반환하기 때문에, 그것은 일을 끝내지 않는 것 같습니다.
의견/제안?