2

I'm currently working on a new project (from scracth) started with Spring Boot with Spring Security.

I need to implements two way of authentication on the same 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.

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

Regards

GIldasftw
  • 51
  • 4

1 Answers1

1

seems like you need to implement your own 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

in shouldAuthenticateAgainstThirdPartySystem you can check the request (https://stackoverflow.com/a/26323545/878361) and decide to use ldap or sso.

destan
  • 4,301
  • 3
  • 35
  • 62