Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-3/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 — deprecated API, session-based, hardcoded secret, missing method security

@Configuration
@EnableWebSecurity                                        // missing @EnableMethodSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {  // deprecated since Spring Security 5.7

    @Autowired                                            // field injection
    private JwtAuthenticationFilter jwtAuthFilter;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()                             // old chaining API, not lambda DSL
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)  // should be STATELESS for JWT
            .and()
            .authorizeRequests()                          // deprecated — use authorizeHttpRequests
            .antMatchers("/api/**").authenticated()        // antMatchers deprecated — 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: 471kUpdated 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: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated 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