Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20230403
Commits
6b7c45f0
Commit
6b7c45f0
authored
Apr 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WhoAmI
parent
5929b9fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
WhoAmI.java
PC30-SklepSpring/src/main/java/sklep/security/WhoAmI.java
+19
-0
whoami.jsp
...-SklepSpring/src/main/webapp/WEB-INF/templates/whoami.jsp
+28
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/security/WhoAmI.java
0 → 100644
View file @
6b7c45f0
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"
;
}
}
PC30-SklepSpring/src/main/webapp/WEB-INF/templates/whoami.jsp
0 → 100644
View file @
6b7c45f0
<
%@
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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment