A characterization of the Chern and Bernwald connections