@RequestMapping("/login") public String login(){ Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if(auth instanceof AnonymousAuthenticationToken){ return "login"; }else{ return "home"; } }