The well-known Dirichlet problem defining the ellipsoidal equilibrium configuration for a self-gravitating homogeneous fluid mass endowed with internal motion linear functions of the coordinates is here generalized. In the present work using the second-order virial equations we provide the conditions necessary to solve the Dirichlet problem in a more general case of heterogeneous masses having nonlinear internal motions. The equations for the stability are presented with the general algorithms for their solution. The generalization to these new solutions of Dedekind's theorem is also proved. These models may lead to a direct explanation of some basic features of galactic morphology.