java如何使用Spring Security更改登录的弹出行为?
在我的应用程序中,我使用安全性。如下所示的xml:
<security:http pattern="/services/upload" security="none" />
<security:http auto-config='true' create-session="stateless" entry-point-ref="digestEntryPoint">
<security:intercept-url pattern="/admin.html"
access="ROLE_ADMIN" />
<security:intercept-url pattern="/services/projects/**"
access="ROLE_ADMIN" />
<security:http-basic />
<security:custom-filter ref="digestFilter" after="BASIC_AUTH_FILTER" />
</security:http>
<bean id="digestFilter"
class="org.springframework.security.web.authentication.www.DigestAuthenticationFilter">
<property name="userDetailsService" ref="userService" />
<property name="authenticationEntryPoint" ref="digestEntryPoint" />
</bean>
<bean id="digestEntryPoint"
class="org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint">
<property name="realmName"
value="Admin Tab via Digest Authentication" />
<property name="key" value="acegi" />
</bean>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service id="userService">
<security:user name="xx" password="xx"
authorities="ROLE_ADMIN" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
当我点击索引上的管理选项卡时。html浏览器弹出其(不受我控制)表单,输入登录名和密码。当我点击这个按钮上的取消,我得到401错误页面。当我输入错误凭据时,弹出窗口将重置,并且不会通知我有关凭据的信息。我想要达到的是只停留在索引上。当用户单击“取消”时显示html,并在用户输入错误凭据时显示一些信息。我尝试了许多解决方案,但都没有找到任何解决方案。有可能吗
# 1 楼答案
原因是您使用的是BasicAuth,这意味着您必须通过编码Base64在请求头中发送凭据。因此,浏览器会识别并向您询问凭据。如果你想改变这一点,你必须使用状态完整的场景。然后,您可以拥有用户可以登录的自定义登录页面
但是对于上面的RESTAPI配置是正确的,我们不想控制登录,因为它是基本身份验证。有关更多详细信息,请查看此http://malalanayake.wordpress.com/2014/06/30/stateless-spring-security-on-rest-api/