Как получить параметры из POST request в CustomFilter Spring Security
Доброго времени суток дорогие друзья.
Не могу получить параметры из POST запроса, в Custom Filter для Spring Security
Вот я создаю фильтр. В фильтре мне нужно получить параметры которые приходят методом POST Но фактически я не могу их почему-то получить. Два дня назад мне случайно удалось это сделать, но сейчас это сломалось и почему то не получается заново сделать. Два дня бьюсь головой об стену и ничего не помогает.
SecurityConfig
package com.myfilter.security;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
CustomFilter newFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(newFilter, AnonymousAuthenticationFilter.class)
.authorizeRequests()
.mvcMatchers("/login", "/").permitAll()
// тут я указываю что будет использоваться метод POST
.mvcMatchers(HttpMethod.POST,"/login").permitAll()
.and()
.csrf().disable()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/")
}
}
CustomFilter
package com.myfilter.security;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@Component
public class CustomFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String email = httpServletRequest.getParameter("email");
// тут я просто вывожу в консоль
System.out.println(email);
chain.doFilter(request, response);
}
}
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sign in</title>
</head>
<body>
<form name="user" method="post" action="/login">
<input type="text" name="email">
<input type="password" name="password">
<button type="submit">Sign in</button>
</form>
</body></html>
View this project at github https://github.com/romanych2021/MyFilter