繁体   English   中英

无法获得Spring安全性以进行BASIC身份验证

[英]Can't get Spring security to work BASIC authentication

我正在尝试添加Spring安全性,但无法使其正常工作。 但是,我本以为这会导致浏览器弹出一个对话框,询问用户名和密码,但是什么也没显示。 它只是带给我正常的页面,而无需执行任何安全性。 使用Spring 3.1:

web.xml

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

context.xml

<security:http>
    <security:http-basic />
    <security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>

<security:authentication-manager>
    <security:authentication-provider>
        <security:user-service>
            <security:user name="test" password="testpass" authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>
</security:authentication-manager>

您还需要这样的东西

 <security:form-login login-page='/Login' authentication-failure-url="/Login?login_error=1"/>

并且您需要创建自己的登录页面,该页面至少包含此登录页面,并映射到上述url(显然与我的不一定相同):

<form name="f" id="f" action="<c:url value='/j_spring_security_check'/>" method="POST">
  <label for="j_username">Username :&nbsp;</label>
  <input type='text' id='j_username' name='j_username'/><br/>
  <label for="j_password">Password :&nbsp;</label>
  <input type='password' id='j_password' name='j_password'><br>

您需要在web.xml中添加spring安全性上下文,以便Web应用程序可以正确加载context.xml。

这是一个关于如何使用Spring Security甚至进行一些自定义的基本身份验证的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM