generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from it-at-m/jwt
Jwt instead of opaque tokens
- Loading branch information
Showing
8 changed files
with
126 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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 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
43 changes: 43 additions & 0 deletions
43
src/main/java/de/muenchen/rbs/kitafindereai/config/JwtAuthoritiesConverter.java
This file contains 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,43 @@ | ||
/* | ||
* Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik | ||
* der Landeshauptstadt München, 2024 | ||
*/ | ||
package de.muenchen.rbs.kitafindereai.config; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
|
||
/** | ||
* | ||
*/ | ||
public class JwtAuthoritiesConverter implements Converter<Jwt, Collection<GrantedAuthority>> { | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public Collection<GrantedAuthority> convert(Jwt jwt) { | ||
// lade Rollen aus folgender Struktur: | ||
// "resource_access": { | ||
// "kf-app-eai": { | ||
// "roles": [ | ||
// "lhm-ab-kf-app-eai-internal-access", | ||
// "internal-access" | ||
// ] | ||
// } | ||
// } | ||
final Map<String, Object> resourceAccess = (Map<String, Object>) jwt.getClaims().getOrDefault("resource_access", | ||
Map.of()); | ||
final Map<String, Object> kfAppEai = (Map<String, Object>) resourceAccess.getOrDefault("kf-app-eai", Map.of()); | ||
final Collection<String> roles = (Collection<String>) kfAppEai.getOrDefault("roles", List.of()); | ||
|
||
return roles.stream().map(role -> new SimpleGrantedAuthority("ROLE_" + role)) | ||
.collect(Collectors.toCollection(HashSet::new)); | ||
} | ||
} |
This file contains 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 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 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 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