private function getUserRoleSecurityContextPermission(
        $locale,
        $securityContext,
        UserRole $userRole,
        $checkPermissionType
    ) {
        $userPermission = $this->maskConverter->convertPermissionsToArray(0);

        foreach ($userRole->getRole()->getPermissions() as $permission) {
            $hasContext = $permission->getContext() == $securityContext;

            if (!$hasContext) {
                continue;
            }

            $hasLocale = null == $locale || in_array($locale, $userRole->getLocales());

            if (!$hasLocale) {
                continue;
            }

            if ($checkPermissionType) {
                $userPermission = $this->maskConverter->convertPermissionsToArray($permission->getPermissions());
            } else {
                array_walk($userPermission, function(&$permission) {
                    $permission = true;
                });
            }
        }

        return $userPermission;
    }