Skip to content

Commit 89d1a46

Browse files
Make externalauth a common parameter (which is optional for standalone
connections).
1 parent 4fa6509 commit 89d1a46

File tree

14 files changed

+248
-29
lines changed

14 files changed

+248
-29
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Thick Mode Changes
2323
#) Added support for getting the message id of the AQ message which generated
2424
a notification.
2525
#) Fixed the ability to use external authentication with connection pools.
26+
#) Added the ability to use `externalauth` as a connection parameter for
27+
standalone connections in addition to creating pools. For standalone
28+
connections, this parameter is optional.
2629

2730

2831
oracledb 1.0.1 (June 2022)

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ cdef class ConnectParamsImpl:
157157
public str user
158158
public str proxy_user
159159
public bint events
160+
public bint externalauth
160161
public uint32_t mode
161162
public str edition
162163
public list appcontext
@@ -201,7 +202,6 @@ cdef class PoolParamsImpl(ConnectParamsImpl):
201202
public type connectiontype
202203
public uint32_t getmode
203204
public bint homogeneous
204-
public bint externalauth
205205
public uint32_t timeout
206206
public uint32_t wait_timeout
207207
public uint32_t max_lifetime_session

src/oracledb/connect_params.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self, *,
7474
ssl_server_cert_dn: str=None,
7575
wallet_location: str=None,
7676
events: bool=False,
77+
externalauth: bool=False,
7778
mode: int=oracledb.AUTH_MODE_DEFAULT,
7879
disable_oob: bool=False,
7980
stmtcachesize: int=oracledb.defaults.stmtcachesize,
@@ -175,6 +176,9 @@ def __init__(self, *,
175176
query notification and high availability event notifications
176177
(default: False)
177178
179+
- externalauth: a boolean indicating whether to use external
180+
authentication (default: False)
181+
178182
- mode: authorization mode to use. For example
179183
oracledb.AUTH_MODE_SYSDBA (default: oracledb.AUTH_MODE_DEFAULT)
180184
@@ -246,6 +250,7 @@ def __repr__(self):
246250
f", ssl_server_cert_dn={self.ssl_server_cert_dn!r}" + \
247251
f", wallet_location={self.wallet_location!r}" + \
248252
f", events={self.events!r}" + \
253+
f", externalauth={self.externalauth!r}" + \
249254
f", mode={self.mode!r}" + \
250255
f", disable_oob={self.disable_oob!r}" + \
251256
f", stmtcachesize={self.stmtcachesize!r}" + \
@@ -356,6 +361,13 @@ def expire_time(self) -> Union[list, int]:
356361
"""
357362
return self._impl.expire_time
358363

364+
@property
365+
def externalauth(self) -> bool:
366+
"""
367+
A boolean indicating whether to use external authentication.
368+
"""
369+
return self._impl.externalauth
370+
359371
@property
360372
@_address_attr
361373
def host(self) -> Union[list, str]:
@@ -602,6 +614,7 @@ def set(self, *,
602614
ssl_server_cert_dn: str=None,
603615
wallet_location: str=None,
604616
events: bool=None,
617+
externalauth: bool=None,
605618
mode: int=None,
606619
disable_oob: bool=None,
607620
stmtcachesize: int=None,
@@ -697,6 +710,9 @@ def set(self, *,
697710
This value is only used in thick mode and is needed for continuous
698711
query notification and high availability event notifications
699712
713+
- externalauth: a boolean indicating whether to use external
714+
authentication
715+
700716
- mode: authorization mode to use. For example
701717
oracledb.AUTH_MODE_SYSDBA
702718

src/oracledb/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ def connect(dsn: str=None, *,
10351035

10361036
# other parameters
10371037
events: bool=None,
1038+
externalauth: bool=None,
10381039
mode: int=None,
10391040
disable_oob: bool=None,
10401041
stmtcachesize: int=None,

src/oracledb/impl/base/connect_params.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ cdef class ConnectParamsImpl:
154154
self._default_description.set_from_description_args(args)
155155
self._default_description.set_from_security_args(args)
156156
self._default_address.set_from_args(args)
157+
_set_bool_param(args, "externalauth", &self.externalauth)
157158

158159
cdef int _copy(self, ConnectParamsImpl other_params) except -1:
159160
"""
@@ -163,6 +164,7 @@ cdef class ConnectParamsImpl:
163164
self.user = other_params.user
164165
self.proxy_user = other_params.proxy_user
165166
self.events = other_params.events
167+
self.externalauth = other_params.externalauth
166168
self.mode = other_params.mode
167169
self.edition = other_params.edition
168170
self.appcontext = other_params.appcontext

src/oracledb/impl/base/pool_params.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ cdef class PoolParamsImpl(ConnectParamsImpl):
5252
self.connectiontype = pool_params.connectiontype
5353
self.getmode = pool_params.getmode
5454
self.homogeneous = pool_params.homogeneous
55-
self.externalauth = pool_params.externalauth
5655
self.timeout = pool_params.timeout
5756
self.wait_timeout = pool_params.wait_timeout
5857
self.max_lifetime_session = pool_params.max_lifetime_session
@@ -82,7 +81,6 @@ cdef class PoolParamsImpl(ConnectParamsImpl):
8281
self.connectiontype = args.get("connectiontype")
8382
_set_uint_param(args, "getmode", &self.getmode)
8483
_set_bool_param(args, "homogeneous", &self.homogeneous)
85-
_set_bool_param(args, "externalauth", &self.externalauth)
8684
_set_uint_param(args, "timeout", &self.timeout)
8785
_set_uint_param_with_deprecated_name(args, "wait_timeout",
8886
"waitTimeout", &self.wait_timeout)

src/oracledb/impl/thick/connection.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ cdef class ThickConnImpl(BaseConnImpl):
324324
_raise_from_odpi()
325325
if params.username_len == 0 and params.password_len == 0:
326326
conn_params.externalAuth = 1
327+
else:
328+
conn_params.externalAuth = user_params.externalauth
327329
if params.cclass is not None:
328330
conn_params.connectionClass = params.cclass_ptr
329331
conn_params.connectionClassLength = params.cclass_len

src/oracledb/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ def create_pool(dsn: str=None, *,
553553
connectiontype: Type["connection_module.Connection"]=None,
554554
getmode: int=None,
555555
homogeneous: bool=True,
556-
externalauth: bool=None,
557556
timeout: int=0,
558557
wait_timeout: int=0,
559558
max_lifetime_session: int=0,
@@ -590,6 +589,7 @@ def create_pool(dsn: str=None, *,
590589

591590
# other parameters
592591
events: bool=None,
592+
externalauth: bool=None,
593593
mode: int=None,
594594
disable_oob: bool=None,
595595
stmtcachesize: int=None,

src/oracledb/pool_params.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def __init__(self, *,
5757
connectiontype: Type["oracledb.Connection"]=None,
5858
getmode: int=oracledb.POOL_GETMODE_WAIT,
5959
homogeneous: bool=True,
60-
externalauth: bool=False,
6160
timeout: int=0,
6261
wait_timeout: int=0,
6362
max_lifetime_session: int=0,
@@ -88,6 +87,7 @@ def __init__(self, *,
8887
ssl_server_cert_dn: str=None,
8988
wallet_location: str=None,
9089
events: bool=False,
90+
externalauth: bool=False,
9191
mode: int=oracledb.AUTH_MODE_DEFAULT,
9292
disable_oob: bool=False,
9393
stmtcachesize: int=oracledb.defaults.stmtcachesize,
@@ -129,9 +129,6 @@ def __init__(self, *,
129129
homogeneous (same user) or heterogeneous (multiple users) (default:
130130
True)
131131
132-
- externalauth: a boolean indicating whether to use external
133-
authentication (default: False)
134-
135132
- timeout: length of time (in seconds) that a connection may remain
136133
idle in the pool before it is terminated. If it is 0 then connections
137134
are never terminated (default: 0)
@@ -243,6 +240,9 @@ def __init__(self, *,
243240
query notification and high availability event notifications
244241
(default: False)
245242
243+
- externalauth: a boolean indicating whether to use external
244+
authentication (default: False)
245+
246246
- mode: authorization mode to use. For example
247247
oracledb.AUTH_MODE_SYSDBA (default: oracledb.AUTH_MODE_DEFAULT)
248248
@@ -300,7 +300,6 @@ def __repr__(self):
300300
f", connectiontype={self.connectiontype!r}" + \
301301
f", getmode={self.getmode!r}" + \
302302
f", homogeneous={self.homogeneous!r}" + \
303-
f", externalauth={self.externalauth!r}" + \
304303
f", timeout={self.timeout!r}" + \
305304
f", wait_timeout={self.wait_timeout!r}" + \
306305
f", max_lifetime_session={self.max_lifetime_session!r}" + \
@@ -328,6 +327,7 @@ def __repr__(self):
328327
f", ssl_server_cert_dn={self.ssl_server_cert_dn!r}" + \
329328
f", wallet_location={self.wallet_location!r}" + \
330329
f", events={self.events!r}" + \
330+
f", externalauth={self.externalauth!r}" + \
331331
f", mode={self.mode!r}" + \
332332
f", disable_oob={self.disable_oob!r}" + \
333333
f", stmtcachesize={self.stmtcachesize!r}" + \
@@ -348,13 +348,6 @@ def connectiontype(self) -> Type["oracledb.Connection"]:
348348
"""
349349
return self._impl.connectiontype
350350

351-
@property
352-
def externalauth(self) -> bool:
353-
"""
354-
A boolean indicating whether to use external authentication.
355-
"""
356-
return self._impl.externalauth
357-
358351
@property
359352
def getmode(self) -> int:
360353
"""
@@ -473,7 +466,6 @@ def set(self, *,
473466
connectiontype: Type["oracledb.Connection"]=None,
474467
getmode: int=None,
475468
homogeneous: bool=None,
476-
externalauth: bool=None,
477469
timeout: int=None,
478470
wait_timeout: int=None,
479471
max_lifetime_session: int=None,
@@ -504,6 +496,7 @@ def set(self, *,
504496
ssl_server_cert_dn: str=None,
505497
wallet_location: str=None,
506498
events: bool=None,
499+
externalauth: bool=None,
507500
mode: int=None,
508501
disable_oob: bool=None,
509502
stmtcachesize: int=None,
@@ -541,9 +534,6 @@ def set(self, *,
541534
- homogeneous: a boolean indicating whether the connections are
542535
homogeneous (same user) or heterogeneous (multiple users)
543536
544-
- externalauth: a boolean indicating whether to use external
545-
authentication
546-
547537
- timeout: length of time (in seconds) that a connection may remain
548538
idle in the pool before it is terminated. If it is 0 then connections
549539
are never terminated
@@ -649,6 +639,9 @@ def set(self, *,
649639
This value is only used in thick mode and is needed for continuous
650640
query notification and high availability event notifications
651641
642+
- externalauth: a boolean indicating whether to use external
643+
authentication
644+
652645
- mode: authorization mode to use. For example
653646
oracledb.AUTH_MODE_SYSDBA
654647

tests/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ This directory contains the test suite for python-oracledb.
3434

3535
python drop_schema.py
3636

37+
4. Enable tests that require extra configuration
38+
39+
The following test(s) are automatically skipped if their required
40+
environment variable(s) and setup is not available.
41+
42+
4.1 test_5000_externalauth.py
43+
44+
This test aims to test the usage of external authentication.
45+
46+
- Set the PYO_TEST_EXTERNAL_USER environment variable to the externally
47+
identified user that will be connected using external authentication.
48+
49+
- Set up external authentication. See
50+
[Connecting Using External Authentication][4] for creating an
51+
Oracle Wallet or enabling OS authentication.
52+
53+
- Run the following SQL commands as a user with administrative
54+
privileges (such as SYSTEM or ADMIN) to allow the external user to
55+
connect to the database and behave as proxy for testing external
56+
authentication with proxy:
57+
58+
grant create session to <External User>;
59+
60+
alter user <Schema Owner> grant connect through <External User>;
61+
62+
3763
[1]: https://github.com/oracle/python-oracledb/blob/main/tests/create_schema.py
3864
[2]: https://github.com/oracle/python-oracledb/blob/main/tests/test_env.py
3965
[3]: https://github.com/oracle/python-oracledb/blob/main/tests/drop_schema.py
66+
[4]: https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connecting-using-external-authentication

0 commit comments

Comments
 (0)