-1
我一個應用程序,我需要訪問POST數據JSON
工作。我的代碼是無法訪問POST數據Spring Security的自定義過濾器
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.web.filter.GenericFilterBean;
public class LoginFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
System.out.println("filtered /login request: " + servletRequest.getParameter("idToken"));
filterChain.doFilter(servletRequest, servletResponse);
}
}
當我運行日誌
2017-05-06 06:23:31.153 INFO 89727 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 2 ms
filtered /login request: null
我缺少的是應用
$ curl -v -X POST -H "Content-Type: application/json" -d '{"idToken" : "[email protected]#[email protected]#23434W$"}' http://localhost:8080/login
我得到null
?
'ServletRequest.getParameter(...)'只檢索請求參數。你可能要(用傑克遜爲例)身體自己 – Riiverside
除此之外解碼,你爲什麼要創建用於處理登錄一個過濾器?一個普通的端點將更適合這個imo。 – Riiverside
@Riiverside,在春季,安全性幾乎總是通過過濾器進行處理。包括登錄和註銷。 – hooknc