春天安全我是新手.我拿起这本书并尝试执行代码.
虽然我这样做,但我得到了
org.springframework.beans.NotReadablePropertyException: Invalid property
'principal.username' of bean class
[org.springframework.security.authentication.AnonymousAuthenticationToken]:
Bean property 'principal.username' is not readable or has an invalid getter
method:
Does the return type of the getter match the parameter type of the setter?
Run Code Online (Sandbox Code Playgroud)
我的spring-security xml配置:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login.do" access="permitAll"/>
<intercept-url pattern="/*" access="hasRole('ROLE_USER')"/>
<form-login login-page="/login.do"/>
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<user-service id="userService">
<user authorities="ROLE_USER" name="guest" password="guest"/>
</user-service>
</authentication-provider>
<!-- Ch 3 Change Password Service -->
<!--
<authentication-provider user-service-ref="userService"/>
-->
</authentication-manager>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
如果您需要任何其他信息,请与我们联系.
Ste*_*n C 10
错误消息似乎表明是某些东西试图访问一个不存在的属性AnonymousAuthenticationToken; 即spring会话未登录时使用的身份验证令牌.
我怀疑问题实际上发生在你的servlet代码中,或者是在试图通过spring安全标记访问当前用户名的JSP中.
错误的完整堆栈跟踪可能会给我们提供更多线索.至少它应该告诉我们异常的来源.
(对于它的价值,a AnonymousAuthenticationToken确实有一个principal属性,但该属性通常不是具有username属性的对象.实际上,它通常只是一个String.)
小智 8
我正在阅读/关注"Spring Security 3"一书.只需将以下行添加到header.jsp问题是如果您未登录,则principal.username不存在.
<div class="username">
Welcome,
<sec:authorize access="isAuthenticated()">
<strong><sec:authentication property="principal.username"/></strong>
</sec:authorize>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10912 次 |
| 最近记录: |