【发布时间】:2020-07-10 11:54:49
【问题描述】:
如何使用基本身份验证调用 Oracle REST 数据服务,在视图上反映选择?
我可以在没有身份验证的情况下使用它,但是一旦我打开身份验证并将凭据添加到客户端的调用中,服务器就会返回 404 错误。
对于服务器,我使用的是托管在 Oracle 云上的 Oracle 数据库。
select * from V$VERSION returns ...
BANNER BANNER_FULL BANNER_LEGACY CON_ID
-------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production 0
Version 19.5.0.0.0
什么有效
给定一个名为 connect4 的目标架构和一个已启用 REST 且对象名称为 game 的视图,当 authentication required 为在服务器上关闭...
$url = 'https://<redacted>.adb.ap-sydney-1.oraclecloudapps.com/ords/connect4/game'
$return = Invoke-RestMethod $url
$return | select -expandProperty Content | convertFrom-Json
什么不起作用
但是,当我打开 authentication required 打开时,以下 powershell 脚本应该可以工作,但不能。相反,它返回 404。此列表中的 $user 是 connect4 用户帐户密码。凭据是使用基本身份验证协议传递的。密码已被验证为正确。
$url = 'https://<redacted>.adb.ap-sydney-1.oraclecloudapps.com/ords/connect4/game'
$user = 'connect4'
$pass = '<redacted>'
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential( $user, $secpasswd)
$return = Invoke-RestMethod $url -Credential $credential -headers @{'X-ID-TENANT-NAME' = '<redacted>'}
$return | select -expandProperty Content | convertFrom-Json
推测
是否需要对 connect4 用户应用某种授权以使其能够通过 REST 选择自己的对象? 还是我的客户调用错了?
更新
REST 服务显示的实际对象是视图GAME_VW。它有一个 REST 对象别名 game,所需的 REST 授权是 ORDS 角色 oracle.dbtools.role.autorest.CONNECT4.GAME_VW。我相信ORDS role 是与常规 Oracle 角色不同的概念,因此不能以通常的方式授予/撤销。
视图的 REST 设置的 DDL 是 ...
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
ORDS.ENABLE_OBJECT(p_enabled => TRUE,
p_schema => 'CONNECT4',
p_object => 'GAME_VW',
p_object_type => 'VIEW',
p_object_alias => 'game',
p_auto_rest_auth => TRUE);
commit;
END;
我相信该用户的 ORDS 角色设置正确。以下查询...
select NAME as ROLE_NAME, sys_context( 'userenv', 'current_schema' ) as CURRENT_SCHEMA, USER
from USER_ORDS_ROLES
where NAME = 'oracle.dbtools.role.autorest.CONNECT4.GAME_VW';
...返回...
ROLE_NAME CURRENT_SCHEMA USER
-----------------------------------------------------------------------
oracle.dbtools.role.autorest.CONNECT4.GAME_VW CONNECT4 CONNECT4
和这个查询,使用同一个会话...
select NAME, SCHEMA_ID
from USER_ORDS_ROLES
where NAME like 'oracle.dbtools.role.autorest.CONNECT4%';
...返回...
NAME SCHEMA_ID
--------------------------------------------------------
oracle.dbtools.role.autorest.CONNECT4 10011
oracle.dbtools.role.autorest.CONNECT4.GAME_VW 10011
此权限的 DDL 是 ...
DECLARE
l_roles OWA.VC_ARR;
l_modules OWA.VC_ARR;
l_patterns OWA.VC_ARR;
BEGIN
ORDS.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'CONNECT4',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'connect4',
p_auto_rest_auth => TRUE);
ORDS.CREATE_ROLE(p_role_name => 'oracle.dbtools.role.autorest.CONNECT4.GAME_VW');
l_roles(1) := 'oracle.dbtools.autorest.any.schema';
l_roles(2) := 'oracle.dbtools.role.autorest.CONNECT4.GAME_VW';
l_patterns(1):= '/game/*';
l_patterns(2):= '/metadata-catalog/game/*';
ORDS.DEFINE_PRIVILEGE(
p_privilege_name => 'oracle.dbtools.autorest.privilege.CONNECT4.GAME_VW',
p_roles => l_roles,
p_patterns => l_patterns,
p_modules => l_modules,
p_label => '',
p_description => '',
p_comments => NULL);
COMMIT;
END;
【问题讨论】:
标签: oracle rest basic-authentication