We introduce a systematic method to solve a type of Cartans realization problem. Our method builds upon a new theory of Lie algebroids and Lie groupoids with structure group and connection. This approach allows to find local as well as complete solutions, their symmetries, and to determine the moduli spaces of local and complete solutions. We apply our method to the problem of classification of extremal Kahler metrics on surfaces.