Conversation
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.
Pull Request: Auth Refactor split responsibilities
Summary
Breaks the monolithic
Authclass into three focused classes and centralizes the duplicatedinstantiate()helper intoContainer.Changes
1. AuthPassword — password utilities extracted
Added:
security/auth/AuthPassword.javahash(String password)— BCrypt hashingcheck(String password, String hash)— BCrypt verification2. TokenAuth — Bearer token authentication extracted
Added:
security/auth/TokenAuth.javauserFromToken(Request)— resolves user fromAuthorization: Bearerheader with request-level cachingisAuthenticated(Request)— checks token validityrequireToken(Request, Response)— halts 401 if no valid tokenrequireTokenRole(Request, Response, String)— halts 403 if missing rolegetTokenResolver()— lazy-loadsTokenResolvervia Container or auto-detection3. Auth — slimmed down to session auth only
Modified:
security/auth/Auth.javaTokenAuth)login()now usesAuthPassword.check()internally instead ofBCryptdirectlyhashPassword()/checkPassword()kept as@Deprecatedwrappers delegating toAuthPasswordfor backward compatibilityautoDetectTokenResolver()side-effect fromautoDetectUserDetailsService()instantiate()method (now usesContainer.instantiate())java.lang.reflect)4. Container.instantiate() — centralized reflection helper
Modified:
di/Container.javainstantiate(Class<?> implClass, Class<T> targetType)— creates an instance via no-arg or DI-resolved constructor + field injectionresolve(), does not require@Service/@Repositoryannotations and does not register as singletoninstantiate()that existed in bothAuthandTokenAuth5. RoleChecker — updated to use TokenAuth
Modified:
security/role/RoleChecker.javaAuth.requireToken()→TokenAuth.requireToken()Auth.requireTokenRole()→TokenAuth.requireTokenRole()6. BaseController — updated to use AuthPassword
Modified:
http/controller/BaseController.javaAuth.hashPassword()→AuthPassword.hash()Auth.checkPassword()→AuthPassword.check()7. Tests updated
Modified:
AuthPasswordTest.javaAuth.hashPassword()/Auth.checkPassword()toAuthPassword.hash()/AuthPassword.check()Modified:
AuthTest.javatokenResolverreset fromsetUp()(field no longer exists inAuth)TokenAuthTest)fakeUser()usesAuthPassword.hash()instead ofAuth.hashPassword()Added:
TokenAuthTest.javaTokenResolverto avoid Reflections auto-detect in test contextuserFromToken(no header, invalid prefix, empty bearer, valid token, caching),isAuthenticated(no token, invalid, valid)Breaking Changes
Auth.requireToken(Request, Response)→ useTokenAuth.requireToken(Request, Response)Auth.requireTokenRole(Request, Response, String)→ useTokenAuth.requireTokenRole(Request, Response, String)Auth.userFromToken(Request)→ useTokenAuth.userFromToken(Request)Auth.isTokenAuthenticated(Request)→ useTokenAuth.isAuthenticated(Request)Auth.getTokenResolver()→ useTokenAuth.getTokenResolver()Auth.hashPassword(String)andAuth.checkPassword(String, String)still work but are@Deprecated— migrate toAuthPassword.hash()/AuthPassword.check()