Repository navigation
Migrate ACL from Sa-Token to Spring Security with JWT - #3
Open
willzou2012 wants to merge 1 commit into
Open
willzou2012 wants to merge 1 commit into
willzou2012 wants to merge 1 commit into
Conversation
Summary: - Login/sessions: replace Sa-Token opaque tokens and session store with stateless JWT (HS256, JJWT) issued at login; Bearer is canonical and the legacy token header is still accepted so the frontend is unchanged. Logout, password change, user disable/delete revoke tokens via a jti registry; new login revokes previous tokens (single-session). - Authorization: convert all 72 SaCheck checks to @PreAuthorize with identical permission codes; load ROLE_* + parent-expanded permissions per request from the unchanged RBAC tables. - Replace SaResult with ServiceResult and SaTokenDao with TtlStore (identical contracts); remove the Sa-Token dependency and the stray vendored Sa-Token file at the repo root (zero references remain). - Rename permissionService files to match their public type names so the build works on case-sensitive filesystems; update docs and config (sa-token.* -> app.jwt.*, JWT_SECRET from env). Test Plan: - mvn test: 56 tests run, 0 failures. New suites cover JWT issue/parse/ revoke, HTTP filter chain (401/403, Bearer + legacy header, revoked/ disabled/malformed tokens), authority loading, login-session flow with real RSA/BCrypt/JWT, forced logout on disable/delete, scratch-store semantics, exception mapping, @PreAuthorize mapping guard, CORS, plus the existing context test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the ACL from Sa-Token to Spring Security with stateless JWT, and removes Sa-Token completely (dependency, annotations, session store, result/KV types, and a stray vendored Sa-Token source file tracked at the repo root). A repo-wide sweep for Sa-Token references now returns 0 matches.
Login & sessions
JwtService(JJWT): 30 days with "remember me", otherwise a 2-hour hard expiry (the former sliding active-timeout cannot slide with JWT).JwtAuthenticationFilter.Authorization: Bearer <token>is canonical; the legacytoken:header is still accepted and login still returns{token}, so the existing frontend needs no changes.ActiveTokenRegistry): logout revokes the current token; password change, account disable, and account delete revoke all of the user's tokens; a new login revokes previously issued tokens (single-session, matching the formeris-concurrent=false).Authorization
@SaCheckPermission/@SaCheckRolechecks were converted to@PreAuthorize("hasAuthority('...')")/hasRole('...')with identical permission codes (guarded byPreAuthorizeMappingTest, which asserts representative codes and the total count).BlogUserDetailsServicefrom the unchanged RBAC tables:ROLE_<roleCode>plus permission codes with the existing parent-expansion rule (a parent permission implies all children; super-admin gets every registered permission). Role/permission edits and account disabling therefore take effect immediately.SecurityConfig:/api/public/**,/api/images/**,/api/captcha/**, and auth entry points (login/register/password-reset/OAuth/public-key) are anonymous; everything else requires authentication. 401/403 responses keep the project's unifiedResponseJSON shape (GlobalExceptionHandler+ security entry points).SaResult / SaTokenDao swap
SaResult->ServiceResult(common/ServiceResult) with an identicaldata/error/ok/setCode/getCode/getData/getMsgcontract, so service signatures and controller handling did not churn.SaTokenDao(used as a generic TTL scratch store) ->TtlStorefor temp-login tokens, OAuth codes, and pending register/password-reset/email-change records;SaFoxUtil->TokenGenerator.Config
sa-token.*properties replaced byapp.jwt.*(JWT_SECRETenv, issuer, expirations). Production must set a strongJWT_SECRET(>= 32 chars); the committed default is dev-only.Incidentals
permissionService.java/permissionServiceImpl.javatoPermissionService.java/PermissionServiceImpl.java(public type names) so the project compiles on case-sensitive filesystems.Document/Permission_Hierarchy.md, API docs).Review guide
config/system/SecurityConfig.java,security/(filter, JWT, registry, user-details), andservice/user/auth/AuthServiceImpl.java(login/logout/password session behavior). The bulk of the remaining diff is mechanical:SaResult -> ServiceResultrenames and@SaCheck* -> @PreAuthorizeconversions.common/ServiceResult.java,common/TtlStore.java,security/*.java,utils/security/TokenGenerator.java. Deleted:config/system/SaTokenConfig.java,cn/dev33/satoken/exception/NotLoginException.java.Test Plan
mvn test: 56 tests run, 0 failures (JDK 23,-Dmaven.compiler.proc=full; on JDK 17 the flag is unnecessary).ROLE_prefix, disabled/deleted users); login-session flow with real RSA/BCrypt/JWT (single-session revoke, logout, password-change revoke); forced logout on user disable/delete; scratch-store one-time/attempt/rate-limit semantics; 401/403 exception mapping;@PreAuthorizemapping/count guard; CORS headers; plus the pre-existingMyblogDevApplicationTests.contextLoads.org.wltea:ik-analyzer:2012_u6is not published to Maven Central, so a fully clean machine cannot resolve the stock pom (verified locally with a stub installed only in the local Maven repo); the H2 test schema logs table-init warnings duringcontextLoads, as before.Rollback
Revert this single commit; the RBAC schema and API contracts are unchanged, and tokens issued before/after are not cross-compatible (users simply log in again).