public void valid_login() { Authentication auth = provider.authenticate(new UsernamePasswordAuthenticationToken("scott", "tiger")); assertNotNull(auth); UserDetails principal = (UserDetails) auth.getPrincipal(); assertEquals(principal.getClass(), SessionContext.class); assertEquals(principal.getUsername(), "scott"); }
/** * Try to get the User information from the session. * * @return represents the user currently in session */ private UserDetails getUserDetails() { UserDetails user = null; Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (null != auth) { Object obj = auth.getPrincipal(); if (obj instanceof UserDetails) { user = (UserDetails) obj; log.debug("Found username: " + user.getUsername()); } } if (null == user) { user = new NoCurrentUserDetails(); } return user; }
/** Sólo las clases hijas pueden crear instancias de esta clase. */ protected Trace() { final UserDetails userDetails = SecurityUtils.getAuthenticatedUser(); who = userDetails == null ? "unknown" : userDetails.getUsername(); }