Spring Security
Spring Security is maintained by the Spring team, not by Choreo Identity & Access Management. Because it already speaks OIDC, it works with Choreo Identity & Access Management out of the box, and this guide shows the configuration. Token validation, session management, and access control are handled by Spring Security itself.
org.springframework.boot- SDK by the Spring team
Handling authentication
Five steps, all standard Spring Security: login flow, token validation, scope-based access control, and back-channel logout. Spring Security is maintained by the Spring team; Choreo Identity & Access Management maintains this guide and the configuration below.
1. Add Spring's OAuth2 starters
Both are Spring Boot artifacts: client for browser login, resource-server for bearer-token APIs. Versions come from the Spring Boot BOM. Drop whichever you do not need.
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
2. Point the app at your Choreo Identity & Access Management issuer
These are Spring's standard OIDC properties. There are no Choreo Identity & Access Management-specific configuration keys to learn.
spring:
security:
oauth2:
client:
registration:
thunderid:
client-id: ${THUNDERID_CLIENT_ID}
client-secret: ${THUNDERID_CLIENT_SECRET}
scope: openid, profile, email
provider:
thunderid:
issuer-uri: https://<DATA_PLANE_URL>
resourceserver:
jwt:
issuer-uri: https://<DATA_PLANE_URL>
Declaring both client and resourceserver lets one application serve browser sessions and bearer-token API calls. Omit either block if you only need one.
3. Secure your endpoints
An ordinary SecurityFilterChain bean. Scopes from the Choreo Identity & Access Management token arrive prefixed with SCOPE_.
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health").permitAll()
.requestMatchers("/api/billing/**").hasAuthority("SCOPE_billing:read")
.anyRequest().authenticated())
.oauth2Login(Customizer.withDefaults())
.oauth2ResourceServer(rs -> rs.jwt(Customizer.withDefaults()))
.build();
}
}
4. Read the authenticated principal
Inject Spring's own OidcUser for session-based flows, or Jwt for bearer-token requests. Claims map straight through.
@RestController
public class ProfileController {
@GetMapping("/me")
public Map<String, Object> me(@AuthenticationPrincipal OidcUser user) {
return Map.of(
"sub", user.getSubject(),
"email", user.getEmail(),
"org", user.getClaimAsString("org_id")
);
}
@PreAuthorize("hasAuthority('SCOPE_billing:read')")
@GetMapping("/api/billing")
public Invoice billing(@AuthenticationPrincipal Jwt jwt) {
return service.forTenant(jwt.getClaimAsString("org_id"));
}
}
Enable @PreAuthorize with @EnableMethodSecurity on any configuration class.
5. Receive back-channel logout
Spring Security implements OpenID Connect Back-Channel Logout. These additions to the configuration above stand up the receiving endpoint and end the matching Spring session when Choreo Identity & Access Management posts a logout token. Register the endpoint URL as the application's back-channel logout URI in Choreo Identity & Access Management. They need Spring Security 6.4 or later, which Spring Boot 3.4 ships.
@Bean
OidcSessionRegistry oidcSessionRegistry() {
return new InMemoryOidcSessionRegistry();
}
@Bean
OidcBackChannelLogoutHandler oidcLogoutHandler(OidcSessionRegistry oidcSessionRegistry) {
return new OidcBackChannelLogoutHandler(oidcSessionRegistry);
}
// Removes a registry entry when its servlet session ends
@Bean
HttpSessionEventPublisher sessionEventPublisher() {
return new HttpSessionEventPublisher();
}
// In the SecurityFilterChain, next to oauth2Login(...):
.oidcLogout(logout -> logout.backChannel(Customizer.withDefaults()))
The endpoint is /logout/connect/back-channel/thunderid, where thunderid is the registration id. Spring correlates each login's sid to the servlet session in the OidcSessionRegistry, which this example keeps in memory. Several instances need a shared OidcSessionRegistry and a shared servlet session store, such as Spring Session, since the notification can reach an instance that does not hold the session. The handler sends the JSESSIONID cookie by default; with Spring Session's SESSION cookie, call setSessionCookieName("SESSION") on the handler.
Claim mapping
How Choreo Identity & Access Management token claims arrive on the Spring side. This is the reference you will actually reach for, since there is no separate Choreo Identity & Access Management API surface to learn.
| Choreo Identity & Access Management claim | Spring accessor | Notes |
|---|---|---|
| sub | user.getSubject() | Stable Choreo Identity & Access Management user identifier. |
| email | user.getEmail() | Present when the email scope is granted. |
| scope | getAuthorities() | Each scope becomes a SCOPE_ authority. |
| org_id | getClaimAsString("org_id") | Tenant context for multi-org applications. |
| act | getClaimAsMap("act") | Present on agent tokens; identifies the acting agent. |
Requirements
| | |
|---|---|
| Spring Boot | 3.2 to 3.4 (supported) |
| Spring Security | >= 6.2 (supported) |
| Java | 17, 21 (supported) |
| Kotlin | >= 1.9 (supported) |
| Spring Boot 2.7 / Security 5 | legacy (unsupported) |
Where to get help
Two projects, two places to ask.
Something wrong in this guide?
The guide and the Choreo Identity & Access Management configuration it documents are ours. We keep it current with each Spring Boot release.
Choreo Identity & Access Management issues · Ask the community
Something wrong in Spring Security?
The library itself is maintained by the Spring team. Bugs and feature requests belong on their tracker, not ours.
Was this page helpful?