apache/shenyu · error · AuthenticationException

userName( ) can not be found.

Error message

userName(%s) can not be found.

What it means

ShiroRealm authenticates the JWT's issuer as a dashboard user name; if dashboardUserService.findByUserName(userName) returns null, no such dashboard user exists in the admin database and an AuthenticationException naming the user is thrown.

Solutions

  1. Log in again to get a token issued for an existing dashboard user
  2. Verify the user exists: query the dashboard_user table for the userName in the error message
  3. If the DB was reset, recreate the dashboard user before reusing old tokens
  4. Check that the admin instance the client targets is the one that issued the token (same database)

Example fix

// before
DELETE FROM dashboard_user WHERE user_name = 'admin';
// after
-- recreate or re-enable the user instead of deleting while sessions are active
INSERT INTO dashboard_user (user_name, password, enabled) VALUES ('admin', '{bcrypt}...', TRUE);
Defensive patterns

Strategy: validation

Validate before calling

// confirm the user exists before using a token
boolean userExists = adminApi.userExists(issuerFromToken);

Try / catch

try { call(); } catch (AuthenticationException e) { if (e.getMessage().endsWith("can not be found.")) { relogin(); } }

Prevention

When it happens

Trigger: The JWT has a valid issuer claim but no DashboardUser row with that userName exists — e.g. the user was deleted from the dashboard, the token was issued by a different admin instance/database, or the H2/MySQL DB was reset while old tokens are still in use.

Common situations: Admin database re-initialized (db/init scripts rerun) while browsers keep old tokens; multi-environment setups sharing tokens between dev/prod admin instances; user renamed via direct DB edits; stale tokens after user deletion.

Understand the failure class

Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/cf3f90113b46fc14. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/shiro/config/ShiroRealm.java:107

        }
        return super.isPermitted(permission, info);
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authenticationToken) {
        String token = (String) authenticationToken.getCredentials();
        if (StringUtils.isEmpty(token)) {
            return null;
        }

        String userName = JwtUtils.getIssuer(token);
        if (StringUtils.isEmpty(userName)) {
            throw new AuthenticationException("userName is null");
        }

        DashboardUserVO dashboardUserVO = dashboardUserService.findByUserName(userName);
        if (Objects.isNull(dashboardUserVO)) {
            throw new AuthenticationException(String.format("userName(%s) can not be found.", userName));
        }
        if (!Boolean.TRUE.equals(dashboardUserVO.getEnabled())) {
            throw new AuthenticationException(String.format("user(%s) is disabled.", userName));
        }
        String clientIdFromToken = JwtUtils.getClientId(token);
        if (StringUtils.isNotEmpty(clientIdFromToken)
                && StringUtils.isNotEmpty(dashboardUserVO.getClientId())
                && !StringUtils.equals(dashboardUserVO.getClientId(), clientIdFromToken)) {
            throw new AuthenticationException("clientId is invalid or does not match");
        }

        if (!JwtUtils.verifyToken(token, jwtProperties.getSecretKey())) {
            throw new AuthenticationException("token is error.");
        }

        return new SimpleAuthenticationInfo(UserInfo.builder()
                .userName(userName)
                .userId(dashboardUserVO.getId())

View on GitHub (pinned to 567142e072)