  We consider the possibility of explaining the observed spectrum and
composition of the cosmic rays with energies above $10^{17}$ eV in terms of two
different extragalactic populations of sources in the presence of a turbulent
intergalactic magnetic field (including also a fading Galactic cosmic-ray
component). The populations are considered to be the superposition of different
nuclear species having rigidity dependent spectra. The first extragalactic
population is dominant in the energy range $10^{17}$ to $10^{18}$ eV and
consists of sources having a relatively large density ($> 10^{-3}$ Mpc$^{-3}$)
and a steep spectrum. The second extragalactic population dominates the cosmic
ray flux above few EeV, it has a harder spectral slope and has a high-energy
cutoff at few $Z$ EeV (where $eZ$ is the associated cosmic ray charge). This
population has a lower density of sources ($<10^{-4}$ Mpc$^{-3}$), so that the
typical intersource separation is larger than few tens of Mpc, being
significantly affected by a magnetic horizon effect that strongly suppresses
its flux for energies below $\sim Z$ EeV. We discuss how this scenario could be
reconciled with the values of the cosmic-ray source spectral indices that are
expected to result from the diffusive shock acceleration mechanism.
