@Override
public boolean authenticate(String username, String password) {
boolean authenticated;
try {
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(username, password));
SecurityContextHolder.getContext().setAuthentication(authentication);
//A hack to allow to track logged users without using SessionManagementFilter which is problematic in Wicket
sessionRegistry.registerNewSession(getId(), authentication.getPrincipal());
authenticated = authentication.isAuthenticated();
} catch (AuthenticationException e) {