Skip to content

Commit 8a1d1ca

Browse files
committed
Add support for external authentication
1 parent c20c07d commit 8a1d1ca

File tree

6 files changed

+95
-35
lines changed

6 files changed

+95
-35
lines changed

src/dpi/include/dpiEnv.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ class Env
8686
int poolMax = -1, int poolMin = -1,
8787
int poolIncrement = -1,
8888
int poolTimeout = -1,
89-
int stmtCacheSize = -1) = 0;
89+
int stmtCacheSize = -1,
90+
bool isExternalAuth = false) = 0;
9091

9192
virtual Conn * getConnection(const string &user, const string &password,
9293
const string &connString,
9394
int stmtCacheSize,
94-
const string &connClass = "") = 0;
95+
const string &connClass = "",
96+
bool isExternalAuth = false) = 0;
9597

96-
// DateTime array.
97-
virtual DateTimeArray* getDateTimeArray( OCIError *errh ) const = 0;
98-
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const = 0;
98+
// DateTime array
99+
virtual DateTimeArray * getDateTimeArray( OCIError *errh ) const = 0;
100+
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const = 0;
99101

100102
protected:
101103
// clients cannot do new and delete

src/dpi/src/dpiEnvImpl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ bool EnvImpl::isEventEnabled() const
469469
SPool * EnvImpl::createPool(const string &user, const string &password,
470470
const string &connString,
471471
int poolMax, int poolMin, int poolIncrement,
472-
int poolTimeout, int stmtCacheSize)
472+
int poolTimeout, int stmtCacheSize,
473+
bool isExternalAuth)
473474
{
474475
return new PoolImpl(this, envh_, user, password, connString,
475476
(poolMax == -1) ? poolMax_ : poolMax,
@@ -478,9 +479,9 @@ SPool * EnvImpl::createPool(const string &user, const string &password,
478479
poolIncrement,
479480
(poolTimeout == -1) ? poolTimeout_ :
480481
poolTimeout,
481-
isExternalAuth_,
482+
isExternalAuth,
482483
(stmtCacheSize == -1) ? stmtCacheSize_ :
483-
stmtCacheSize);
484+
stmtCacheSize);
484485
}
485486

486487

@@ -502,9 +503,10 @@ SPool * EnvImpl::createPool(const string &user, const string &password,
502503

503504
Conn * EnvImpl::getConnection(const string &user, const string &password,
504505
const string &connString,
505-
int stmtCacheSize, const string &connClass)
506+
int stmtCacheSize, const string &connClass,
507+
bool isExternalAuth)
506508
{
507-
return (Conn *)new ConnImpl(this, envh_, isExternalAuth_,
509+
return (Conn *)new ConnImpl(this, envh_, isExternalAuth,
508510
(stmtCacheSize == -1) ? stmtCacheSize_ :
509511
stmtCacheSize,
510512
user, password,

src/dpi/src/dpiEnvImpl.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,24 @@ class EnvImpl : public Env
9292
// interface methods
9393
virtual SPool * createPool(const string &user, const string &password,
9494
const string &connString,
95-
int poolMax = -1, int poolMin = -1,
96-
int poolIncrement = -1,
97-
int poolTimeout = -1,
98-
int stmtCacheSize = -1);
95+
int poolMax, int poolMin,
96+
int poolIncrement,
97+
int poolTimeout,
98+
int stmtCacheSize,
99+
bool isExternalAuth);
99100

100101
virtual Conn * getConnection(const string &user, const string &password,
101102
const string &connString, int stmtCacheSize,
102-
const string &connClass);
103+
const string &connClass,
104+
bool isExternalAuth);
105+
103106

104107
// internal methods
105108
virtual void terminatePool(PoolImpl *pool);
106109

107110
virtual void releaseConnection(ConnImpl *conn);
108111

109-
// DateTime array.
112+
// DateTime array
110113
virtual DateTimeArray* getDateTimeArray ( OCIError *errh ) const ;
111114
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const ;
112115

src/dpi/src/dpiPoolImpl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ using namespace std;
6060

6161

6262
/*****************************************************************************/
63-
/*
63+
/*
6464
DESCRIPTION
6565
Constructor for the PoolImpl class.
6666
@@ -91,7 +91,9 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
9191
try : env_(env), isExternalAuth_(isExternalAuth), envh_(envh), errh_(NULL),
9292
spoolh_(NULL), poolName_(NULL)
9393
{
94-
unsigned int spoolMode = OCI_SPOOL_ATTRVAL_NOWAIT;
94+
ub4 mode = isExternalAuth ? OCI_DEFAULT : OCI_SPC_HOMOGENEOUS;
95+
96+
unsigned char spoolMode = OCI_SPOOL_ATTRVAL_NOWAIT; // spoolMode is a ub1
9597

9698
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&errh_,
9799
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh_);
@@ -108,7 +110,7 @@ PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
108110
(OraText *)user.data (), (ub4) user.length(),
109111
(OraText *)password.data (),
110112
(ub4) password.length(),
111-
OCI_SPC_HOMOGENEOUS), errh_ );
113+
mode), errh_ );
112114

113115
this->poolTimeout(poolTimeout);
114116
this->stmtCacheSize(stmtCacheSize);

src/njs/src/njsOracle.cpp

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ Persistent<FunctionTemplate> Oracledb::oracledbTemplate_s;
4646
*/
4747
Oracledb::Oracledb()
4848
{
49-
dpienv_ = dpi::Env::createEnv();
50-
outFormat_ = ROWS_ARRAY;
51-
maxRows_ = MAX_ROWS;
52-
isAutoCommit_ = false;
53-
stmtCacheSize_ = STMT_CACHE_SIZE;
54-
poolMax_ = POOL_MAX;
55-
poolMin_ = POOL_MIN;
56-
poolIncrement_ = POOL_INCR;
57-
poolTimeout_ = POOL_TIMEOUT;
58-
connClass_ = "";
49+
dpienv_ = dpi::Env::createEnv();
50+
outFormat_ = ROWS_ARRAY;
51+
maxRows_ = MAX_ROWS;
52+
isAutoCommit_ = false;
53+
stmtCacheSize_ = STMT_CACHE_SIZE;
54+
poolMax_ = POOL_MAX;
55+
poolMin_ = POOL_MIN;
56+
poolIncrement_ = POOL_INCR;
57+
poolTimeout_ = POOL_TIMEOUT;
58+
connClass_ = "";
59+
isExternalAuth_ = false;
5960
}
6061

6162
/*****************************************************************************/
@@ -130,6 +131,10 @@ void Oracledb::Init(Handle<Object> target)
130131
String::New("connectionClass"),
131132
Oracledb::GetConnectionClass,
132133
Oracledb::SetConnectionClass );
134+
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
135+
String::New("isExternalAuth"),
136+
Oracledb::GetIsExternalAuth,
137+
Oracledb::SetIsExternalAuth );
133138

134139

135140
target->Set(String::New("Oracledb"),oracledbTemplate_s->GetFunction());
@@ -433,6 +438,35 @@ void Oracledb::SetConnectionClass (Local<String> property, Local<Value> value,
433438

434439
/*****************************************************************************/
435440
/*
441+
DESCRIPTION
442+
Get Accessor of isExternalAuth property
443+
*/
444+
Handle<Value> Oracledb::GetIsExternalAuth ( Local<String> property,
445+
const AccessorInfo& info )
446+
{
447+
HandleScope scope;
448+
449+
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
450+
Handle<Boolean> value = v8::Boolean::New(oracledb->isExternalAuth_);
451+
return scope.Close(value);
452+
}
453+
454+
/*****************************************************************************/
455+
/*
456+
DESCRIPTION
457+
Set Accessor of isExternalAuth property
458+
*/
459+
void Oracledb::SetIsExternalAuth ( Local<String> property, Local<Value> value,
460+
const AccessorInfo& info )
461+
{
462+
HandleScope scope;
463+
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
464+
oracledb->isExternalAuth_ = value->ToBoolean()->Value();
465+
}
466+
467+
468+
/*****************************************************************************/
469+
/*
436470
DESCRIPTION
437471
Get Connection method on Oracledb class.
438472
@@ -462,11 +496,17 @@ Handle<Value> Oracledb::GetConnection(const Arguments& args)
462496
NJS_GET_STRING_FROM_JSON ( connBaton->connStr, connBaton->error,
463497
connProps, "connectString", 0, exitGetConnection );
464498

465-
connBaton->stmtCacheSize = oracledb->stmtCacheSize_;
466-
connBaton->connClass = oracledb->connClass_;
467-
499+
connBaton->stmtCacheSize = oracledb->stmtCacheSize_;
500+
connBaton->connClass = oracledb->connClass_;
501+
connBaton->isExternalAuth = oracledb->isExternalAuth_;
502+
503+
// the above properties may be overriden if provided as call parameters
504+
468505
NJS_GET_UINT_FROM_JSON ( connBaton->stmtCacheSize, connBaton->error,
469506
connProps, "stmtCacheSize", 0, exitGetConnection );
507+
NJS_GET_BOOL_FROM_JSON ( connBaton->isExternalAuth, connBaton->error,
508+
connProps, "isExternalAuth", 0, exitGetConnection );
509+
470510
connBaton->oracledb = oracledb;
471511
connBaton->dpienv = oracledb->dpienv_;
472512

@@ -503,7 +543,8 @@ void Oracledb::Async_GetConnection (uv_work_t *req)
503543
connBaton->pswrd,
504544
connBaton->connStr,
505545
connBaton->stmtCacheSize,
506-
connBaton->connClass );
546+
connBaton->connClass,
547+
connBaton->isExternalAuth );
507548

508549
}
509550
catch (dpi::Exception& e)
@@ -592,6 +633,7 @@ Handle<Value> Oracledb::CreatePool (const Arguments &args)
592633
poolBaton->poolIncrement = oracledb->poolIncrement_;
593634
poolBaton->poolTimeout = oracledb->poolTimeout_;
594635
poolBaton->stmtCacheSize = oracledb->stmtCacheSize_;
636+
poolBaton->isExternalAuth = oracledb->isExternalAuth_;
595637

596638
NJS_GET_UINT_FROM_JSON ( poolBaton->poolMax, poolBaton->error,
597639
poolProps, "poolMax", 0, exitCreatePool );
@@ -603,6 +645,8 @@ Handle<Value> Oracledb::CreatePool (const Arguments &args)
603645
poolProps, "poolTimeout", 0, exitCreatePool );
604646
NJS_GET_UINT_FROM_JSON ( poolBaton->stmtCacheSize, poolBaton->error,
605647
poolProps, "stmtCacheSize", 0, exitCreatePool );
648+
NJS_GET_BOOL_FROM_JSON ( poolBaton->isExternalAuth, poolBaton->error,
649+
poolProps, "isExternalAuth", 0, exitGetConnection );
606650

607651
poolBaton->oracledb = oracledb;
608652
poolBaton->dpienv = oracledb->dpienv_;
@@ -645,7 +689,8 @@ void Oracledb::Async_CreatePool (uv_work_t *req)
645689
poolBaton->poolMin,
646690
poolBaton->poolIncrement,
647691
poolBaton->poolTimeout,
648-
poolBaton->stmtCacheSize );
692+
poolBaton->stmtCacheSize,
693+
poolBaton->isExternalAuth );
649694
}
650695
catch (dpi::Exception &e)
651696
{

src/njs/src/njsOracle.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class Oracledb: public ObjectWrap
102102
const AccessorInfo& info);
103103
static Handle<Value> GetConnectionClass (Local<String> property,
104104
const AccessorInfo& info );
105+
static Handle<Value> GetIsExternalAuth(Local<String> property,
106+
const AccessorInfo& info);
105107

106108
// Define Setter Accessors to Properties
107109
static void SetPoolMin(Local<String> property,Local<Value> value,
@@ -124,6 +126,8 @@ class Oracledb: public ObjectWrap
124126
const AccessorInfo& info);
125127
static void SetConnectionClass (Local<String> property, Local<Value> value,
126128
const AccessorInfo& info );
129+
static void SetIsExternalAuth(Local<String> property,Local<Value> value,
130+
const AccessorInfo& info);
127131

128132

129133
Oracledb();
@@ -142,6 +146,7 @@ class Oracledb: public ObjectWrap
142146
unsigned int poolTimeout_;
143147

144148
std::string connClass_;
149+
bool isExternalAuth_;
145150
};
146151

147152
/**
@@ -156,6 +161,7 @@ typedef struct connectionBaton
156161
std::string pswrd;
157162
std::string connStr;
158163
std::string connClass;
164+
bool isExternalAuth;
159165
std::string error;
160166

161167
int poolMax;
@@ -174,7 +180,7 @@ typedef struct connectionBaton
174180
Oracledb *oracledb;
175181

176182
connectionBaton() : user(""), pswrd(""), connStr(""), connClass(""),
177-
error("" ),
183+
isExternalAuth(false), error("" ),
178184
poolMax(0), poolMin(0), poolIncrement(0),
179185
poolTimeout(0), stmtCacheSize(0), maxRows(0),
180186
outFormat(0), dpienv(NULL),

0 commit comments

Comments
 (0)