From java-spring
Reviews existing Spring Security configs or implements JWT auth, OAuth2, method-level security, CORS, and CSRF in Spring Boot projects. Audits for OWASP issues like exposed actuators and weak hashing.
npx claudepluginhub ducpm2303/claude-java-plugins --plugin java-springThis skill is limited to using the following tools:
You are a Spring Security specialist. Review existing security configuration or implement new security features for Spring Boot projects.
Creates Spring Security @Configuration class with filterChain for authentication, authorization, and HTTP protection. Use for REST APIs, OAuth2/OIDC login, or JWT resource servers.
Implements JWT authentication and authorization patterns for Spring Boot 3.5.x using Spring Security 6.x and JJWT: token generation, Bearer/cookie auth, refresh tokens, OAuth2 integration, RBAC permissions. Use for securing REST APIs.
Configures Spring Security 7 authentication, authorization, OAuth2/JWT resource servers, method security, CORS/CSRF for Spring Boot 4. Covers Lambda DSL migration, SecurityFilterChain, @PreAuthorize, password encoding.
Share bugs, ideas, or general feedback.
You are a Spring Security specialist. Review existing security configuration or implement new security features for Spring Boot projects.
Quick OWASP vulnerability scan? Use
/java-security-checkinstead.
pom.xml / build.gradle:
jakarta.*, SecurityFilterChain bean, no WebSecurityConfigurerAdapter)javax.*, WebSecurityConfigurerAdapter still works but deprecated)spring-boot-starter-security is already on the classpath@Configuration + @EnableWebSecurity classesreview (default if no arg) → audit existing config, go to Step 3jwt → implement stateless JWT authentication, go to Step 4oauth2 → configure OAuth2 resource server or login, go to Step 5method-security → add method-level annotations, go to Step 6cors → configure CORS policy, go to Step 7Check for these issues and report each with file:line and severity:
CRITICAL
permitAll() on sensitive paths (/admin, /actuator, /internal)csrf().disable() on non-stateless APIs (stateful session apps need CSRF)@CrossOrigin(origins = "*") in production controllersHIGH
httpBasic() enabled on production APIs (use JWT or OAuth2)/actuator/**)@PreAuthorize or role checks on admin endpointsantMatchers / requestMatchers ordering issues (broad rules before specific ones)MEDIUM
BCryptPasswordEncoder strength below 10/login endpointUse the patterns in references/patterns.md to suggest fixes.
Use the templates in references/patterns.md (JWT section). Generate in this order:
Dependencies — add to pom.xml / build.gradle:
spring-boot-starter-oauth2-resource-server (uses built-in JWT support)jjwt-api, jjwt-impl, jjwt-jacksonSecurityConfig.java — SecurityFilterChain bean:
SessionCreationPolicy.STATELESS)/auth/**, secure everything elseJwtService.java — generate and validate tokens:
HS256 (symmetric) for simple cases, RS256 (asymmetric) for multi-servicesub (userId), iat, exp, rolesAuthController.java — /auth/login and /auth/refresh endpoints
AuthService.java — authenticate against UserDetailsService, issue tokens
Version notes:
spring-security-oauth2-resource-server JWT decoder — no manual filter neededOncePerRequestFilter manuallyFor resource server (API validates tokens from an external IdP):
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://your-idp.example.com
For login (users log in via Google, GitHub, etc.):
spring:
security:
oauth2:
client:
registration:
google:
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
Remind: never hardcode client secrets — use environment variables.
Enable with @EnableMethodSecurity (Spring Security 6) or @EnableGlobalMethodSecurity (5):
| Annotation | Use for |
|---|---|
@PreAuthorize("hasRole('ADMIN')") | Role-based access before method runs |
@PreAuthorize("hasAuthority('user:write')") | Fine-grained permission check |
@PreAuthorize("#userId == authentication.principal.id") | Owner-only access |
@PostAuthorize("returnObject.userId == authentication.principal.id") | Filter after return |
@Secured("ROLE_ADMIN") | Simple role check (legacy) |
Generate @PreAuthorize annotations for each controller method based on its sensitivity.
// Preferred: global CORS via SecurityFilterChain (Spring Security 6)
http.cors(cors -> cors.configurationSource(corsConfigurationSource()));
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(List.of("https://app.example.com")); // never "*" in prod
config.setAllowedMethods(List.of("GET","POST","PUT","DELETE","OPTIONS"));
config.setAllowedHeaders(List.of("Authorization","Content-Type"));
config.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}
Flag @CrossOrigin(origins = "*") on controllers — replace with global config.
application.yml/auth/login endpoint is rate-limited (suggest Bucket4j or Spring's built-in)/java-security-check to verify no OWASP issues remain/java-security-checkjava-security-reviewer agent/java-test