Connections with prescribed curvature