I have several UserDetailsService - one for users of a mobile application with a jdbc-based implementation and LdapUserDetailsService for internal users. I'm trying to build SSO and I'm missing a component that would work with multiple UserDetailsService, for example:

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UsernameNotFoundException ex = null;
        UserDetails userDetails = null;

        for (UserDetailsService service : services) {
            try {
                userDetails = service.loadUserByUsername(username);
            } catch (UsernameNotFoundException exception) {
                ex = exception;
            }
        }
        if (userDetails != null) {
            return userDetails;
        }
        throw ex;
    }

Comment From: marcusdacoregio

Hi, @CrazyParanoid. I don't feel like this is generic enough to have a place in the framework. I say this because I see a few use cases that may vary the implementation, like:

  • What if the username exists in more than one UserDetailsService?
  • How do we know if we chose the right UserDetails?

Given those use cases and more, it is very likely that we won't get the implementation right. Since the implementation is relatively simple, it is better for users to implement it by themselves to make sure they achieve all their business needs.

I'm closing this as denied but if we get more upvotes on this we can always reopen it.