{"record":{"id":"61daab7a6e90e793","repo":"paascloud/paascloud-master","slug":"uac10011041","errorCode":"UAC10011041","errorMessage":"UAC10011041","messagePattern":"UAC10011041","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/support/BaseController.java","lineNumber":44,"sourceCode":"\n/**\n * The class Base controller.\n *\n * @author paascloud.net@gmail.com\n */\npublic class BaseController {\n\n\tprotected final Logger logger = LoggerFactory.getLogger(this.getClass());\n\n\t/**\n\t * Gets login auth dto.\n\t *\n\t * @return the login auth dto\n\t */\n\tprotected LoginAuthDto getLoginAuthDto() {\n\t\tLoginAuthDto loginAuthDto = (LoginAuthDto) ThreadLocalMap.get(GlobalConstant.Sys.TOKEN_AUTH_DTO);\n\t\tif (PublicUtil.isEmpty(loginAuthDto)) {\n\t\t\tthrow new BusinessException(ErrorCodeEnum.UAC10011041);\n\t\t}\n\t\treturn loginAuthDto;\n\t}\n\n\t/**\n\t * Handle result wrapper.\n\t *\n\t * @param <T>    the type parameter\n\t * @param result the result\n\t *\n\t * @return the wrapper\n\t */\n\tprotected <T> Wrapper<T> handleResult(T result) {\n\t\tboolean flag = isFlag(result);\n\n\t\tif (flag) {\n\t\t\treturn WrapMapper.wrap(Wrapper.SUCCESS_CODE, \"操作成功\", result);\n\t\t} else {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/support/BaseController.java#L26-L62","documentation":"BaseController.getLoginAuthDto throws ErrorCodeEnum.UAC10011041 when there is no LoginAuthDto stored in the ThreadLocal under TOKEN_AUTH_DTO. It means the controller wants the current logged-in user but no authenticated user was propagated into this thread (e.g. the auth filter/interceptor did not run or the token was missing/invalid).","triggerScenarios":"A controller extending BaseController calls getLoginAuthDto() while ThreadLocalMap.get(GlobalConstant.Sys.TOKEN_AUTH_DTO) returns null — unauthenticated request, missing Authorization header, or the auth interceptor never populated the ThreadLocal.","commonSituations":"Calling a protected endpoint without a valid token, internal/scheduled code paths invoking controllers outside an HTTP request, gateway not forwarding auth headers, or testing controllers without simulating the auth filter.","solutions":["Ensure the request carries a valid Authorization token so the auth interceptor populates ThreadLocalMap.","Verify the gateway/security filter chain forwards and decodes the auth header on this route.","For non-HTTP contexts, refactor to pass LoginAuthDto explicitly instead of relying on the ThreadLocal.","In tests, seed ThreadLocalMap with a LoginAuthDto before invoking the controller."],"exampleFix":"// before (test)\nLoginAuthDto user = controller.getLoginAuthDto();\n// after\nThreadLocalMap.put(GlobalConstant.Sys.TOKEN_AUTH_DTO, new LoginAuthDto(1L, \"testUser\"));\nLoginAuthDto user = controller.getLoginAuthDto();","handlingStrategy":"validation","validationCode":"LoginAuthDto cached = (LoginAuthDto) ThreadLocalMap.get(GlobalConstant.Sys.TOKEN_AUTH_DTO);\nif (cached == null) {\n    throw new AuthenticationException(\"no login user in context; ensure auth filter ran\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    LoginAuthDto user = getLoginAuthDto();\n} catch (BusinessException e) {\n    throw new UnauthorizedException(\"login required\");\n}","preventionTips":["Call getLoginAuthDto only from request threads after the auth interceptor.","In tests, seed ThreadLocalMap before invoking controllers.","Do not use it inside @Async tasks; pass the user explicitly.","Confirm gateway forwards Authorization headers on all secured routes."],"tags":["authentication","threadlocal","controller","missing-user"],"backgroundTag":"authentication-required","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}