یک منبع داده می تواند در یکی از دو حالت دسترسی به شرح زیر عمل کند:
در حالت دسترسی محدود، که پیشفرض است، یک منبع داده فقط درخواستهایی را ارائه میکند که از همان دامنهای که منبع داده در آن قرار دارد، منشأ میگیرند. حالت محدود از حملات جعل درخواست بین سایتی (XSRF) جلوگیری می کند و بنابراین از حالت دسترسی نامحدود ایمن تر است. از آنجایی که کتابخانه منبع داده رابطی را فقط برای بازگرداندن داده ها و نه برای تغییر وضعیت یا داده ها در سمت سرور فراهم می کند، فقط حملات XSRF که سعی در سرقت داده ها دارند امکان پذیر است. برای ایمنسازی منبع دادهتان در برابر تلاشها برای سرقت دادهها، حالت محدود باید همراه با احراز هویت مبتنی بر کوکی استفاده شود. روش احراز هویت کاربران به محیط و پیاده سازی شما بستگی دارد.
در حالت دسترسی نامحدود، یک منبع داده به همه درخواستها بدون در نظر گرفتن منشأ آنها پاسخ میدهد. منبع داده ای که در حالت نامحدود اجرا می شود را می توان با احراز هویت مبتنی بر کوکی محافظت کرد، اما توجه داشته باشید که منبع داده در برابر حملات XSRF آسیب پذیر خواهد بود. اگر تجسمها در صفحات وب خارج از دامنه منبع داده نیاز به دسترسی به منبع داده دارند، یا اگر دادهها در دامنه عمومی هستند و بنابراین نیازی به محافظت ندارند، از حالت نامحدود استفاده کنید.
یک درخواست تجسم میتواند فرمت پاسخ JSON، CSV، یا HTML را مشخص کند. فرمت پاسخ، فرمتی را تعیین می کند که منبع داده، جدول داده را برمی گرداند. از آنجایی که فرمتهای CSV و HTML در برابر حملات XSRF آسیبپذیر نیستند، میتوان از دامنههای دیگر، حتی در حالت محدود، به آنها دسترسی داشت.
برای تعیین حالت نامحدود، isRestrictedAccessMode() را به صورت زیر لغو کنید:
برای سادگی، تمام نمونه های ارائه شده با کتابخانه در حالت دسترسی نامحدود اجرا می شوند.
خطاها و هشدارها
هنگامی که امکان یا مطلوب نیست، یک جدول داده معتبر را برگردانید، کتابخانه یک DataSourceException می اندازد. به عنوان مثال اگر کاربر نمی تواند احراز هویت شود. کتابخانه این استثناها را زمانی که خطاها مانع از ایجاد جدول داده می شود را ایجاد می کند. ممکن است بخواهید در موقعیتهایی که منحصر به منبع داده شما هستند، استثناء ایجاد کنید. اگر چنین است، انواع استثنای خطای خود را با ارث بردن از کلاس DataSourceException ایجاد کنید. همچنین می توانید کلاس DataSourceException را مستقیماً پرتاب کنید.
کلاس DataSourceException در بسته base قرار دارد و پارامترهای زیر را می گیرد:
ReasonType این پارامتر اجباری است. انواع دلایل موجود در فهرست ReasonType تعریف شده است. اگر هیچ یک از انواع دلایل موجود مناسب نیست، می توانید از Other یا Internal استفاده کنید.
MessageToUser این پارامتر متن پیام خطا را مشخص می کند. در بیشتر موارد، به عنوان یک راهنمای ابزار به کاربر نمایش داده می شود، بنابراین مهم است که اطلاعات فنی یا محرمانه درج نشود.
می توانید از مجموعه توابع کمکی در datasource.DataSourceHelper برای رسیدگی به خطاها استفاده کنید. در این مورد دو تابع را با نام یکسان setErrorServletResponse فراخوانی کنید تا یک DataSourceException گرفته شود و یک خطا در پاسخ سرولت داده تنظیم شود. یکی از این توابع درخواست منبع داده را می گیرد، دیگری HttpServlet request می گیرد و در مواردی استفاده می شود که ایجاد DataSourceRequest ناموفق باشد. یک نمونه پیادهسازی در تعریف قابلیتها و جریان رویدادها ارائه شده است.
اگر امکان برگرداندن جدول داده وجود نداشته باشد، کتابخانه یک خطا برمی گرداند. اگر امکان برگرداندن یک جدول داده وجود داشته باشد، اما مشکلی برای گزارش وجود داشته باشد، کتابخانه یک هشدار را همراه با جدول داده برمی گرداند. به عنوان مثال، کتابخانه در شرایط زیر یک هشدار ایجاد می کند:
اگر تجسم پرس و جو یک LIMIT فراهم کند که منجر به داده های کوتاه شده شود.
اگر یک تجسم پرس و جو یک الگوی قالب بندی نامعتبر در یک عبارت FORMAT درخواست کند.
برای اضافه کردن هشدار خود، یک نمونه از base.Warning ایجاد کنید و با استفاده از متد addWarning() آن را به جدول دادههای خود اضافه کنید.
ورود به سیستم
این کتابخانه از ثبت گزارش مشترک جاکارتا استفاده می کند. ورود به سیستم عام جاکارتا را می توان با اکثر سیستم های گزارش گیری رایج که ممکن است قبلاً در جای خود داشته باشید استفاده کرد. اگر سیستم ورود به سیستم شما غیر استاندارد است، ممکن است نیاز به نوشتن یک آداپتور داشته باشید. برای جزئیات بیشتر، به صفحه اصلی ثبت نام عوام جاکارتا مراجعه کنید.
هنگامی که یک استثنا پرتاب می شود اطلاعات به گزارش ارسال می شود. نحوه دسترسی شما به گزارش به سیستم ثبت گزارشی که استفاده می کنید بستگی دارد.
تاریخ آخرین بهروزرسانی 2024-07-10 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2024-07-10 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis documentation provides information about security considerations, error handling, and logging within the data source library.\u003c/p\u003e\n"],["\u003cp\u003eData sources operate in restricted access mode by default to prevent XSRF attacks, but unrestricted mode can be enabled for cross-domain access.\u003c/p\u003e\n"],["\u003cp\u003eThe library uses \u003ccode\u003eDataSourceException\u003c/code\u003e for errors, with helper functions available to handle these errors in servlet responses.\u003c/p\u003e\n"],["\u003cp\u003eWarnings are used to indicate problems without preventing data table return, like truncated data due to limits or invalid formatting.\u003c/p\u003e\n"],["\u003cp\u003eLogging is handled through Jakarta commons logging, which can be adapted to various logging systems.\u003c/p\u003e\n"]]],[],null,["# Handling Security, Errors, Warnings, and Logging\n\nThis section covers the following topics:\n\n- [Security](#access)\n- [Errors and Warnings](#error)\n- [Logging](#logging)\n\nSecurity\n--------\n\nA data source can operate in one of two access modes as follows:\n\n- In\n restricted access mode, which is the default, a data source serves only\n those requests that originate from the same domain as that in which the\n data source is located. Restricted mode prevents [cross-site\n request forgery](http://en.wikipedia.org/wiki/Cross-site_request_forgery) (XSRF) attacks and so is more secure than unrestricted\n access mode. Because the data source library provides an interface for\n returning data only, and not for changing state or data on the server side,\n only XSRF attacks\n that attempt to steal data are possible. To\n make your data source secure against attempts to steal data, restricted\n mode must be used in conjunction with cookie-based authentication.\n The way that you authenticate users depends on your environment and implementation.\n\n- In unrestricted access mode, a data source serves all requests\n regardless of their origin. A data source that runs in unrestricted mode\n can be protected by cookie-based authentication, but note that\n the data source will be vulnerable to\n XSRF attacks. Use unrestricted mode if visualizations on web pages outside the data source's\n domain need to access the data source, or if the data is in the public\n domain and so does not need to be protected.\n\nA visualization request can specify a response\nformat of JSON, CSV, or HTML. The response format determines the format\nin which a data source returns a data table. Because CSV and HTML formats\nare not vulnerable to XSRF attacks, these can be accessed from other domains,\neven in restricted mode.\n\nTo specify unrestricted mode, override `isRestrictedAccessMode()` as\nfollows: \n\n```transact-sql\n @Override\n protected boolean isRestrictedAccessMode() {\n return false;\n }\n```\n\nFor simplicity, all the examples provided with the library run in unrestricted\naccess mode.\n\nErrors and Warnings\n-------------------\n\nWhen it is not possible, or desirable, to return a valid data table, the\nlibrary throws a `DataSourceException`. For example if\nthe user cannot be authenticated. The library throws these exceptions\nwhen errors prevent it from creating a data table. You may want to throw\nexceptions in situations unique to your data source. If so,\ncreate your own error exception types by inheriting from the `DataSourceException`\nclass. You can also throw the `DataSourceException` class\ndirectly.\n\nThe `DataSourceException` class\nis located in the `base` package, it takes the following parameters: \n\n- `ReasonType` \n This parameter is mandatory. Available reason types are defined in the `ReasonType` enum. If none of the available reason types are suitable, you can use `Other` or `Internal`. \n- `MessageToUser` \n This parameter defines the text of the error message. In most cases, it is displayed to the user as a tooltip, so it is important not to include technical or confidential information.\n\nYou can use the set of helper functions\nin `datasource.DataSourceHelper` to handle\nerrors. In this case call two functions both with same name of `setErrorServletResponse` to\ntake a `DataSourceException` and set an error on the data\nservlet response. One of these functions takes a data source request, the\nother takes an `HttpServlet request` and is used in cases\nwhere there is a failure to create a `DataSourceRequest`. An\nexample implementation is provided in [Defining Capabilities and the Flow of Events](/chart/interactive/docs/dev/dsl_httpservlet).\n\nIf it is not possible to return a data table, the library returns an\nerror. If it is possible to return a data table, but there is a problem\nto report, the library returns a warning together with the data table.\nFor example, the library\ncreates a warning in the following situations:\n\n- if a querying visualization provides a `LIMIT` that results in truncated data.\n- if a querying visualization requests an invalid formatting pattern in a `FORMAT` clause.\n\nTo add your own warning,\ncreate an instance of `base.Warning` and add it to your\ndata table using the `addWarning()` method.\n\nLogging\n-------\n\nThe library uses Jakarta commons logging. Jakarta commons logging can\nbe used with most common logging systems that you might already have in\nplace. You might need to write an adapter if your logging system is non-standard.\nFor more details, see the [Jakarta\ncommons logging home page](http://commons.apache.org/logging/).\n\nWhen an exception is thrown information is sent to the log. The way\nthat you access the log depends on the logging system you use."]]