Commit 87212bc3 by Patryk Czarnik

whoami

parent 5227d823
package sklep.security;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class WhoAmI {
@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="http://java.sun.com/jsp/jstl/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