Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-4/spring-security-jwt

spring-security-jwt

Verified

Use when an application issues and validates its own first-party JWT access and refresh tokens, including authentication filters, password encoding, RBAC, and method security. For JWTs issued by Keycloak, Auth0, Okta, Cognito, or another authorization server, use oauth2-resource-server.

examples/bad-security-config.java

View on GitHub
// BAD — pre-Security-7 API (won't compile), session-based, hardcoded secret, missing method security

@Configuration
@EnableWebSecurity                                        // missing @EnableMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {  // REMOVED — gone since Security 6, still gone in 7

    @Autowired                                            // field injection
    private JwtAuthenticationFilter jwtAuthFilter;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()                             // non-lambda DSL — removed in Security 7, won't compile
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)  // should be STATELESS for JWT
            .and()                                            // and() removed from HttpSecurity in Security 7
            .authorizeRequests()                          // removed — use authorizeHttpRequests
            .antMatchers("/api/**").authenticated()        // antMatchers removed in Security 7 — use requestMatchers
            .and()
            .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();               // default strength 10, should use 12
    }

    // secret hardcoded as string literal — should be in environment variable
    private static final String SECRET = "mySecretKey12345678901234567890123456";
}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall