Exemplo n.º 1
0
  /**
   * Perform user login
   *
   * @param principal
   */
  protected void setupSecurityContext(String principal) {
    logger.entry(principal);
    UsernamePasswordAuthenticationToken preauth =
        new UsernamePasswordAuthenticationToken(principal, "password");
    Authentication auth = authMgr.authenticate(preauth);
    SecurityContextHolder.getContext().setAuthentication(auth);

    logger.info(auth.toString());
    logger.exit();
  }
  @RequestMapping(
      value = {"/index"},
      method = RequestMethod.GET)
  public String homeSetUp(Model model) {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    String nameUser = authentication.getName();
    String toString = authentication.toString();
    Collection<? extends GrantedAuthority> GrantedAuthorities = authentication.getAuthorities();

    model.addAttribute("GrantedAuthorities", GrantedAuthorities);
    model.addAttribute("username", nameUser);
    model.addAttribute("toString", toString);

    return "index";
  }