{"record":{"id":"7834836f6465211e","repo":"alibaba/nacos","slug":"user-s-not-found-783483","errorCode":null,"errorMessage":"User %s not found","messagePattern":"User (.+?) not found","errorType":"exception","errorClass":"UsernameNotFoundException","httpStatus":null,"severity":"warning","filePath":"plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserServiceRemoteImpl.java","lineNumber":62,"sourceCode":" * @author xiweng.yy\n */\npublic class NacosUserServiceRemoteImpl extends AbstractCachedUserService\n    implements NacosUserService {\n    \n    private static final Logger LOGGER = LoggerFactory.getLogger(NacosUserServiceRemoteImpl.class);\n    \n    private final NacosRestTemplate nacosRestTemplate;\n    \n    public NacosUserServiceRemoteImpl() {\n        super();\n        this.nacosRestTemplate = new DefaultHttpClientFactory(LOGGER).createNacosRestTemplate();\n    }\n    \n    @Override\n    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {\n        User user = getUser(username);\n        if (null == user) {\n            throw new UsernameNotFoundException(String.format(\"User %s not found\", username));\n        }\n        return new NacosUserDetails(user);\n    }\n    \n    @Override\n    public void updateUserPassword(String username, String password) {\n        Query query = Query.newInstance().addParam(\"username\", username);\n        Map<String, String> body = Map.of(\"newPassword\", password);\n        try {\n            HttpRestResult<String> result = nacosRestTemplate.putForm(\n                buildRemoteUserUrlPath(AuthConstants.USER_PATH),\n                RemoteServerUtil.buildServerRemoteHeader(), query, body, String.class);\n            RemoteServerUtil.singleCheckResult(result);\n        } catch (NacosException e) {\n            throw new NacosRuntimeException(e.getErrCode(), e.getErrMsg());\n        } catch (Exception unpectedException) {\n            throw new NacosRuntimeException(NacosException.SERVER_ERROR,\n                unpectedException.getMessage());","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/users/NacosUserServiceRemoteImpl.java#L44-L80","documentation":"Same UsernameNotFoundException contract but from the remote/proxying impl: getUser(username) first checks the local cache, then triggers reload() from the peer, and if still absent throws. Because the remote impl never touches a DB directly, a miss here means the peer server also does not have the user (or the peer was unreachable and reload() logged and swallowed the failure).","triggerScenarios":"Login on a console node proxied to a server where the user does not exist; the user cache is cold and reload() returned a list without that user; reload() itself failed silently (caught in AbstractCachedUserService.reload) so the cache stayed empty.","commonSituations":"User created on one server but not yet visible to the proxying console node; peer temporarily unreachable during reload; user deleted on the peer after the cache was built.","solutions":["Verify the user exists on the peer server via /user/list or the DB behind it.","Check server logs for [LOAD-USERS] load failed warnings indicating reload() could not reach the peer.","Confirm the peer address in cluster.conf is correct and reachable.","Map UsernameNotFoundException to a 401/invalid-credentials response at the login boundary."],"exampleFix":"// before\nUserDetails ud = userService.loadUserByUsername(username);\n\n// after\ntry {\n    UserDetails ud = userService.loadUserByUsername(username);\n} catch (UsernameNotFoundException e) {\n    log.warn(\"user not found via remote impl; peer may be unreachable: {}\", username);\n    throw new BadCredentialsException(\"invalid credentials\");\n}","handlingStrategy":"try-catch","validationCode":"// For the remote impl, confirm the peer is reachable and the cache loaded.\nif (RemoteServerUtil.getServerAddresses().isEmpty()) {\n    log.warn(\"no peer configured; user lookup will miss\");\n}\n// Trigger a cache reload awareness:\nif (userService.getCachedUserMap().isEmpty()) {\n    log.warn(\"user cache empty; remote lookup may be needed\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    UserDetails ud = userService.loadUserByUsername(username);\n} catch (UsernameNotFoundException e) {\n    log.warn(\"user not found via remote impl (peer may be unreachable): {}\", username);\n    throw new org.springframework.security.authentication.BadCredentialsException(\"invalid credentials\");\n}","preventionTips":["Verify the user exists on the peer server, not just the local cache.","Watch for [LOAD-USERS] load failed warnings signaling reload() could not reach the peer.","Keep cluster.conf accurate so reload() reaches a healthy node.","Map the exception to a 401 without leaking whether the peer was unreachable."],"tags":["auth","user-management","login","remote","spring-security"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}