你无需创建
/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>
- 在中
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);}
支持重写
supports
方法。EmployeeCustomAuthenticationProviderUsernamePasswordAuthenticationToken
支持重写
supports
方法。CustomerCustomAuthenticationProviderCustomerAuthenticationToken
@Overridepublic boolean supports(Class<?> authentication) { return (CustomerAuthenticationToken.class.isAssignableFrom(authentication));}
- 在
authentication-manager
以下两个提供商中使用:
<security:authentication-manager alias="authenticationManager"> <security:authentication-provider ref='employeeCustomAuthenticationProvider ' /> <security:authentication-provider ref='customerCustomAuthenticationProvider ' /></security:authentication-manager>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)