ORA-1031 When Setting Attribute via DBMS_SESSION SET_CONTEXT

(Doc ID 100130.1)

Last updated on APRIL 18, 2017

Applies to:

Oracle Database - Enterprise Edition - Version 11.1.0.7 and later
Information in this document applies to any platform.
Checked for relevance on 11-Mar-2015


Symptoms

While setting a context attribute via the DBMS_SESSION.SET_CONTEXT procedure an ORA-1031 error is encountered:


SQL> CREATE CONTEXT m_context USING sec_user.p_context;
Context created

SQL> EXECUTE DBMS_SESSION.SET_CONTEXT('m_context','attr1','Hello');
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 55
ORA-06512: at line 1



SQL> begin
2 DBMS_SESSION.SET_CONTEXT('m_context','attr1','Hello');
3 end;
4 /
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SESSION", line 55
ORA-06512: at line 1



The user who executes these commands has all the necessary system privileges granted:



SQL> select * from dba_sys_privs where grantee='SCOTT';

GRANTEE      PRIVILEGE             ADM
-----------  -----------------     ----
SCOTT        DROP ANY CONTEXT      NO
SCOTT        CREATE ANY CONTEXT    NO
SCOTT        UNLIMITED TABLESPACE  NO
SCOTT        ALTER SESSION         NO




Changes

When you use a secure application context, it can only be changed with dbms_session if it is called from a package or procedure that is designated for this context when it was created. This is part of the security surrounding this feature. An arbitrary user or package may not change the context values, as these are often used to decide on VPD predicates from a policy function or other security features and procedures.

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms