Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Boot项目上的LDAP和SSO身份验证_Spring_Spring Boot_Spring Security_Spring Security Oauth2_Spring Security Ldap - Fatal编程技术网

Spring Boot项目上的LDAP和SSO身份验证

Spring Boot项目上的LDAP和SSO身份验证,spring,spring-boot,spring-security,spring-security-oauth2,spring-security-ldap,Spring,Spring Boot,Spring Security,Spring Security Oauth2,Spring Security Ldap,我目前正在从事一个新项目(来自scracth),该项目从SpringBoot和SpringSecurity开始 我需要在同一个RESTAPI上实现两种方式的身份验证。首先是SSO身份验证和LDAP身份验证,用户通过单击将身份验证请求传输到API的web应用程序上的复选框来进行选择 我的问题是:我如何才能做到这一点?我已经在同一个项目上实现了LDAP身份验证或SSO身份验证,但从未在这两个项目上实现过,我没有找到任何关于这方面的文档 您似乎需要实现自己的身份验证提供程序。见下面的代码: @Comp

我目前正在从事一个新项目(来自scracth),该项目从SpringBoot和SpringSecurity开始

我需要在同一个RESTAPI上实现两种方式的身份验证。首先是SSO身份验证和LDAP身份验证,用户通过单击将身份验证请求传输到API的web应用程序上的复选框来进行选择

我的问题是:我如何才能做到这一点?我已经在同一个项目上实现了LDAP身份验证或SSO身份验证,但从未在这两个项目上实现过,我没有找到任何关于这方面的文档


您似乎需要实现自己的
身份验证提供程序

。见下面的代码:

@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);
}
}
@组件
公共类CustomAuthenticationProvider实现AuthenticationProvider{
@凌驾
公共身份验证(身份验证)
抛出AuthenticationException{
String name=authentication.getName();
字符串密码=authentication.getCredentials().toString();
如果(应针对第三方系统()进行身份验证){
//使用凭据
//并针对第三方系统进行身份验证
返回新的用户名PasswordAuthenticationToken(
名称、密码、新ArrayList());
}否则{
返回null;
}
}
@凌驾
公共布尔支持(类身份验证){
返回authentication.equals(
UsernamePasswordAuthenticationToken.class);
}
}
代码来自:

shouldAuthenticateAigainstThirdPartySystem
中,您可以检查请求()并决定使用ldap或sso