第四步,在数据库用户A 中,将视图查询权限授予给用户B
因为在步骤二中,加了with grant option ,所以这里视图查询权限可以成功授予。
grant select on INVEST_CLOCK_views to ryd_interface;
grant select on INVEST_LOG_views to ryd_interface;
grant select on run_views to ryd_interface;
第五步,在数据库用户B 中,检查视图能否查询得到,再创建同义词。
conn ryd_interface/ryd_interface
select count(*) from ryd_interface_src.run_views;
select count(*) from ryd_interface_src.INVEST_CLOCK_views;
select count(*) from ryd_interface_src.INVEST_LOG_views;
create synonym run_views for ryd_interface_src.run_views;
create synonym INVEST_CLOCK_views for ryd_interface_src.INVEST_CLOCK_views;
create synonym INVEST_log_views for ryd_interface_src.INVEST_log_views;
第三方的系统直接通过这个同义词就可以访问到用户A 中的视图。这也是对系统安全的一种保护措施。第三方系统登录后,只能看到其同义词,其他的都不会访问得到。
第六步,限制资源使用
因为用户B 是给第三方系统使用,我们无法控制第三方应用的质量,为了防止在应用出现异常连接时数据库会话数暴涨导致数据库整体服务出现故障,所以我们对该用户的数据库会
话数做一个限制。
这里采用profile 的sessions_per_user 功能,实现单个用户会话数的限制。
conn / as sysdba
alter system set resource_limite=true scope=both sid='*';
新建profile, 初始限制为1 ,用于测试。
create profile third_user limit SESSIONS_PER_USER 1 FAILED_LOGIN_ATTEMPTS unlimited;
alter user ryd_interface profile third_user;
将会话数调整到30
alter profile third_user limit SESSIONS_PER_USER 30;
通过以上操作,我们就可以实现这个需求了。
再想一下,这个实现方法真的完全满足要求了吗?
请见下文:Oracle用户访问权限与PUBLIC角色的关系(http://www.linuxidc.com/Linux/2012-06/62061.htm)