rrezartprebreza/spring-boot-skills / skills/spring-boot-4/oauth2-resource-server
oauth2-resource-server
VerifiedUse when configuring Spring Boot as an OAuth2 resource server, validating JWTs from an external auth provider (Keycloak, Auth0, Okta, Cognito), extracting claims, or implementing scope-based authorization.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.3 KB |
| agents/openai.yaml | config | 207 B |
| examples/bad-resource-server-config.java | other | 2.1 KB |
| examples/good-resource-server-config.java | other | 1.6 KB |
| templates/ExternalIdentity.java | other | 751 B |
| templates/JwtClaimExtractor.java | other | 2.2 KB |
| templates/ResourceServerConfig.java | other | 3.3 KB |
examples/bad-resource-server-config.java
View on GitHub// BAD — pre-Security-7 API (won't compile), wrong role check, unnecessary UserDetailsService, session-based
@Configuration
@EnableWebSecurity
public class ResourceServerConfig extends WebSecurityConfigurerAdapter { // REMOVED — gone since Security 6, still gone in 7
@Autowired // field injection
private UserDetailsService userDetailsService; // not needed for JWT resource server
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable() // non-lambda DSL — removed in Security 7, won't compile
.authorizeRequests() // removed in Security 7 — use authorizeHttpRequests
.antMatchers("/api/**") // antMatchers removed in Security 7 — use requestMatchers
.hasRole("ADMIN") // hasRole expects ROLE_ prefix, not SCOPE_
.and() // and() removed from HttpSecurity in Security 7
.oauth2ResourceServer() // non-lambda style removed — use lambda DSL
.jwt(); // no custom converter — roles won't map correctly
// Session is not explicitly STATELESS — defaults to IF_REQUIRED
// This means the server creates HTTP sessions, defeating JWT's purpose
}
@Bean
public JwtDecoder jwtDecoder() {
return NimbusJwtDecoder.withJwkSetUri(
"http://auth-server/.well-known/jwks.json") // hardcoded URL, should use issuer-uri
.build();
}
// UserDetailsService is unnecessary for resource servers —
// the JWT token contains all claims needed for authentication
@Bean
public UserDetailsService userDetailsService() {
return username -> userRepository.findByEmail(username) // extra DB call per request!
.map(u -> User.withUsername(u.getEmail()).password(u.getPassword()).roles("USER").build())
.orElseThrow();
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |