Updating AccountController to use LdapUserDetailsService
We will now update the AccountController
object to use the LdapDetailsUserDetailsService
interface to look up the user that it displays:
//src/main/java/com/packtpub/springsecurity/web/controllers/AccountController.java @Controller public class AccountController { private final UserDetailsService userDetailsService; @Autowired public AccountController(UserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } @RequestMapping("/accounts/my") public String view(Model model) { Authentication authentication = SecurityContextHolder. getContext().getAuthentication(); // null check omitted String principalName = authentication.getName(); Object principal = userDetailsService. loadUserByUsername(principalName); ... } }
Obviously, this example is a bit silly, but it demonstrates the use of LdapUserDetailsService
....