zoukankan      html  css  js  c++  java
  • Oracle定义者权限,调用者权限

    权限概述:

    定义者权限:定义者权限使用它所有者的权限,而不是当前用户来执行过程。因此,你可以限制用户执行的数据库操作,允许他们仅通过运行定义者权限的过程和函数访问数据。创建过程、函数和程序包的默认权限是定义者权限。
    调用者权限:在当前的用户模式下用当前的用户权限来执行过程。换句话说,就是调用者的权限过程并不与某个特定的用户或模式绑定。调用者权限程序可以使应用程序开发人员很容易的将应用逻辑集中起来,即使底层的数据在用户和模式中被划分。创建时需要显式使用AUTHID CURRENT_USER来定义调用者过程。

    演示:

    1、创建两个测试用户,并分别授权
    SQL> create user test1 identified by test1 ;
    User created.
    SQL> grant connect ,resource to test1;
    Grant succeeded.
    SQL> create user test2 identified by test2;
    User created.
    SQL> grant connect ,resource to test2;
    Grant succeeded.
    2、切换到用户Test1,创建过程
    过程一:定义者权限,为创建过程的默认权限
    TEST1@orcl _SQL>CREATE OR REPLACE PROCEDURE proc_definer IS
      2  BEGIN
      3    dbms_output.put_line('Current User :' || sys_context('userenv', 'current_user'));
      4    dbms_output.put_line('Session User :' || sys_context('userenv', 'session_user'));
      5    dbms_output.put_line('Current Schema :' || sys_context('userenv', 'current_schema'));
      6  END proc_definer;
      7  /
    
    Procedure created.
    过程二:调用者权限
    TEST1@orcl _SQL>CREATE OR REPLACE PROCEDURE proc_invoker AUTHID CURRENT_USER IS
      2  BEGIN
      3    dbms_output.put_line('Current User :' || sys_context('userenv', 'current_user'));
      4    dbms_output.put_line('Session User :' || sys_context('userenv', 'session_user'));
      5    dbms_output.put_line('Current Schema :' || sys_context('userenv', 'current_schema'));
      6  END proc_invoker;
      7  /
    
    Procedure created.
    3、查看这两个过程的权限
    TEST1@orcl _SQL>column object_name for a20
    TEST1@orcl _SQL>column authid for a20
    TEST1@orcl _SQL>select object_name , authid from user_procedures where object_name like '%PROC%';
    
    OBJECT_NAME	     AUTHID
    -------------------- --------------------
    PROC_INVOKER	     CURRENT_USER
    PROC_DEFINER	     DEFINER
    4、在TEST1下分别执行定义者权限和调用者权限过程
    TEST1@orcl _SQL>set serveroutput on
    TEST1@orcl _SQL>exec proc_definer;
    Current User :TEST1
    Session User :TEST1
    Current Schema :TEST1
    
    PL/SQL procedure successfully completed.
    
    TEST1@orcl _SQL>exec proc_invoker;
    Current User :TEST1
    Session User :TEST1
    Current Schema :TEST1
    
    PL/SQL procedure successfully completed.
    5、将TEST1的两个过程授权给TEST2
    TEST1@orcl _SQL>grant execute on proc_definer to test2;
    Grant succeeded.
    
    TEST1@orcl _SQL>grant execute on proc_invoker to test2;
    Grant succeeded.
    6、切换用户TEST2,测试,结果显示在调用者权限下,程序在当前用户下用当前用户的权限执行
    TEST2@orcl _SQL>set serveroutput on 
    TEST2@orcl _SQL>exec test1.proc_definer;
    Current User :TEST1
    Session User :TEST2
    Current Schema :TEST1
    
    PL/SQL procedure successfully completed.
    
    TEST2@orcl _SQL>exec test1.proc_invoker;
    Current User :TEST2
    Session User :TEST2
    Current Schema :TEST2
    
    PL/SQL procedure successfully completed.
    
    TEST2@orcl _SQL>

  • 相关阅读:
    解决 搭建Jekins过程中 启动Tomcat的java.net.UnknownHostException异常
    射手和农场主
    java 和 JS(javaScript)中的反斜杠正则转义
    分享修改密码的SharePoint Web part: ITaCS Change Password web part
    分享微软官方Demo用的SharePoint 2010, Exchange 2010, Lync 2010虚拟机
    Office 365 的公共网站的一些限制及解决的办法
    SharePoint 2013 关闭 customErrors
    安装 KB2844286 导致SharePoint 2010 XSLT web part 显示出现错误
    安装Office Web Apps Server 2013 – KB2592525安装失败
    如何将hyper-v虚拟机转换成vmware的虚拟机- 转换SharePoint 2010 Information Worker Demonstration and Evaluation Virtual Machine (SP1)
  • 原文地址:https://www.cnblogs.com/alen-liu-sz/p/12975728.html
Copyright © 2011-2022 走看看