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);
.....