Spring Boot Security
Rule: Every endpoint must be explicitly protected. No endpoint is public unless declared with permitAll() in SecurityConfig.
Before Starting
- Check existing security setup in
src/security/andsrc/config/SecurityConfig.java:bash ~/.claude/skills/project-scan/scripts/scan.sh - Load
references/security-patterns.md— permission model and guard patterns
Steps
Protecting an existing endpoint
- Add
@PreAuthorizeto the controller method:@PreAuthorize("@permissionEvaluator.hasPermission(authentication, 'PERMISSION_NAME')") - Verify the permission exists in the
AppPermissionenum - Confirm the permission is assigned to the correct roles in the seeder or config
Setting up JWT from scratch
- Add dependencies:
spring-boot-starter-security,jjwt-api,jjwt-impl,jjwt-jackson - Create in
src/security/:JwtFilter,JwtService,UserDetailsServiceImpl - Create
SecurityConfiginsrc/config/— define the filter chain and public routes - Add
JWT_SECRETandJWT_EXPIRATIONtoapplication.ymlvia env vars — never hardcode - Run
env-checkto confirm vars are set:bash ~/.claude/skills/env-check/scripts/check-env.sh