Commit 750bd50d by Patryk Czarnik

stronka "who am i?"

parent 18616b5e
......@@ -2,6 +2,7 @@ package sklep.controller;
import java.time.LocalDateTime;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -26,5 +27,14 @@ public class RootController {
model.addAttribute("dt", now);
return "pokaz_czas";
}
@GetMapping("/whoami")
public String whoAmI(Authentication authentication, Model model) {
if(authentication != null && authentication.isAuthenticated()) {
model.addAttribute("userName", authentication.getName());
model.addAttribute("authorities", authentication.getAuthorities());
}
return "whoami";
}
}
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="jakarta.tags.core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<c:choose>
<c:when test="${not empty userName}">
<p>Jesteś zalogowany jako <strong>${userName}</strong>.</p>
<p>Twoje uprawnienia (<i>authorities</i>):</p>
<ul>
<c:forEach var="auth" items="${authorities}">
<li>${auth}</li>
</c:forEach>
</ul>
</c:when>
<c:otherwise>
<p>Nie jesteś zalogowany.</p>
</c:otherwise>
</c:choose>
<div><a href="/">Powrót do spisu treści</a></div>
<div><a href="/logout">Wyloguj się</a></div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment