栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

你无需创建

/j_spring_security_check_for_employee
/j_security_check_for_customer filterProcessingUrl

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

在定制登录中

LoginFilter
,你需要为员工和客户创建不同的令牌。

步骤如下:

  1. 使用默认值

    UsernamePasswordAuthenticationToken
    进行员工登录。

  2. 创建

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

  3. 定义自定义登录过滤器:

<security:http>    <security:custom-filter position="FORM_LOGIN_FILTER" ref="customFormLoginFilter" /></security:http>
  1. 在中
    customFormLoginFilter
    ,请进行以下重写
    attemptAuthentication
    (伪代码):
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);}
  1. 支持重写

    supports
    方法。
    EmployeeCustomAuthenticationProviderUsernamePasswordAuthenticationToken

  2. 支持重写

    supports
    方法。
    CustomerCustomAuthenticationProviderCustomerAuthenticationToken

@Overridepublic boolean supports(Class<?> authentication) {    return (CustomerAuthenticationToken.class.isAssignableFrom(authentication));}
  1. authentication-manager
    以下两个提供商中使用:
<security:authentication-manager alias="authenticationManager">    <security:authentication-provider ref='employeeCustomAuthenticationProvider ' />    <security:authentication-provider ref='customerCustomAuthenticationProvider ' /></security:authentication-manager>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451904.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号