Generalized symmetries and 2-groups via electromagnetic duality in AdS/CFT