简体   繁体   English

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

[英]LDAP and SSO authentication on Spring Boot project

I'm currently working on a new project (from scracth) started with Spring Boot with Spring Security. 我目前正在从Spring Security和Spring Boot开始一个新项目(从scracth开始)。

I need to implements two way of authentication on the same REST API. 我需要在同一REST API上实现两种身份验证方式。 First the SSO authentication and the LDAP authentication, the choice is made by the user by clicking a checkbox on the web application who transmit the auth request to the API. 首先是SSO身份验证和LDAP身份验证,由用户通过单击Web应用程序上的复选框将用户身份验证请求发送到API进行选择。

My question is : How can i achieve this ? 我的问题是:我该如何实现? i already implemented LDAP authentication or SSO authentication but never both on the same project, i don't found any documentation on that 我已经实现了LDAP身份验证或SSO身份验证,但从未在同一个项目中同时使用这两个方法,但是我在该文件上找不到任何文档

Regards 问候

seems like you need to implement your own AuthenticationProvider . 似乎您需要实现自己的AuthenticationProvider See code below: 参见下面的代码:

@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);
}
}

the code is from: http://www.baeldung.com/spring-security-authentication-provider 该代码来自: http : //www.baeldung.com/spring-security-authentication-provider

in shouldAuthenticateAgainstThirdPartySystem you can check the request ( https://stackoverflow.com/a/26323545/878361 ) and decide to use ldap or sso. shouldAuthenticateAgainstThirdPartySystem您可以检查请求( https://stackoverflow.com/a/26323545/878361 )并决定使用ldap或sso。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM