問題が発生するパターンのSpring Securityの設定は概ねこんな感じ。
public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter {
private static final String URL_PATTERN = "xxx";
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.regexMatcher(URL_PATTERN)
.formLogin()
.successHandler((req, res, auth) -> res.setStatus(HttpServletResponse.SC_OK))
.failureHandler((req, res, auth) -> res.setStatus(HttpServletResponse.SC_UNAUTHORIZED))
.permitAll();
http.regexMatcher(URL_PATTERN)
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint("Bearer error=\"invalid_request\""));
http.regexMatcher(URL_PATTERN).csrf().disable();
また、APIは下記のような実装を行っていた。
単一URLにPOST
HTTP Headerによって処理をルーティング