spring - Spring Boot 项目上的 LDAP 和 SSO 身份验证
问题描述
我目前正在开发一个新项目(来自 scracth),该项目从带有 Spring Security 的 Spring Boot 开始。
我需要在同一个 REST API 上实现两种身份验证方式。首先是 SSO 身份验证和 LDAP 身份验证,用户通过单击将身份验证请求传输到 API 的 Web 应用程序上的复选框来进行选择。
我的问题是:我怎样才能做到这一点?我已经实现了 LDAP 身份验证或 SSO 身份验证,但从来没有在同一个项目中实现,我没有找到任何文档
问候
解决方案
似乎您需要实现自己的AuthenticationProvider
. 请参见下面的代码:
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
if (shouldAuthenticateAgainstThirdPartySystem()) {
// use the credentials
// and authenticate against the third-party system
return new UsernamePasswordAuthenticationToken(
name, password, new ArrayList<>());
} else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(
UsernamePasswordAuthenticationToken.class);
}
}
代码来自:http ://www.baeldung.com/spring-security-authentication-provider
shouldAuthenticateAgainstThirdPartySystem
您可以检查请求(https://stackoverflow.com/a/26323545/878361 )并决定使用 ldap 或 sso。
推荐阅读
- mysql - 实体框架创建仅拉入最后一条记录的左外连接
- firebase - IllegalArgumentException:不支持的值:使用 twitter 登录时为 null
- c++ - 在 C++ 中访问虚拟类
- css - 如何缩放方形 CSS 网格以尊重父级宽度和高度
- python - Python中JSON的选择性展平
- powershell - PowerShell 脚本来配置没有密码用户的 Windows 服务
- java - 使用 Spring Cloud 优雅地关闭/停止 RabbitMQ 消费者
- django - 升级到最新版本后,默认 Django Rest Framework HTML POST 表单不显示
- solr - 通过 SOLR 使用 Tesseract 支持 OCR
- r - 由于 rstan 编译问题,travis 构建失败