보안, 오류, 경고, 로깅 처리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 섹션에서는 다음 내용에 대해 설명합니다.
보안
데이터 소스는 다음과 같은 두 액세스 모드 중 하나로 작동할 수 있습니다.
-
기본값인 액세스 제한 모드에서는 데이터 소스가 데이터 소스가 있는 도메인과 동일한 도메인에서 발생한 요청만 처리합니다. 제한 모드는 교차 사이트 요청 위조 (XSRF) 공격을 방지하므로 무제한 액세스 모드보다 안전합니다. 데이터 소스 라이브러리는 서버 측에서 상태나 데이터를 변경하지 않고 데이터를 반환하기 위한 인터페이스만 제공하므로 데이터를 도용하려는 XSRF 공격만 가능합니다. 데이터를 도용하려는 시도로부터 데이터 소스를 안전하게 보호하려면 제한 모드를 쿠키 기반 인증과 함께 사용해야 합니다.
사용자를 인증하는 방법은 환경과 구현에 따라 다릅니다.
-
무제한 액세스 모드에서는 데이터 소스가 출처와 관계없이 모든 요청을 처리합니다. 무제한 모드로 실행되는 데이터 소스는 쿠키 기반 인증으로 보호할 수 있지만 데이터 소스는 XSRF 공격에 취약합니다. 데이터 소스 도메인 외부 웹페이지의 시각화에서 데이터 소스에 액세스해야 하는 경우 또는 데이터가 공개 도메인에 있으므로 보호할 필요가 없는 경우 무제한 모드를 사용하세요.
시각화 요청에서 JSON, CSV 또는 HTML의 응답 형식을 지정할 수 있습니다. 응답 형식은 데이터 소스가 데이터 테이블을 반환하는 형식을 결정합니다. CSV 및 HTML 형식은 XSRF 공격에 취약하지 않으므로 제한 모드에서도 다른 도메인에서 액세스할 수 있습니다.
무제한 모드를 지정하려면 다음과 같이 isRestrictedAccessMode()
를 재정의합니다.
@Override
protected boolean isRestrictedAccessMode() {
return false;
}
편의상 라이브러리와 함께 제공되는 모든 예는 무제한 액세스 모드에서 실행됩니다.
오류 및 경고
유효한 데이터 테이블을 반환할 수 없거나 반환하는 것이 불가능하거나 바람직하지 않은 경우
라이브러리에서 DataSourceException
이 발생합니다. 예를 들어 사용자를 인증할 수 없는 경우입니다. 라이브러리에서는 오류로 인해 데이터 테이블을 만들지 못할 때 이러한 예외를 발생시킵니다. 데이터 소스에 고유한 상황에서 예외를 발생시키는 것이 좋습니다. 이 경우 DataSourceException
클래스에서 상속하여 자체 오류 예외 유형을 만드세요. DataSourceException
클래스를 직접 발생시킬 수도 있습니다.
DataSourceException
클래스는 base
패키지에 있으며 다음 매개변수를 사용합니다.
ReasonType
이 매개변수는 필수 항목입니다. 사용 가능한 이유 유형은 ReasonType
enum에 정의되어 있습니다. 사용 가능한 이유 유형 중 적합한 것이 없다면 Other
또는 Internal
를 사용할 수 있습니다.
MessageToUser
이 매개변수는 오류 메시지의 텍스트를 정의합니다.
대부분의 경우 사용자에게 도움말로 표시되므로 기술 또는 기밀 정보를 포함하지 않는 것이 중요합니다.
datasource.DataSourceHelper
의 도우미 함수 집합을 사용하여 오류를 처리할 수 있습니다. 이 경우 이름이 같은 setErrorServletResponse
의 두 함수를 호출하여 DataSourceException
을 가져오고 데이터 서블릿 응답에 오류를 설정합니다. 이러한 함수 중 하나는 데이터 소스 요청을 사용하고 다른 함수는 HttpServlet request
를 사용하며 DataSourceRequest
생성에 실패한 경우에 사용됩니다. 구현 예는 기능 및 이벤트 흐름 정의에서 제공됩니다.
데이터 테이블을 반환할 수 없는 경우 라이브러리는 오류를 반환합니다. 데이터 테이블을 반환할 수 있지만 보고할 문제가 있는 경우 라이브러리는 데이터 테이블과 함께 경고를 반환합니다.
예를 들어 라이브러리는 다음과 같은 상황에서 경고를 생성합니다.
- 쿼리 시각화에서 데이터가 잘리는
LIMIT
를 제공하는 경우입니다.
- 쿼리 시각화가
FORMAT
절에 잘못된 형식 지정 패턴을 요청하는 경우
자체 경고를 추가하려면 base.Warning
인스턴스를 만들고 addWarning()
메서드를 사용하여 데이터 테이블에 이를 추가합니다.
로깅
도서관은 자카르타 커먼즈 로깅을 사용합니다. 자카르타 커먼즈 로깅은 이미 사용 중인 가장 일반적인 로깅 시스템과 함께 사용할 수 있습니다. 로깅 시스템이 표준이 아닌 경우 어댑터를 작성해야 할 수도 있습니다.
자세한 내용은 Jakarta Commons Logging 홈페이지를 참조하세요.
예외가 발생하면 정보가 로그로 전송됩니다. 로그에 액세스하는 방법은 사용하는 로깅 시스템에 따라 다릅니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-07-10(UTC)
[null,null,["최종 업데이트: 2024-07-10(UTC)"],[[["\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."]]