我是Spring的新手MVC bellow是我的spring-security.xml,当我从安全上下文持有者检索用户详细信息时,它给出null。请帮助我如何解决这个问题。?
<http auto-config="true" >
<intercept-url pattern="/login*"
access="IS_AUTHENTICATED_ANONYMOUSLY,ROLE_USER"/>
<intercept-url pattern="/login.jsp*"
access="IS_AUTHENTICATED_ANONYMOUSLY,ROLE_USER"/>
<intercept-url pattern="/employee/*" access="ROLE_EMPLOYEE"/>
<intercept-url pattern="/campaign/*" access="ROLE_EMPLOYEE"/>
<intercept-url pattern="/marketing/*" access="ROLE_EMPLOYEE"/>
<intercept-url pattern="/company*" access="ROLE_USER,ROLE_ANONYMOUSLY,ROLE_USER,ROLE_EMPLOYEE"/>
<intercept-url pattern=" /j_ascend_security_check*" access="ROLE_USER,ROLE_ANONYMOUSLY,ROLE_USER,ROLE_EMPLOYEE"/>
<form-login login-page="/pages/login.jsp"
authentication-success-handler-ref="authenticationSuccessRedirectHandler"
authentication-failure-handler-ref="authenticationFailureRedirectHandler"/>
</http>
Java代码
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
System.out.println("user at sh:::"+user.getCompanyShortName()); //getting null here
问题是什么。任何人都可以帮忙吗?