paascloud/paascloud-master · error · BusinessException
UAC10011041
UAC10011041
Error message
UAC10011041
What it means
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).
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.
Example fix
// before (test) LoginAuthDto user = controller.getLoginAuthDto(); // after ThreadLocalMap.put(GlobalConstant.Sys.TOKEN_AUTH_DTO, new LoginAuthDto(1L, "testUser")); LoginAuthDto user = controller.getLoginAuthDto();
Defensive patterns
Strategy: validation
Validate before calling
LoginAuthDto cached = (LoginAuthDto) ThreadLocalMap.get(GlobalConstant.Sys.TOKEN_AUTH_DTO);
if (cached == null) {
throw new AuthenticationException("no login user in context; ensure auth filter ran");
} Try / catch
try {
LoginAuthDto user = getLoginAuthDto();
} catch (BusinessException e) {
throw new UnauthorizedException("login required");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- UAC10011039
- UAC10011040
- Failed to decode basic authentication token
- Invalid basic authentication token
- Authentication method not supported:
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/61daab7a6e90e793.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/support/BaseController.java:44
/**
* The class Base controller.
*
* @author paascloud.net@gmail.com
*/
public class BaseController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* Gets login auth dto.
*
* @return the login auth dto
*/
protected LoginAuthDto getLoginAuthDto() {
LoginAuthDto loginAuthDto = (LoginAuthDto) ThreadLocalMap.get(GlobalConstant.Sys.TOKEN_AUTH_DTO);
if (PublicUtil.isEmpty(loginAuthDto)) {
throw new BusinessException(ErrorCodeEnum.UAC10011041);
}
return loginAuthDto;
}
/**
* Handle result wrapper.
*
* @param <T> the type parameter
* @param result the result
*
* @return the wrapper
*/
protected <T> Wrapper<T> handleResult(T result) {
boolean flag = isFlag(result);
if (flag) {
return WrapMapper.wrap(Wrapper.SUCCESS_CODE, "操作成功", result);
} else {View on GitHub (pinned to 781281a950)