首页 文章

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

提问于
浏览
0

我目前正在开发一个新项目(来自scracth),该项目始于Spring Boot with Spring Security .

我需要在同一个REST API上实现两种身份验证方式 . 首先是SSO身份验证和LDAP身份验证,用户可以通过单击将身份验证请求发送到API的Web应用程序上的复选框来进行选择 .

我的问题是:我怎样才能做到这一点?我已经实现了LDAP身份验证或SSO身份验证,但从来没有在同一个项目上,我没有找到任何相关的文档

问候

1 回答

  • 0

    好像你需要实现自己的 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 .

相关问题