繁体   English   中英

Spring Security AuthenticationProvider-扩展身份验证

[英]Spring Security AuthenticationProvider - extends Authentication

我们为应用程序提供了自定义类型的用户,因此我们不想使用

@Override
public Authentication authenticate(Authentication authentication) {
    String name = authentication.getName();

在我们的

public EmployeeAuthenticationProvider implements AuthenticationProvider {

但是,因为我们有不同的传入POST参数名称,例如

@Override
public Authentication authenticate(Authentication authentication) {
    String employeeName = authentication.getEmployeeName();
    String employeePassword = authentication.getEmployeePassword();

因为我们正在为应用程序的用户使用一个名为Employee的自定义bean。

是否可以扩展身份验证并将其替换为authenticate方法? 我们的EmployeeServiceImplementation也应该实现org.spring.security.core.Authentication还是应该在我们的Employee bean中实现(这会令人沮丧)? 我对如何解决此问题有些困惑。

谢谢你的帮助。

编辑

根据这个很棒的POST Spring,我现在在SecurityContextHolder中获得了自定义UserDetails

class EmployeeUserDetailsService implements UserDetailsService {

class EmployeeUserDetails extends Employee implements UserDetails, Authentication{

现在我上课了

class EmployeeAuthenticationProvider implements AuthenticationProvider {

我想改变方法

 org.springframework.security.authentication.AuthenticationProvider#authenticate(Authentication authentication)

所以我可以使用EmployeeUserDetails代替Authentication

您不能更改方法签名,但是可以在从authenticate方法返回的Authentication对象中设置EmployeeUserDetails。 您可以使用Authentication对象的setDetails方法执行此操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM