Based on sa-token-doc/plugin/ integration class documentation.
Applicable Scenarios
Activate this skill when the user needs the following scenarios:
- JWT stateless authentication — Encode login information into the Token, reducing Redis queries, suitable for high-concurrency scenarios
- Distributed Session sharing — Session data needs to be shared during multi-instance deployment
- Redis cache isolation — Physically separate Sa-Token's Redis from the business Redis
- Service-layer annotation authentication — Use annotations such as @SaCheckLogin at the Service layer (not Controller)
- Quickly build a login page — Zero-code login page for development environments or internal management systems
- Template engine authentication tags — Control button visibility in Thymeleaf/Freemarker pages
Workflow
Step 1. Determine integration requirements — Choose JWT/Redis/AOP/template and other modules Step 2. Introduce dependencies — Add the corresponding Maven/Gradle dependencies Step 3. Configure parameters — Configure jwt-secret-key/Redis connection/Alone-Redis, etc. Step 4. Inject implementations — Inject StpLogic, register filters, configure template engine Step 5. Verify and test — Confirm the integration takes effect, and test whether core functions work properly
Capability Boundaries
✅ Strong Suits
- JWT integration — Choose among the three modes Simple/Mixin/Stateless
- Redis persistence — Two approaches: JDK serialization/JSON serialization
- Alone-Redis standalone Redis — Physical isolation of authentication cache and business cache
- AOP annotation authentication — Use annotations such as @SaCheckLogin at the Service layer
- SpEL expressions — @SaCheckEL uses Spring expressions
- Quick-Login quick login — Zero-code injection of the login page
- JSON serialization extension — Jackson/Fastjson/Fastjson2/Snack3/Snack4
- Template engine integration — Thymeleaf/Freemarker custom tags
- RPC integration — Dubbo/Dubbo3/gRPC context propagation
⚠️ Requirements
- JWT requires configuring
jwt-secret-key - Redis requires configuring
spring.redisconnection information - AOP annotations and interceptor annotations cannot be used at the same time
❌ Out of Scope
- Basic login/permission/annotation authentication → sa-token
- SSO → sa-token-sso
- OAuth2.0 → sa-token-oauth2
- Microservice authentication → sa-token-micro
Reference documentation
| Topic | File | Source |
|---|---|---|
| JWT three modes (Simple/Mixin/Stateless) | references/jwt-extend.md | GitHub |
| Redis persistence + Alone-Redis | references/dao-extend.md | dao-extend、integ-redis |
FAQ
Q: How do you choose among the three JWT modes? A: Simple mode is recommended (complete functionality: kick-out, ban, and session management are all supported). If statelessness is needed, choose Stateless (but kick-out/ban are unavailable). Mixin is between the two.
Q: Which of the two Redis serialization methods should be chosen? A: RedisTemplate JSON serialization is recommended (data is readable, convenient for troubleshooting). JDK serialization has better compatibility but the data is garbled.
Q: What is the difference between Alone-Redis and regular Redis? A: Alone-Redis uses an independent Redis connection and database, fully isolated from business Redis, ensuring that authentication cache is not affected by business.
Q: Can AOP annotation authentication and interceptor authentication be used at the same time? A: They cannot be used at the same time. AOP is used for the Service layer, and interceptors are used for the Controller layer. Choose one.
Q: Is Quick-Login suitable for production environments? A: It is suitable for small systems or internal management systems. For production environments, it is recommended to customize the login page.
Q: What functions do template engine tags support?
A: Supports sa:login(login verification),sa:hasRole(role judgment),sa:hasPermission(permission judgment), and other tags.
Gotchas
- Simple mode
is-shareis always false — incompatible with Extra data, cannot share token - Mixin mode
is-concurrentmust be true — otherwise the kick-out API is unavailable - After JWT integration, Token becomes JWT format — it is no longer uuid format, and the content can be decoded and viewed
- Alone-Redis has an independent configuration prefix
sa-token-alone-redis— notspring.redis - After Redis JSON serialization, Session data is readable in Redis — it can be viewed directly in the Redis client
- AOP annotations and interceptor annotations cannot be mixed — if AOP is chosen, interceptors can no longer be used
- Quick-Login default account password is sa/123456 — be sure to change it in production environments
- Dubbo integration automatically handles context propagation — no additional code is needed, just import the dependency
Data Privacy
This skill does not collect, store, or transmit any user data. All code examples are for local development reference only.