-
Notifications
You must be signed in to change notification settings - Fork 0
Epic/sec test #89
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
Merged
Merged
Epic/sec test #89
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
4e9f284
Fix cors
strug 5ee0e47
Fix cors
strug ca988c8
Fix cors
strug 53ec0d0
Fix cors
strug c2cad39
Fix cors
strug 22edc4a
Fix cors
strug 97230e2
Fix cors
strug 3d5109f
Fix tests
strug be832ef
After review
strug 3127732
Merge remote-tracking branch 'origin/master' into ft/up-libs
strug e7b0713
Fix security
strug 24752b8
Fix secure
strug 60a9f7e
Fix secure
strug ce93aa1
Fix secure
strug ad64ef9
Fix secure
strug a1ebb99
Fix secure
strug 44abc46
Merge remote-tracking branch 'origin/master' into ft/security
strug d2f2ca5
Fix secure
strug 176ab3c
Fix secure
strug 9ca6cc2
Fix secure
strug 5e6d907
Fix secure
strug 740c5f6
Fix secure
strug 615ac95
Fix secure
strug 9d3bb1b
Fix secure
strug ba28add
Fix secure
strug c3d0dac
Fix secure
strug 37708eb
Fix secure
strug f76cef5
Fix secure
strug 7a7abbf
Fix secure
strug 04e4212
Fix sec
strug 2d4268d
Merge
strug ec319ef
Merge remote-tracking branch 'origin/master' into epic/sec-test
strug 36ea011
Bump libs
strug 467eba9
Bump libs
strug 2aefce2
Bump libs
strug 37b2d97
Bump libs
strug fcffd30
Bump libs
strug e1c896d
Bump libs
strug 72c38ec
Bump libs
strug 0a9d7dd
Bump libs
strug d9f636d
Bump libs
strug 65725d2
Bump libs
strug 58760b2
Bump libs
strug 6ea9b8f
Bump libs
strug 5be5907
Bump libs
strug ea29b58
Bump libs
strug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ on: | |
| push: | ||
| branches: | ||
| - 'master' | ||
| - 'ft/up-woody' | ||
| - 'epic/*' | ||
|
|
||
| jobs: | ||
| build-and-deploy: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/vality/fraudbusters/management/config/converter/JwtAuthConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package dev.vality.fraudbusters.management.config.converter; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.core.convert.converter.Converter; | ||
| import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
| import org.springframework.security.core.GrantedAuthority; | ||
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| import org.springframework.security.oauth2.jwt.Jwt; | ||
| import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationToken> { | ||
|
|
||
| private static final String principleAttribute = "preferred_username"; | ||
| private static final String resourceAttribute = "resource_access"; | ||
|
|
||
| @Override | ||
| public AbstractAuthenticationToken convert(Jwt jwt) { | ||
| return new JwtAuthenticationToken( | ||
| jwt, | ||
| new HashSet<>(extractResourceRoles(jwt)), | ||
| getPrincipleClaimName(jwt) | ||
| ); | ||
| } | ||
|
|
||
| private Collection<? extends GrantedAuthority> extractResourceRoles(Jwt token) { | ||
| if (token.getClaim(resourceAttribute) == null) { | ||
| return Set.of(); | ||
| } | ||
| Map<String, Object> resourceAccess = token.getClaim(resourceAttribute); | ||
| if (resourceAccess.isEmpty()) { | ||
| return Set.of(); | ||
| } | ||
|
|
||
| return resourceAccess.values().stream() | ||
| .map(resourceAccessInfo -> (Map<String, Object>) resourceAccessInfo) | ||
| .flatMap(resourceAccessInfo -> ((Collection<String>) resourceAccessInfo.get("roles")).stream()) | ||
| .map(SimpleGrantedAuthority::new) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| private String getPrincipleClaimName(Jwt jwt) { | ||
| return jwt.getClaim(principleAttribute); | ||
| } | ||
| } |
21 changes: 10 additions & 11 deletions
21
src/main/java/dev/vality/fraudbusters/management/utils/UserInfoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,27 @@ | ||
| package dev.vality.fraudbusters.management.utils; | ||
|
|
||
| import dev.vality.fraudbusters.management.config.converter.JwtAuthConverter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| import java.security.Principal; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserInfoService { | ||
|
|
||
| private final JwtAuthConverter jwtAuthConverter; | ||
|
|
||
| public static final String UNKNOWN = "UNKNOWN"; | ||
|
|
||
| public String getUserName() { | ||
| var authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| log.info("authentication: {}", authentication); | ||
| if (authentication == null || authentication.getPrincipal() == null) { | ||
| return UNKNOWN; | ||
| } | ||
| return ((Principal) authentication.getPrincipal()).getName(); | ||
| } | ||
|
|
||
| public String getUserName(Principal principal) { | ||
| if (principal == null || !StringUtils.hasText(principal.getName())) { | ||
| return UNKNOWN; | ||
| } | ||
| return principal.getName(); | ||
| return jwtAuthConverter.convert((org.springframework.security.oauth2.jwt.Jwt) authentication.getPrincipal()) | ||
| .getName(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.