Skip to content

Commit

Permalink
Fixed bug resulting in error "ORA-25707: The token is invalid" when
Browse files Browse the repository at this point in the history
using IAM token based authentication and creating multiple pooled
connections.
  • Loading branch information
anthony-tuininga committed Oct 25, 2024
1 parent 1880a7d commit f453aee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
3 changes: 3 additions & 0 deletions doc/src/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Version 5.4.0 (TBD)
#) Added support for getting information about a connection in the structure
:ref:`dpiConnInfo<dpiConnInfo>` using the new method
:func:`dpiConn_getInfo()`.
#) Fixed bug resulting in error ``ORA-25707: The token is invalid`` when
using IAM token based authentication and creating multiple pooled
connections.
#) Fixed bug affecting Application Continuity with older Oracle Client
libraries by ensuring that the mode indicating bound REF CURSOR statement
handles are never re-used is only enabled with Oracle Client libraries 23.6
Expand Down
58 changes: 35 additions & 23 deletions src/dpiConn.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int dpiConn__getSession(dpiConn *conn, uint32_t mode,
static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
uint32_t handleType, const char *userName, uint32_t userNameLength,
const char *password, uint32_t passwordLength,
const dpiConnCreateParams *params, dpiError *error);
const dpiConnCreateParams *params, int *used, dpiError *error);
static int dpiConn__setShardingKey(dpiConn *conn, void **shardingKey,
void *handle, uint32_t handleType, uint32_t attribute,
const char *action, dpiShardingKeyColumn *columns, uint8_t numColumns,
Expand Down Expand Up @@ -453,6 +453,7 @@ static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
const dpiConnCreateParams *createParams, dpiError *error)
{
uint32_t credentialType, authMode;
int used = 0;

// mark the connection as a standalone connection
conn->standalone = 1;
Expand Down Expand Up @@ -498,7 +499,7 @@ static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
// populate attributes on the session handle
if (dpiConn__setAttributesFromCreateParams(conn, conn->sessionHandle,
DPI_OCI_HTYPE_SESSION, userName, userNameLength, password,
passwordLength, createParams, error) < 0)
passwordLength, createParams, &used, error) < 0)
return DPI_FAILURE;

// set the session handle on the service context handle
Expand Down Expand Up @@ -607,6 +608,7 @@ static int dpiConn__get(dpiConn *conn, const char *userName,
int externalAuth, status;
void *authInfo;
uint32_t mode;
int used = 0;

// clear pointers if length is 0
if (userNameLength == 0)
Expand Down Expand Up @@ -651,14 +653,15 @@ static int dpiConn__get(dpiConn *conn, const char *userName,
// set attributes for create parameters
if (dpiConn__setAttributesFromCreateParams(conn, authInfo,
DPI_OCI_HTYPE_AUTHINFO, userName, userNameLength, password,
passwordLength, createParams, error) < 0) {
passwordLength, createParams, &used, error) < 0) {
dpiOci__handleFree(authInfo, DPI_OCI_HTYPE_AUTHINFO);
return DPI_FAILURE;
}

// get a session from the pool
status = dpiConn__getSession(conn, mode, connectString,
connectStringLength, createParams, authInfo, error);
connectStringLength, createParams, (used) ? authInfo : NULL,
error);
dpiOci__handleFree(authInfo, DPI_OCI_HTYPE_AUTHINFO);
if (status < 0)
return status;
Expand Down Expand Up @@ -736,7 +739,6 @@ static int dpiConn__getHandles(dpiConn *conn, dpiError *error)
//-----------------------------------------------------------------------------
static int dpiConn__getInfo(dpiConn *conn, dpiError *error)
{
dpiConnInfo *info;
uint8_t temp8;

// if the cache has been populated and we are not using DRCP, no need to do
Expand Down Expand Up @@ -1168,33 +1170,41 @@ static int dpiConn__setAppContext(void *handle, uint32_t handleType,
static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
uint32_t handleType, const char *userName, uint32_t userNameLength,
const char *password, uint32_t passwordLength,
const dpiConnCreateParams *params, dpiError *error)
const dpiConnCreateParams *params, int *used, dpiError *error)
{
uint32_t purity;

// set credentials
if (userName && userNameLength > 0 && dpiOci__attrSet(handle,
handleType, (void*) userName, userNameLength,
DPI_OCI_ATTR_USERNAME, "set user name", error) < 0)
return DPI_FAILURE;
if (password && passwordLength > 0 && dpiOci__attrSet(handle,
handleType, (void*) password, passwordLength,
DPI_OCI_ATTR_PASSWORD, "set password", error) < 0)
return DPI_FAILURE;
if (userName && userNameLength > 0) {
if (dpiOci__attrSet(handle, handleType, (void*) userName,
userNameLength, DPI_OCI_ATTR_USERNAME, "set user name",
error) < 0)
return DPI_FAILURE;
*used = 1;
}
if (password && passwordLength > 0) {
if (dpiOci__attrSet(handle, handleType, (void*) password,
passwordLength, DPI_OCI_ATTR_PASSWORD, "set password",
error) < 0)
return DPI_FAILURE;
*used = 1;
}

// set connection class and purity parameters
if (params->connectionClass && params->connectionClassLength > 0 &&
dpiOci__attrSet(handle, handleType,
(void*) params->connectionClass,
params->connectionClassLength,
DPI_OCI_ATTR_CONNECTION_CLASS, "set connection class",
error) < 0)
return DPI_FAILURE;
if (params->connectionClass && params->connectionClassLength > 0) {
if (dpiOci__attrSet(handle, handleType,
(void*) params->connectionClass, params->connectionClassLength,
DPI_OCI_ATTR_CONNECTION_CLASS, "set connection class",
error) < 0)
return DPI_FAILURE;
*used = 1;
}
if (params->purity != DPI_OCI_ATTR_PURITY_DEFAULT) {
purity = params->purity;
if (dpiOci__attrSet(handle, handleType, &purity,
sizeof(purity), DPI_OCI_ATTR_PURITY, "set purity", error) < 0)
if (dpiOci__attrSet(handle, handleType, &purity, sizeof(purity),
DPI_OCI_ATTR_PURITY, "set purity", error) < 0)
return DPI_FAILURE;
*used = 1;
}

// set sharding key and super sharding key parameters
Expand All @@ -1204,6 +1214,7 @@ static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
params->shardingKeyColumns, params->numShardingKeyColumns,
error) < 0)
return DPI_FAILURE;
*used = 1;
}
if (params->superShardingKeyColumns &&
params->numSuperShardingKeyColumns > 0) {
Expand All @@ -1215,6 +1226,7 @@ static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
"set super sharding key", params->superShardingKeyColumns,
params->numSuperShardingKeyColumns, error) < 0)
return DPI_FAILURE;
*used = 1;
}

// set application context, if applicable
Expand Down

0 comments on commit f453aee

Please sign in to comment.