我试图实施此question.中提供的解决方案@H_502_2@
但是,他们都没有为我工作.在我的抽象基本控制器中,我有以下方法(我也使用静态方法在helper类中尝试过,但存在相同的问题):@H_502_2@
@H_502_2@
public User getUser() {
User user =
(User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
}
即使在我的jsps中,getAuthentication()返回null,也可以正常工作:@H_502_2@
@H_502_2@
<sec:authentication property="principal.firstname" />
为什么getAuthentication返回null?@H_502_2@
另外,我尝试将Principal作为参数传递给我的特定控制器方法,这是null也会解析为null …@H_502_2@
为什么我的主体为null,但jsp仍在工作?@H_502_2@
最佳答案
确保在< intercept-url>中没有过滤器=“ none”.对于控制器的URL,它会禁用Spring Security过滤器,因此不会填充安全上下文.@H_502_2@
如果需要使每个人都可以访问控制器,请使用other approaches.