Миграция на Spring Boot 2 из 1.5.7 - Метод запроса POST не поддерживается - csrf уже отключен
Мы перенесли наше программное обеспечение с весенней загрузки 1.5.7 на весеннюю загрузку 2. Мы используем JSF, включив joinfaces-parent в наш pom.xml.
При запуске все работает отлично, но вход в систему не работает:
Request method 'POST' not supported
Это, вероятно, проблема безопасности Spring? CSRF уже отключен.
Вот наш файл SecurityConfig:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) {
try {
http.csrf().disable().authorizeRequests()
.antMatchers("/javax.faces.resource/**", Page.LOGIN.getUrlForSecurityContext())
.permitAll()
.and()
........
// *** login configuration
.formLogin()
.loginPage(Page.LOGIN.getUrlForSecurityContext()).permitAll()
.failureUrl(Page.LOGIN.getUrlForSecurityContext() + "?error=true")
.usernameParameter("username")
.passwordParameter("password")
.successHandler(authenticationSuccessHandler)
.and()
...........
// @formatter:on
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
.......
}
Запрос на вход в систему не поступает на наш сервер. Я обнаружил, что эта ошибка генерируется из dispatcher.forward
функция, вызываемая из xhtml. Здесь функция:
public void login() throws ServletException, IOException {
final ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
final RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/login");
dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
}
Здесь больше журналов, когда сообщение об ошибке происходит:
[io.undertow.servlet] (default task-3) Initializing Spring FrameworkServlet 'dispatcherServlet'
16:02:20,926 INFO [org.springframework.web.servlet.DispatcherServlet] (default task-3) FrameworkServlet 'dispatcherServlet': initialization started
16:02:20,938 INFO [org.springframework.web.servlet.DispatcherServlet] (default task-3) FrameworkServlet 'dispatcherServlet': initialization completed in 12 ms
16:02:20,949 WARN [org.springframework.web.servlet.PageNotFound] (default task-3) Request method 'POST' not supported
16:02:20,973 ERROR [org.springframework.boot.web.servlet.support.ErrorPageFilter] (default task-3) Cannot forward to error page for request [/login] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
Спасибо за совет!
1 ответ
Конфигурация Spring Security выглядит нормально для меня. Что-то не так с вашим контроллером входа в систему. Я полагаю, ваш login
метод вызывается в ответ на запрос POST от клиента. Затем он пытается переслать этот POST для отображения страницы входа и, наконец, выдает исключение. Очевидно, это должен быть запрос GET вместо POST.