elunez/eladmin · error · BadRequestException
账号未激活!
Error message
账号未激活!
What it means
Thrown by UserDetailsServiceImpl.loadUserByUsername (line 53) when the user row exists but user.getEnabled() is false. eladmin treats the enabled flag as the account-activation switch; a disabled account passes the existence check but is rejected before authorities are built. Note the check only runs on a cache miss — an already-cached JwtUserDto bypasses it until UserCacheManager evicts the entry.
Source
Thrown at eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java:53
@Slf4j
@RequiredArgsConstructor
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
private final UserService userService;
private final RoleService roleService;
private final DataService dataService;
private final UserCacheManager userCacheManager;
@Override
public JwtUserDto loadUserByUsername(String username) {
JwtUserDto jwtUserDto = userCacheManager.getUserCache(username);
if(jwtUserDto == null){
UserDto user = userService.getLoginData(username);
if (user == null) {
throw new BadRequestException("用户不存在");
} else {
if (!user.getEnabled()) {
throw new BadRequestException("账号未激活!");
}
// 获取用户的权限
List<AuthorityDto> authorities = roleService.buildPermissions(user);
// 初始化JwtUserDto
jwtUserDto = new JwtUserDto(user, dataService.getDeptIds(user), authorities);
// 添加缓存数据
userCacheManager.addUserCache(username, jwtUserDto);
}
}
return jwtUserDto;
}
}
View on GitHub (pinned to 55fbf70595)
Solutions
- UPDATE sys_user SET is_enabled = 1 WHERE username = '<user>' then retry login.
- If the account should stay disabled, inform the user — no code fix is needed; this is intended behavior.
- If disabling must take effect immediately, also clear the user cache (UserCacheManager.cleanCache / eviction) after toggling enabled, not just on next miss.
- Check the admin UI user list: the status toggle writes the enabled field; verify it persisted.
Example fix
// after an admin disables a user, keep auth consistent: // before user.setEnabled(false); userRepository.save(user); // after user.setEnabled(false); userRepository.save(user); userCacheManager.cleanCache(user.getUsername()); // drop cached JwtUserDto immediately
Defensive patterns
Strategy: validation
Try / catch
Catch BadRequestException on the auth call and branch on the message ('账号未激活' vs '用户不存在') to show account-activation guidance instead of a generic failure. Prevention
- Always set is_enabled = 1 when inserting users by SQL.
- When an admin toggles enabled, also evict the UserCacheManager entry so disable takes effect immediately.
- Surface account status in the admin user list so operators see which accounts are disabled.
When it happens
Trigger: Logging in with an account whose sys_user.is_enabled = 0 (e.g. deactivated by an admin in the user management screen); a freshly seeded user inserted with enabled missing (defaults off); admin disables a user mid-session and the user re-authenticates after cache eviction (default 1 hour via UserCacheManager).
Common situations: New rows inserted by hand into sys_user without setting is_enabled = 1; admin deactivates a leaver's account and the leaver's next login fails; stale Redis/user cache still authenticating a disabled user until eviction, creating confusion about whether the disable worked.
Related errors
AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14).
Data as JSON: /api/errors/c58d3fd68530bcbf.
Report an issue: GitHub.