Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using appcontext with SessionPool #546

Open
ehaspulat opened this issue Mar 18, 2021 · 4 comments
Open

Using appcontext with SessionPool #546

ehaspulat opened this issue Mar 18, 2021 · 4 comments

Comments

@ehaspulat
Copy link

ehaspulat commented Mar 18, 2021

  1. What versions are you using?
cx_Oracle 8.0.1

>>> import sys
>>> import platform
>>> 
>>> print("platform.platform:", platform.platform())
platform.platform: Linux-4.18.0-193.29.1.el8_2.x86_64-x86_64-with-centos-7.9.2009-Core
>>> print("sys.maxsize > 2**32:", sys.maxsize > 2**32)
sys.maxsize > 2**32: True
>>> print("platform.python_version:", platform.python_version())
platform.python_version: 3.6.9

>>> import cx_Oracle
>>> print("cx_Oracle.version:", cx_Oracle.version)
cx_Oracle.version: 8.0.1
>>> print("cx_Oracle.clientversion:", cx_Oracle.clientversion())
cx_Oracle.clientversion: (19, 9, 0, 0, 0)
  1. Describe the problem

When I want to get a connection using cx_Oracle.connection(..., appcontext=CTX_ENTRIES), I succesfully see that context entries are applied.

But when I want to use a connection pool, I was unable to find a way to provide an appcontext.

So my question is, is there a way to provide appcontext when using SessionPool, such as:

pool = cx_Oracle.SessionPool(..., appcontext=CTX_ENTRIES)

@cjbj
Copy link
Member

cjbj commented Mar 19, 2021

There doesn't seem to be a direct way.

Is calling DBMS_SESSION.SET_CONTEXT in a pool sessionCallback function usable?

What are you using contexts for?

@ehaspulat
Copy link
Author

ehaspulat commented Mar 19, 2021

What are you using contexts for?

We have a LOGON TRIGGER on our production database that performs certain validations, one of them expecting the sys_context('USERENV', 'OS_USER') to be a certain value. Due to some operational challenges, I cannot rely on the username cx_Oracle resolves, and need to override it.

Is calling DBMS_SESSION.SET_CONTEXT in a pool sessionCallback function usable?

Since I cannot get past the logon trigger, I assumed the sessionCallback would not work. I've performed some tests now, and they did not work out for me.

What I tried was to create a simple all denying logon trigger like this one and use sessionCallback:

CREATE OR REPLACE TRIGGER test_logon_trigger
  AFTER LOGON
  ON SOME.SCHEMA
BEGIN
  raise_application_error(-20001, 'You cannot connect, your os_user is ' || sys_context('USERENV', 'OS_USER') || '');
END;
/

EDIT:
Just to give a better idea about the requirement I have, when using the JDBC driver we set -Doracle.jdbc.v$session.osuser=XXXXXX to override the required context. If there is a way to override this on oracle client level, maybe that would work out for me as well.

@Nermin-Rabieh
Copy link

Hello ,

were you able to resolve the issue? I am facing same case

Thanks

@ehaspulat
Copy link
Author

Hello ,

were you able to resolve the issue? I am facing same case

Thanks

Unfortunately no, not at the time of discussion. We went ahead with an internal workaround that is not relevant to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants