Compare commits
No commits in common. "9824fbbbfd68c394ba7bea768ec8d55a9fd4dad6" and "8e7b0770de3e0e6b623d2db61b68b28ee99de4cc" have entirely different histories.
9824fbbbfd
...
8e7b0770de
@ -84,8 +84,8 @@ class KeycloakSecurityConfig {
|
|||||||
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
|
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
|
||||||
|
|
||||||
Map<String, Object> realmAccess = jwt.getClaim(REALM_ACCESS_CLAIM);
|
Map<String, Object> realmAccess = jwt.getClaim(REALM_ACCESS_CLAIM);
|
||||||
if (realmAccess != null && realmAccess.containsKey(ROLES_CLAIM)) {
|
if (realmAccess != null && realmAccess.containsKey("roles")) {
|
||||||
List<String> roles = (List<String>) realmAccess.get(ROLES_CLAIM);
|
List<String> roles = (List<String>) realmAccess.get("roles");
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + role));
|
grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + role));
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ package de.szut.lf8_starter.welcome;
|
|||||||
|
|
||||||
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.security.Principal;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class WelcomeController {
|
public class WelcomeController {
|
||||||
@ -19,7 +19,7 @@ public class WelcomeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/roles")
|
@GetMapping("/roles")
|
||||||
public ResponseEntity<Collection<? extends GrantedAuthority>> getRoles(Authentication authentication) {
|
public ResponseEntity<?> getRoles(Authentication authentication) {
|
||||||
return ResponseEntity.ok(authentication.getAuthorities());
|
return ResponseEntity.ok(authentication.getAuthorities());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user