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");
 }
 public List<String> getRolesForUser(final String username)
     throws UsernameNotFoundException, DataAccessException {
   UserDetails user = userDetailsService.loadUserByUsername(username);
   List<String> roles = new ArrayList<String>(user.getAuthorities().length);
   for (GrantedAuthority role : user.getAuthorities()) {
     roles.add(role.getAuthority());
   }
   return roles;
 }
  /**
   * 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;
  }
Example #4
0
 /** Sólo las clases hijas pueden crear instancias de esta clase. */
 protected Trace() {
   final UserDetails userDetails = SecurityUtils.getAuthenticatedUser();
   who = userDetails == null ? "unknown" : userDetails.getUsername();
 }
Example #5
0
 private void getUserAuthorityInfo() {
   GrantedAuthority[] authorities = userDetails.getAuthorities();
   userAuthority = authorities;
 }