Index of every page on this site: llms.txt
All skills
roby2358 avatar

/java-spring-boot-coldstart

@956ee23
by roby2358roby2358/skills5 stars
Run it yourself

Bootstrap and build Java 21 Spring Boot 3 services for a team with mixed Java experience. Covers REST APIs, SQS messaging via Spring Cloud AWS, Spring Security 6 (JWT resource server), and JUnit 5 + Mockito testing. Maven, no Lombok. Use when creating a new Spring Boot project, adding REST endpoints/SQS listeners/security config, or writing tests against Spring components.

Use this Skill: https://skilld.dev/gh/roby2358/skills/java-spring-boot-coldstart

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencessecurity.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Security

Spring Security 6 (Boot 3.x) configures via a SecurityFilterChain bean and a fluent lambda DSL. The old WebSecurityConfigurerAdapter class is gone — don't use examples that extend it.

Default behavior

Adding spring-boot-starter-security to the classpath secures every endpoint with HTTP Basic and a generated password (printed at startup). That is the default — it must be replaced before deploying.

Filter chain: JWT resource server

Most internal services authenticate via a JWT issued by an upstream identity provider. Configure the app as an OAuth2 resource server:

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .requestMatchers("/actuator/health/**").permitAll()
                .requestMatchers(HttpMethod.GET, "/orders/**").hasAuthority("SCOPE_orders:read")
                .requestMatchers(HttpMethod.POST, "/orders/**").hasAuthority("SCOPE_orders:write")
                .anyRequest().authenticated()
            )
            .oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
            .sessionManagement(s -> s.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
            .csrf(csrf -> csrf.disable());  // safe to disable for stateless JSON APIs
        return http.build();
    }
}
spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://auth.example.com/realms/internal

Spring fetches the JWKS from the issuer's well-known endpoint and validates incoming Authorization: Bearer <jwt> headers automatically.

Authority mapping

By default, JWT scopes become authorities prefixed with SCOPE_ (e.g. orders:read → SCOPE_orders:read). To use roles from a custom claim, register a JwtAuthenticationConverter:

@Bean
public JwtAuthenticationConverter jwtAuthConverter() {
    JwtGrantedAuthoritiesConverter authorities = new JwtGrantedAuthoritiesConverter();
    authorities.setAuthoritiesClaimName("roles");
    authorities.setAuthorityPrefix("ROLE_");

    JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
    converter.setJwtGrantedAuthoritiesConverter(authorities);
    return converter;
}

Spring picks up the bean automatically; no extra wiring needed.

Method security

For finer-grained checks inside services, enable method security and use @PreAuthorize:

@Configuration
@EnableMethodSecurity
public class MethodSecurityConfig {}
@PreAuthorize("hasAuthority('SCOPE_orders:write')")
public OrderResponse cancel(String orderId) { ... }

@PreAuthorize("hasAuthority('SCOPE_orders:read') and #customerId == authentication.name")
public List<OrderResponse> myOrders(String customerId) { ... }

Use sparingly — most authz belongs at the URL level in the filter chain. Method security shines for object-level permissions (e.g. "can this user touch this specific order?").

CORS

If the API is called by browsers from a different origin, enable CORS in the filter chain and define the allowed origins centrally:

http.cors(Customizer.withDefaults());

@Bean
CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowedOrigins(List.of("https://app.example.com"));
    config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE"));
    config.setAllowedHeaders(List.of("Authorization", "Content-Type"));
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", config);
    return source;
}

Don't use * for allowed origins on an authenticated API — browsers reject it.

Common pitfalls

  • Looking up old WebSecurityConfigurerAdapter examples — removed in Spring Security 6. Always use the SecurityFilterChain bean.
  • Disabling CSRF without thinking — fine for stateless JSON APIs called by SPAs/services, dangerous for browser-rendered apps with cookies.
  • Wide-open actuator — only /actuator/health should be public. Everything else (/actuator/env, /actuator/beans) leaks internals.
  • permitAll() on a path that should be authenticated — the filter chain matches in order; check the order when something is unexpectedly public.
  • Not testing security — see testing.md for @WithMockUser and MockMvc security helpers.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6mo3 checks · Risk SAFE
  • Gen Agent Trust Hub6mo

    This skill provides a set of templates and instructions for bootstrapping and developing Java Spring Boot 3 applications. It uses official and well-known resources, follow industry best practices for security and configuration, and contains no malicious patterns.

  • Socket6mo

    No alerts

  • Snyk6mo

    Risk: LOW · No issues

Signed by skilld at 956ee23. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 7 months ago

README badge

README badge for roby2358/skills/java-spring-boot-coldstart