-
Notifications
You must be signed in to change notification settings - Fork 0
Fix JWT token Cast + Handle Custom admin role in CsmAdmin verification #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import com.nimbusds.jwt.JWTParser | |
| import org.springframework.security.core.Authentication | ||
| import org.springframework.security.core.context.SecurityContextHolder | ||
| import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication | ||
| import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken | ||
|
|
||
| fun getCurrentAuthentication(): Authentication? = SecurityContextHolder.getContext().authentication | ||
|
|
||
|
|
@@ -23,17 +24,31 @@ fun getCurrentAuthenticatedIssuer(): String { | |
| throw IllegalStateException("User Authentication not found in Security Context") | ||
| } | ||
|
|
||
| val authentication = getCurrentAuthentication() as BearerTokenAuthentication | ||
| return authentication.token.tokenValue.let { JWTParser.parse(it).jwtClaimsSet.issuer } | ||
| val authentication = getCurrentAuthentication() | ||
|
|
||
| if (authentication is JwtAuthenticationToken) { | ||
| return authentication.token.tokenValue.let { JWTParser.parse(it).jwtClaimsSet.issuer } | ||
| } | ||
|
|
||
| return (authentication as BearerTokenAuthentication).token.tokenValue.let { | ||
| JWTParser.parse(it).jwtClaimsSet.issuer | ||
| } | ||
| } | ||
|
|
||
| fun getCurrentAuthenticatedMail(configuration: CsmPlatformProperties): String { | ||
| if (getCurrentAuthentication() == null) { | ||
| throw IllegalStateException("User Authentication not found in Security Context") | ||
| } | ||
|
|
||
| val authentication = getCurrentAuthentication() as BearerTokenAuthentication | ||
| return authentication.token.tokenValue.let { | ||
| val authentication = getCurrentAuthentication() | ||
|
|
||
| if (authentication is JwtAuthenticationToken) { | ||
| return authentication.token.tokenValue.let { | ||
| JWTParser.parse(it).jwtClaimsSet.getStringClaim(configuration.authorization.mailJwtClaim) | ||
| } | ||
| } | ||
|
|
||
| return (authentication as BearerTokenAuthentication).token.tokenValue.let { | ||
| JWTParser.parse(it).jwtClaimsSet.getStringClaim(configuration.authorization.mailJwtClaim) | ||
| } | ||
| } | ||
|
|
@@ -43,8 +58,15 @@ fun getCurrentAuthenticatedRoles(configuration: CsmPlatformProperties): List<Str | |
| throw IllegalStateException("User Authentication not found in Security Context") | ||
| } | ||
|
|
||
| val authentication = getCurrentAuthentication() as BearerTokenAuthentication | ||
| return authentication.token.tokenValue.let { | ||
| val authentication = getCurrentAuthentication() | ||
|
|
||
| if (authentication is JwtAuthenticationToken) { | ||
| return authentication.token.tokenValue.let { | ||
| JWTParser.parse(it).jwtClaimsSet.getStringListClaim(configuration.authorization.rolesJwtClaim) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same, like before, line 2 times:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will change it (certainly) use |
||
| } | ||
| } | ||
|
|
||
| return (authentication as BearerTokenAuthentication).token.tokenValue.let { | ||
| JWTParser.parse(it).jwtClaimsSet.getStringListClaim(configuration.authorization.rolesJwtClaim) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is present 2 times :
JWTParser.parse(it).jwtClaimsSet.getStringClaim(configuration.authorization.mailJwtClaim)To refactor? Maybe with
whenThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will change it (certainly) use
whensyntax when we'll integrate Keycloak as identity provider ;)