Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osiv2-postfach
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
osiv2-postfach
Commits
d67fa44b
Commit
d67fa44b
authored
5 months ago
by
Jan Zickermann
Browse files
Options
Downloads
Patches
Plain Diff
#2
Cleanup JwtParser
parent
853dc538
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2
Resolve "Bauen eines Mock Servicekonto & Mock Osi Fassade"
Pipeline
#1088
passed
5 months ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/extension/JwtParser.java
+17
-7
17 additions, 7 deletions
...cloud/nachrichten/postfach/osiv2/extension/JwtParser.java
with
17 additions
and
7 deletions
src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/extension/JwtParser.java
+
17
−
7
View file @
d67fa44b
...
...
@@ -11,17 +11,27 @@ public class JwtParser {
@SneakyThrows
public
static
ReadContext
parseBody
(
String
authorizationHeaderValue
)
{
var
jwt
=
authorizationHeaderValue
.
substring
(
"Bearer "
.
length
());
// Step 2: Split the JWT
String
[]
jwtParts
=
jwt
.
split
(
"\\."
);
var
jwtParts
=
splitIntoSignatureAndHeaderAndBody
(
discardBearerPrefix
(
authorizationHeaderValue
)
);
var
bodyPart
=
jwtParts
[
1
];
return
parseJsonPartFromUrlEncodedBase64
(
bodyPart
);
}
private
static
ReadContext
parseJsonPartFromUrlEncodedBase64
(
String
base64EncodedPayload
)
{
return
JsonPath
.
parse
(
new
String
(
base64UrlDecode
(
base64EncodedPayload
)));
}
private
static
String
discardBearerPrefix
(
String
authorizationHeaderValue
)
{
return
authorizationHeaderValue
.
substring
(
"Bearer "
.
length
());
}
private
static
String
[]
splitIntoSignatureAndHeaderAndBody
(
String
jwt
)
{
var
jwtParts
=
jwt
.
split
(
"\\."
);
if
(
jwtParts
.
length
!=
3
)
{
throw
new
IllegalArgumentException
(
"Invalid JWT token"
);
}
// Step 3: Base64Url decode the Payload part
var
payloadJson
=
base64UrlDecode
(
jwtParts
[
1
]);
return
JsonPath
.
parse
(
new
String
(
payloadJson
));
return
jwtParts
;
}
private
static
byte
[]
base64UrlDecode
(
String
input
)
{
...
...
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