Last active
February 6, 2021 16:16
-
-
Save rajj6/606700ac67205c9e5fe1bf9bb8a9c667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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