and also an role

$roleAuthModel = $objectManager->create('\Magento\Authorization\Model\Role');            
            $roleAuthModel->setName("cool role")
                ->setPid(0) //set parent role id of your role

        $userModel->setEmail("[email protected]");

How can I relate and set "cool role" to my new user "bbbb" ?

1 Answer 1


You can set role to admin user using role and user models.

/** @var \Magento\Authorization\Model\Role $role */
$role = $this->getRole();
/** @var $model \Magento\User\Model\User */
$user = $this->getUser();


In your case:


Source: \Magento\User\Controller\Adminhtml\User\Save::execute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.