相关疑难解决方法(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万
查看次数

如何在spring-security,spring mvc中调用target-url之前重定向到登录/注销时的方法

我试图在登录成功后记录登录的当前时间(在方法或对象中),并在注销时将LastLogin时间分配给当前登录时间.我使用spring security登录,注销.但是我不知道在进入target-URL之前如何控制方法.

SPRING-SECURITY.XML -

<security:form-login login-page="/login"  login-processing-url="/home/currentTime" authentication-failure-url="/login?error=true" default-target-url="/home"/>

<security:logout invalidate-session="true"
            logout-success-url="/home/copyLastloginToCurrentLoginTime" logout-url="/logout" />
Run Code Online (Sandbox Code Playgroud)

控制器 - /home -

 @RequestMapping(value = "/currentTime", method = RequestMethod.GET)
        public void recordCurrentLoginTime(Model model) { //code to record current time }

    @RequestMapping(value = "/copyLastloginToCurrentLoginTime", method = RequestMethod.GET)
    public void changeLastLoginTime(Model model) {//code to copy current to last time }
Run Code Online (Sandbox Code Playgroud)

问题 - 我得到错误404 - project-title/j_spring_security_check URL.当我尝试调试时,它根本不会进入控制器方法.我应该为此目的使用一些过滤器或其他东西吗?

我见过SpringSecurity:总是将登录用户重定向到页面以及如何使用Spring Security/Spring MVC处理表单登录.但无法实现我的目标.

我是春天安全的新手,我需要一些帮助才能朝着正确的方向前进.

  • 谢谢

spring-mvc spring-security

16
推荐指数
1
解决办法
2万
查看次数

Spring MVC 3.0基本身份验证实现

我正在使用ASP.NET中的Spring MVC框架将我的Web应用程序转换为Java(虽然可以学习它的好方法 - :))我需要在我的应用程序中实现身份验证:请告诉我,如果我的方法是好的和专业的,如果不是,最好的做法是什么:

首先,我正在写User class,其中包含有关当前用户firstname/lastname/email/id/etc的所有信息....

class User implements Serializable{
private String firstName;
private String lastName;
private Long id;
private String email;

///Settters and Getters

}
Run Code Online (Sandbox Code Playgroud)

我正在实现名为DlSession的类并在sesison级别上实现它.

<bean id="MySession" class="DlSession" scope="session">
<aop:scoped-proxy/>

class DlSession implements Serializable{
private User currentUser;

public DlSession(){}

// getters and setters:
}
Run Code Online (Sandbox Code Playgroud)

当用户提交他的用户/通行证时,我正在验证凭证,以及用户是否存在将所有用户数据检索到User类的实例.然后我将Session中的currentUser设置为我检索到的用户:

mySesison.setCurrentUser(user);
Run Code Online (Sandbox Code Playgroud)

为了验证身份验证,我需要检查:

if (mySession.getcurrentUser() == null)
//return unauthenticated 
else 
//return authenticated
Run Code Online (Sandbox Code Playgroud)

要从系统注销用户,我只是这样做:

mySession.setcurrentUser(null);
Run Code Online (Sandbox Code Playgroud)

这种方法是否正确?任何建议都受到欢迎.:)

java authentication spring-mvc spring-security java-ee

3
推荐指数
1
解决办法
1万
查看次数