我对 Spring Security 非常陌生。我捡起来了this https://rads.stackoverflow.com/amzn/click/com/1847199747书并尝试执行代码。
当我这样做时,我得到了
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?
我的 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>
我错过了什么吗?
如果您需要任何其他信息,请告诉我。
错误消息似乎表明某些东西正在尝试访问某个不存在的属性AnonymousAuthenticationToken
;即会话未登录时 Spring Security 使用的身份验证令牌。
我怀疑问题实际上发生在您的 servlet 代码中,或者发生在尝试通过 spring 安全标记访问当前用户的名称的 JSP 中。
错误的完整堆栈跟踪可能会给我们更多线索。至少它应该告诉我们异常来自哪里。
(就其价值而言,AnonymousAuthenticationToken
确实有一个principal
属性,但该属性通常不是具有username
财产。事实上,它通常只是一个字符串。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)