您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

你无需创建/j_spring_security_check_for_employee/j_security_check_for_customer filterProcessingUrl

认情况下,可以与单选按钮字段提示配合使用。

在定制登录LoginFilter,你需要为员工和客户创建不同的令牌。

步骤如下:

使用认值UsernamePasswordAuthenticationToken进行员工登录

创建CustomerAuthenticationToken用于客户登录。进行扩展AbstractAuthenticationToken,以使其类类型不同于UsernamePasswordAuthenticationToken

定义自定义登录过滤器:

<security:http>
    <security:custom-filter position="FORM_LOGIN_FILTER" ref="customformLoginFilter" />
</security:http>
if (radiobutton_param value employee) {
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
    setDetails(whatever);
    return getAuthenticationManager().authenticate(authRequest);
} else if (radiobutton_param value customer) {
    CustomerAuthenticationToken authRequest = new CustomerAuthenticationToken(username, password);
    setDetails(whatever);
    return getAuthenticationManager().authenticate(authRequest);
}

支持重写supports方法EmployeeCustomAuthenticationProviderUsernamePasswordAuthenticationToken

支持重写supports方法CustomerCustomAuthenticationProviderCustomerAuthenticationToken

@Override
public boolean supports(Class<?> authentication) {
    return (CustomerAuthenticationToken.class.isAssignableFrom(authentication));
}
<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref='employeeCustomAuthenticationProvider ' />
    <security:authentication-provider ref='customerCustomAuthenticationProvider ' />
</security:authentication-manager>
Java 2022/1/1 18:16:11 有584人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶