当前位置:网站首页>第九章 REST 服务安全
第九章 REST 服务安全
2022-07-28 11:43:00 【yaoxin521123】
文章目录
第九章 REST 服务安全
如果 REST 服务正在访问机密数据,应该对服务使用身份验证。如果需要为不同的用户提供不同级别的访问权限,还要指定端点所需的权限。
为 REST 服务设置身份验证
可以对 IRIS REST 服务使用以下任何形式的身份验证:
HTTP身份验证标头 — 这是REST服务的推荐身份验证形式。Web会话身份验证 — 其中用户名和密码在 URL 中的问号后面指定。OAuth 2.0身份验证 - 请参阅以下小节。
REST 应用程序和 OAuth 2.0
要通过 OAuth 2.0 对 REST 应用程序进行身份验证,请执行以下所有操作:
- 将包含
REST应用程序的资源服务器配置为OAuth 2.0资源服务器。 - 允许对
%Service.CSP进行委派身份验证。 - 确保将
Web应用程序(用于REST应用程序)配置为使用委托身份验证。 - 在
%SYS命名空间中创建一个名为ZAUTHENTICATE的例程。 提供了一个示例例程REST.ZAUTHENTICATE.mac,可以复制和修改它。此例程是 GitHub (https://github.com/intersystems/Samples-Security) 上 Samples-Security 示例的一部分。可以按照“下载用于 IRIS 的示例”中的说明下载整个示例,但在GitHub上打开例程并复制其内容可能更方便。
在例程中,修改 applicationName 的值并根据需要进行其他更改。
指定使用 REST 服务所需的权限
为了指定执行代码或访问数据所需的权限, 技术使用基于角色的访问控制 (RBAC)。
如果需要为不同的用户提供不同级别的访问权限,请执行以下操作来指定权限:
- 修改规范类以指定使用
REST服务或REST服务中的特定端点所需的权限;然后重新编译。权限是与资源名称组合的权限(例如读取或写入)。 - 使用管理门户:
- 定义在规范类中引用的资源。
- 定义提供权限集的角色。例如,角色可以提供对端点的读取访问权限或对不同端点的写入访问权限。一个角色可以包含多组权限。
- 将用户置于其任务所需的所有角色中。
此外,可以使用 %CSP.REST 类的 SECURITYRESOURCE 参数来执行授权。
指定权限
可以为整个 REST 服务指定权限列表,也可以为每个端点指定权限列表。为此:
- 要指定访问服务所需的权限,请编辑规范类中的
OpenAPI XData块。对于info对象,添加一个名为x-ISC_RequiredResource的新属性,其值是以逗号分隔的已定义资源列表及其访问模式 (resource:mode),这是访问REST服务的任何端点所必需的。
下面显示了一个示例:
"swagger":"2.0",
"info":{
"version":"1.0.0",
"title":"Swagger Petstore",
"description":"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService":"http://swagger.io/terms/",
"x-ISC_RequiredResource":["resource1:read","resource2:read","resource3:read"],
"contact":{
"name":"Swagger API Team"
},
...
- 要指定访问特定端点所需的权限,请将
x-ISC_RequiredResource属性添加到定义该端点的操作对象,如下例所示:
"post":{
"description":"Creates a new pet in the store. Duplicates are allowed",
"operationId":"addPet",
"x-ISC_RequiredResource":["resource1:read","resource2:read","resource3:read"],
"produces":[
"application/json"
],
...
- 编译规范类。此操作重新生成调度类。
使用 SECURITYRESOURC 参数
作为附加的授权工具,分派 %CSP.REST 子类的类具有 SECURITYRESOURCE 参数。 SECURITYRESOURCE 的值要么是资源及其权限,要么只是资源(在这种情况下,相关权限是使用)。系统检查用户是否对与 SECURITYRESOURCE 关联的资源具有所需的权限。
注意:如果调度类为 SECURITYRESOURCE 指定了一个值,并且 CSPSystem 用户没有足够的权限,那么这可能会导致登录尝试失败时出现意外的 HTTP 错误代码。为防止这种情况发生, 建议您将指定资源的权限授予 CSPSystem 用户。
边栏推荐
- Use json.stringify() to format data
- Why do enterprises need the ability of enterprise knowledge management?
- Anhui Jingzhun: Beidou satellite synchronous clock | Beidou synchronous clock | NTP network clock server
- Not optimistic about Apple making AR, Luo Yonghao: I'll do it myself
- 30 years of open source community | 2022 open atom global open source summit 30 years of special activities of open source community were successfully held
- 用C语言开发NES游戏(CC65)05、调色板
- Yan Ji lost Beijing again, and more than half of the stores in the country were closed
- STM32F103 几个特殊引脚做普通io使用注意事项以及备份寄存器丢失数据问题1,2
- [try to hack] UDF raises rights
- 十三. 实战——常用依赖的作用
猜你喜欢

Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held

Is it overtime to be on duty? Take up legal weapons to protect your legitimate rights and interests. It's time to rectify the working environment

AVL tree (balanced search tree)

Zadig v1.13.0 believes in the power of openness, and workflow connects all values

Distributed session solution

How does musk lay off staff?

04 pyechars 地理图表(示例代码+效果图)

恋爱男女十禁

New progress in the implementation of the industry | the openatom openharmony sub forum of the 2022 open atom global open source summit was successfully held

Uniapp wechat applet realizes the function of connecting low-power Bluetooth printing
随机推荐
Deployment之滚动更新策略。
sqli-labs(less-8)
西门子对接Leuze BPS_304i 笔记
Developing NES game (cc65) 07 and controller with C language
【萌新解题】爬楼梯
HMS core audio editing service supports 7 kinds of audio effects to help one-stop audio processing
STM32F103 几个特殊引脚做普通io使用注意事项以及备份寄存器丢失数据问题1,2
恋爱男女十禁
Hongjiu fruit passed the hearing: five month operating profit of 900million Ali and China agricultural reclamation are shareholders
Solve the PHP prompt warning: division by zero in error
[Nuxt 3] (十二) 项目目录结构 3
Brief discussion on open source OS distribution
Industry, University, research and application jointly build an open source talent ecosystem | the 2022 open atom global open source summit education sub forum was successfully held
新零售电商O2O模式解析
C for循环内定义int i变量出现的重定义问题
[cute new problem solving] climb stairs
Fastjson parses multi-level JSON strings
图书馆自动预约脚本
C# 结构使用
Most of the interfaces of Tiktok are already available, and more interfaces are still open. Please look forward to it