java Spring Security getPrincipal() 方法返回anonymousUser
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14665886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Security getPrincipal() method returns anonymousUser
提问by Igorock
in my spring web application I want to get an authenticated user in my controller:
在我的 Spring Web 应用程序中,我想在我的控制器中获得一个经过身份验证的用户:
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
But the principal's value is "anonymousUser" although I have loged in. How can I get an authenticated user? My configurations in spring-security.xml:
但是主体的值是“anonymousUser”,尽管我已经登录。我怎样才能获得经过身份验证的用户?我在 spring-security.xml 中的配置:
<http auto-config="true" request-matcher="regex">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
采纳答案by Marcel St?r
Not sure I understand but try this
不确定我理解但试试这个
<http auto-config="true" request-matcher="regex">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<intercept-url pattern="/*" access="IS_AUTHENTICATED,IS_AUTHENTICATED_ANONYMOUSLY"/>