Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to mention authID as current_user

Tags:

oracle

I'm mostly an oracle novice, so forgive me if this is a stupid question...

I have read lot of articles already on authID, My understanding is that AUTHID clause instructs Oracle as to whether the routine is to be run with the invoker's rights (CURRENT_USER), or with the Owner rights (DEFINER). If the clause is not specified, Oracle will default to using the AUTHID DEFINER.

Can you please give me a simple example for better understanding of authID?

like image 376
Wolfgang Avatar asked Nov 24 '15 15:11

Wolfgang


People also ask

What is the use of Authid Current_user?

AUTHID CURRENT_USER Specify CURRENT_USER to indicate that the package executes with the privileges of CURRENT_USER . This clause creates an invoker-rights package. This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of CURRENT_USER .

What is Authid clause?

The AUTHID clause of the package specification determines whether the subprograms and cursors in the package run with the privileges of their definer (the default) or invoker, and whether their unqualified references to schema objects are resolved in the schema of the definer or invoker.

What are invoker rights?

Invoker. rights is a new model for resolving references to database elements in a PL/SQL. program unit. From Oracle 8i onwards, we can decide if a program unit should. run with the authority of the definer or of the invoker.


1 Answers

Here the example:

User1 has DEPARTMENTS table.

User2 has DEPARTMENTS table also.

If we create this procedure within User2 schema

    -- Connected as User2    
    CREATE OR REPLACE PROCEDURE create_dept (

       v_deptno NUMBER,
       v_dname  VARCHAR2,
       v_mgr    NUMBER,
       v_loc    NUMBER) 
    AUTHID CURRENT_USER AS
    BEGIN
       INSERT INTO departments VALUES (v_deptno, v_dname, v_mgr, v_loc);
    END;
    /

Then , if we call this procedure - after give appropriate privileges- from User1,

-- Connected as User1
CALL create_dept(44, 'Information Technology', 200, 1700);

The record will be inserted on:

User1.DEPARTMENTS

Because procedure was executed AS CURRENT USER - User1 the caller.

If we omitted AUTHID CURRENT_USER when procedure was created, the record will be inserted on User2.DEPARTMENTS...as usual.

HTH

like image 185
Osy Avatar answered Nov 22 '22 19:11

Osy