When studying the quantization of the electromagnetic field, one seems to always derive everything for free space (no charges/currents). This involves solving Maxwell's equations to find modes (in this case plane waves) that are occupied by photons.
How does this translate to situations where one also has a medium (e.g. waveguide, cavity,...)?
In practice, I see people calculating EM modes by solving Maxwell's equations as if they were classical, and then stating that this is the mode a photon can occupy. I see this is the case for free space, but I wonder what the theoretical basis is to get to the case of non-free space.