【发布时间】:2012-08-15 12:26:00
【问题描述】:
我正在开发网站(HTML、javascript、jQuery、Ajax、css),我在服务器端使用 spring 中的基本身份验证。 我在 HTTP 请求的授权标头中发送 Basic="Base64 Endcoded Username & password"。 登录在正确的用户名和密码上工作正常。 但是在失败时,它会显示一个默认提示,让我输入用户名和密码。 我该怎么做才能不显示提示,而是应该得到一个错误代码。 这样,我就可以显示正确的失败消息。
春季安全
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<http create-session="never">
<intercept-url pattern="/rest/user*" access="ROLE_USER" />
<logout logout-success-url="/index.jsp" invalidate-session="true" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="md5"/>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select UserName as username, Password as user_password,true
from User where username=?"
authorities-by-username-query="
select UserName as username,'ROLE_USER' from User where username=?"
/>
</authentication-provider>
</authentication-manager>
【问题讨论】:
-
你在xml文件中使用了
标签吗?在日志中您是否收到身份验证失败错误?
标签: javascript jquery html spring-security basic-authentication