Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PA165 Banking System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Filip Piták
PA165 Banking System
Commits
c56331e3
There was an error fetching the commit references. Please try again later.
Commit
c56331e3
authored
11 months ago
by
Filip Piták
Browse files
Options
Downloads
Patches
Plain Diff
Security filter and feign configuration
parent
26fca0ce
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/pom.xml
+1
-8
1 addition, 8 deletions
client/pom.xml
client/src/main/java/cz/muni/pa165/banking/client/controller/AuthController.java
+20
-2
20 additions, 2 deletions
.../muni/pa165/banking/client/controller/AuthController.java
infrastructure/pom.xml
+32
-1
32 additions, 1 deletion
infrastructure/pom.xml
with
53 additions
and
11 deletions
client/pom.xml
+
1
−
8
View file @
c56331e3
...
...
@@ -28,12 +28,6 @@
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-oauth2-client
</artifactId>
...
...
@@ -42,7 +36,6 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
...
...
@@ -70,8 +63,8 @@
<artifactId>
js-cookie
</artifactId>
<version>
3.0.1
</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
...
...
This diff is collapsed.
Click to expand it.
client/src/main/java/cz/muni/pa165/banking/client/controller/AuthController.java
+
20
−
2
View file @
c56331e3
...
...
@@ -2,12 +2,23 @@ package cz.muni.pa165.banking.client.controller;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.oauth2.client.OAuth2AuthorizedClient
;
import
org.springframework.security.oauth2.client.OAuth2AuthorizedClientService
;
import
org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient
;
import
org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken
;
import
org.springframework.security.oauth2.core.OAuth2AccessToken
;
import
org.springframework.security.oauth2.core.oidc.user.OidcUser
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
java.time.ZoneId
;
import
java.util.TreeSet
;
/**
* Spring MVC Controller.
* Handles HTTP requests by preparing data in model and passing it to Thymeleaf HTML templates.
...
...
@@ -17,6 +28,9 @@ public class AuthController {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AuthController
.
class
);
@Autowired
private
OAuth2AuthorizedClientService
clientService
;
/**
* Home page accessible even to non-authenticated users. Displays user personal data.
*/
...
...
@@ -26,13 +40,17 @@ public class AuthController {
log
.
debug
(
"* index() called *"
);
log
.
debug
(
"********************************************************"
);
log
.
debug
(
"user {}"
,
user
==
null
?
"is anonymous"
:
user
.
getSubject
());
model
.
addAttribute
(
"user"
,
user
);
if
(
user
!=
null
)
{
Authentication
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
OAuth2AuthenticationToken
oauthToken
=
(
OAuth2AuthenticationToken
)
authentication
;
OAuth2AuthorizedClient
client
=
clientService
.
loadAuthorizedClient
(
oauthToken
.
getAuthorizedClientRegistrationId
(),
oauthToken
.
getName
());
log
.
info
(
"BEARER: "
+
client
.
getAccessToken
().
getTokenValue
());
model
.
addAttribute
(
"issuerName"
,
"https://oidc.muni.cz/oidc/"
.
equals
(
user
.
getIssuer
().
toString
())
?
"MUNI"
:
"Google"
);
model
.
addAttribute
(
"token"
,
user
.
getId
Token
().
getTokenValue
());
model
.
addAttribute
(
"token"
,
client
.
getAccess
Token
().
getTokenValue
());
}
return
"index"
;
...
...
This diff is collapsed.
Click to expand it.
infrastructure/pom.xml
+
32
−
1
View file @
c56331e3
...
...
@@ -20,13 +20,44 @@
<maven.compiler.source>
21
</maven.compiler.source>
<maven.compiler.target>
21
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<spring-cloud.version>
2023.0.1
</spring-cloud.version>
</properties>
<!-- Only exact dependencies to eliminate transitive dependencies -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-config
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-oauth2-resource-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-starter-common
</artifactId>
<version>
2.3.0
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment