在 Spring 安全 4 中获取 HttpServletRequest、HttpServletResponse
Get HttpServletRequest, HttpServletResponse in Spring Security 4
我试过注入 HttpRequest、HttpResponse。
尝试过
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
@Controller("/test")
public class Test {
public String callback() {
SecurityContextHolder.getContext().setAuthentication(auth);
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = attributes.getRequest();
HttpServletResponse response = attributes.getResponse();
}
}
没什么,我总是收到一个空对象。
这是Spring的方法:
@Controller("/test")
public class Test {
public String callback(HttpServletRequest request,HttpServletResponse response) {
...
}
}
我试过注入 HttpRequest、HttpResponse。
尝试过
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
@Controller("/test")
public class Test {
public String callback() {
SecurityContextHolder.getContext().setAuthentication(auth);
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = attributes.getRequest();
HttpServletResponse response = attributes.getResponse();
}
}
没什么,我总是收到一个空对象。
这是Spring的方法:
@Controller("/test")
public class Test {
public String callback(HttpServletRequest request,HttpServletResponse response) {
...
}
}