Spring Security AuthenticationProvider - 扩展身份验证

问题描述 投票:0回答:1

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

@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。

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

谢谢你的帮助。

编辑

根据这个伟大的POST Spring get custom UserDetails in SecurityContextHolder我现在

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

java spring spring-mvc spring-security
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.