A way to assign a role, for example ROLE_ADMIN, to a user goes like this.
//Get the enity manager
$em = $this->getDoctrine()->getManager();
//Get the user with name admin
$user= $em->getRepository("<your vendor>\<your bundle>\Entity\User")->findBy(Array("name" => "admin"));
//Set the admin role
$user->addRole("ROLE_ADMIN");
//Save it to the database
$em->persist($user);
$em->flush();
You can also set the role in the constructor of the User Entity class, which goes like this:
public function __construct()
{
parent::__construct();
$this->addRole("ROLE_ADMIN");
}
Remember that setting the role in the constructor means that's it is not saved in the database(unless your persist and flush) and that it is applied to every user.
If you have some additional questions please let me know.
PS: if you use the Sonata Admin bundle the user's role can be set with a form located in the Admin section