zp-fightwine/fightwine-admin/src/main/java/com/yzt/admin/manager/CusAuthenticationManager.java
2025-12-03 19:35:10 +08:00

34 lines
1.2 KiB
Java

package com.yzt.admin.manager;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderNotFoundException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 自定义认证管理器
*
*/
@Component
public class CusAuthenticationManager implements AuthenticationManager {
// private final CustomAuthenticationProvider customAuthenticationProvider = new CustomAuthenticationProvider();
private final CustomAuthenticationProvider customAuthenticationProvider;
public CusAuthenticationManager(CustomAuthenticationProvider customAuthenticationProvider) {
this.customAuthenticationProvider = customAuthenticationProvider;
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Authentication result = customAuthenticationProvider.authenticate(authentication);
if (Objects.nonNull(result)) {
return result;
}
throw new ProviderNotFoundException("Authentication failed!");
}
}