相关疑难解决方法(0)

配置Spring Security 3.x以具有多个入口点

我一直在使用Spring Security 3.x来处理我的项目的用户身份验证,到目前为止,它已经完美运行.

我最近收到了一个新项目的要求.在此项目中,它需要两组用户身份验证:一组用于根据LDAP对员工进行身份验证,另一组用于根据数据库对客户进行身份验证.我对如何在Spring Security中配置它感到有点困惑.

我最初的想法是创建一个具有以下字段的登录屏幕: -

  • 单选按钮字段 - 供用户选择是员工还是客户.
  • j_username 用户字段.
  • j_password 密码字段.

如果用户选择"employee",那么我希望Spring Security针对LDAP对其进行身份验证,否则将根据数据库对凭据进行身份验证.但是,问题是表单将被提交,/j_spring_security_check并且我无法将单选按钮字段发送到我实现的自定义身份验证提供程序.我最初的想法是,我可能需要两个表单提交URL,而不是依赖于默认值/j_spring_security_check.每个URL都将由不同的身份验证提供程序处理,但我不确定如何在Spring Security中配置它.

我知道在Spring Security中,我可以配置后备身份验证,例如,如果LDAP身份验证失败,那么它将回退到数据库身份验证,但这不是我在这个新项目中拍摄的内容.

有人可以分享我应该如何在Spring Security 3.x中配置它?

谢谢.


更新 - 01-28-2011 - @ EasyAngel的技术

我正在尝试执行以下操作: -

  • 员工表单登录提交 /j_spring_security_check_for_employee
  • 客户表单登录提交 /j_spring_security_check_for_customer

我想要2种不同的表单登录的原因是允许我根据用户不同地处理身份验证,而不是进行后备身份验证.在我的情况下,员工和客户可能拥有相同的用户ID.

我合并了@ EasyAngel的想法,但必须更换一些已弃用的类.我目前面临的问题是没有过滤进程URLS似乎在Spring Security中注册,因为我不断获取Error 404: SRVE0190E: File not found: /j_spring_security_check_for_employee.我的直觉是springSecurityFilterChainbean没有正确连接,因此根本不使用我的自定义过滤器.

顺便说一下,我正在使用WebSphere,我确实com.ibm.ws.webcontainer.invokefilterscompatibility=true在服务器中设置了属性.我可以/j_spring_security_check毫无问题地达到默认值.

这是我完整的安全配置: -

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

    <sec:http auto-config="true">
        <sec:form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1" default-target-url="/welcome.jsp"
            always-use-default-target="true" />
        <sec:logout …
Run Code Online (Sandbox Code Playgroud)

java authentication spring forms-authentication spring-security

64
推荐指数
2
解决办法
6万
查看次数