Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
bdc16fb8
Commit
bdc16fb8
authored
Jul 30, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dodanie security
parent
59a375fb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
pom.xml
PC27-SklepSpring/pom.xml
+4
-0
RootController.java
...Spring/src/main/java/sklep/controller/RootController.java
+10
-0
whoami.jsp
...-SklepSpring/src/main/webapp/WEB-INF/templates/whoami.jsp
+28
-0
No files found.
PC27-SklepSpring/pom.xml
View file @
bdc16fb8
...
...
@@ -46,6 +46,10 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<!-- Dodatkowe zależności, aby używać JSP w Springu -->
<dependency>
...
...
PC27-SklepSpring/src/main/java/sklep/controller/RootController.java
View file @
bdc16fb8
package
sklep
.
controller
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -27,4 +28,13 @@ public class RootController {
return
"show_time"
;
}
@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"
;
}
}
PC27-SklepSpring/src/main/webapp/WEB-INF/templates/whoami.jsp
0 → 100644
View file @
bdc16fb8
<
%@
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>
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