Skip to content

Instantly share code, notes, and snippets.

@rajj6
Last active February 6, 2021 16:16
Show Gist options
  • Save rajj6/606700ac67205c9e5fe1bf9bb8a9c667 to your computer and use it in GitHub Desktop.
Save rajj6/606700ac67205c9e5fe1bf9bb8a9c667 to your computer and use it in GitHub Desktop.
package com.raj.controller;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
@org.springframework.stereotype.Controller
public class Controller {
@GetMapping("/home")
public String showHome() {
return "home";
}
@GetMapping("/hello")
public String showGreetings() {
return "hello";
}
@GetMapping("/login")
public String showLoginPage() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication instanceof AnonymousAuthenticationToken) {
return "login";
}
return "redirect:/home";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment