Skip to content

Commit b279d06

Browse files
committed
JAVA-46416: Changes made for restoring https://www.baeldung.com/soap-keycloak code
1 parent f2d8c13 commit b279d06

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

spring-boot-modules/spring-boot-keycloak-2/src/main/java/com/baeldung/keycloak/keycloaksoap/KeycloakRoleConverter.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,15 @@ public class KeycloakRoleConverter implements Converter<Jwt, Collection<GrantedA
1212

1313
@Override
1414
public Collection<GrantedAuthority> convert(Jwt jwt) {
15-
Collection<GrantedAuthority> authorities = new ArrayList<>();
16-
// Extract client roles with ROLE_ prefix
17-
authorities.addAll(extractClientRoles(jwt));
18-
19-
return authorities;
20-
}
21-
22-
23-
24-
private Collection<GrantedAuthority> extractClientRoles(Jwt jwt) {
2515
Map<String, Object> resourceAccess = jwt.getClaim("resource_access");
26-
if (resourceAccess == null || resourceAccess.isEmpty()) {
27-
return Collections.emptyList();
28-
}
2916
// Replace this with your actual client ID from Keycloak
3017
String clientId = "baeldung-soap-services";
3118

3219
Map<String, Object> client = (Map<String, Object>) resourceAccess.get(clientId);
33-
if (client == null || client.isEmpty()) {
34-
return Collections.emptyList();
35-
}
36-
@SuppressWarnings("unchecked")
3720
List<String> roles = (List<String>) client.get("roles");
38-
if (roles == null) {
39-
return Collections.emptyList();
40-
}
21+
4122
return roles.stream()
42-
.map(role -> new SimpleGrantedAuthority("ROLE_" + role)) // Add ROLE_ prefix here
23+
.map(role -> new SimpleGrantedAuthority("ROLE_" + role))
4324
.collect(Collectors.toList());
4425
}
4526
}

spring-boot-modules/spring-boot-keycloak-2/src/main/java/com/baeldung/keycloak/keycloaksoap/KeycloakSecurityConfig.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
6-
import org.springframework.security.config.Customizer;
76
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
87
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
98
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
109
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
1110
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
12-
import org.springframework.security.oauth2.server.resource.web.authentication.BearerTokenAuthenticationFilter;
1311
import org.springframework.security.web.SecurityFilterChain;
14-
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1512

1613
@Configuration
1714
@EnableWebSecurity

0 commit comments

Comments
 (0)