code: public void validateTenantAccess(Tenant tenant, String userid, String password,
                                       Permission permNeeded, boolean isPrivileged)
              throws UnauthorizedException, NotFoundException {
          // So we can allow /_logs and other commands before the DBService has initialized,
          // allow valid privileged commands without checking the tenant.
          if (isPrivileged) {
              if (!isValidSystemCredentials(userid, password)) {
                  throw new UnauthorizedException("Unrecognized system user id/password");
              }
              return;
          }
          
          // Here the DB connection must be established.
          checkServiceState();
          if (!isValidTenantUserAccess(tenant, userid, password, permNeeded)) {
              throw new UnauthorizedException("Invalid tenant credentials or insufficient permission");
          }
      }
docs: Verify that the given tenant and command can be accessed using by the user
  represented by the given userID and password. An {@link UnauthorizedException} is
  thrown if the given credentials are invalid for the given tenant/command or if the
  user has insufficient rights for the command being accessed.
  <p>
  If the given tenant does not exist, a {@link NotFoundException} is thrown.
  
  @param tenant        {@link Tenant} being accessed.
  @param userid        User ID of caller. May be null.
  @param password      Password of caller. May be null.
  @param permNeeded    {@link Permission} needed by the invoking command.
  @param isPrivileged  True if the command being accessed is privileged.
  @throws              NotFoundException if the given tenant does not exist.
  @throws              UnauthorizedException if the given credentials are invalid or
  have insufficient rights for the given tenant and command.