Skip to content

Commit 4d2c36d

Browse files
committed
Refactor: Keep a reference to the serverContext in SaslTask
Change-Id: Ic24653fece3f507ca583489df67071cdb3a26a05 Reviewed-on: http://review.couchbase.org/100260 Tested-by: Build Bot <[email protected]> Reviewed-by: Daniel Owen <[email protected]>
1 parent 22b8d8a commit 4d2c36d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

daemon/sasl_tasks.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "mcaudit.h"
2222
#include "memcached.h"
2323
#include <cbsasl/mechanism.h>
24+
#include <cbsasl/server.h>
2425
#include <logger/logger.h>
2526
#include <memcached/rbac.h>
2627
#include <utilities/logtags.h>
@@ -31,6 +32,7 @@ SaslAuthTask::SaslAuthTask(Cookie& cookie_,
3132
const std::string& challenge_)
3233
: cookie(cookie_),
3334
connection(connection_),
35+
serverContext(connection_.getSaslConn()),
3436
mechanism(mechanism_),
3537
challenge(challenge_) {
3638
// no more init needed
@@ -44,8 +46,8 @@ void SaslAuthTask::notifyExecutionComplete() {
4446
false};
4547

4648
// If CBSASL generated a UUID, we should continue to use that UUID
47-
if (connection.getSaslConn().containsUuid()) {
48-
cookie.setEventId(connection.getSaslConn().getUuid());
49+
if (serverContext.containsUuid()) {
50+
cookie.setEventId(serverContext.getUuid());
4951
}
5052

5153
if (response.first == cb::sasl::Error::OK) {

daemon/sasl_tasks.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
class Connection;
2525
class Cookie;
2626

27+
namespace cb {
28+
namespace sasl {
29+
namespace server {
30+
class ServerContext;
31+
} // namespace server
32+
} // namespace sasl
33+
} // namespace cb
34+
2735
/**
2836
* The SaslAuthTask is the abstract base class used during SASL
2937
* authentication (which is being run by the executor service)
@@ -59,6 +67,7 @@ class SaslAuthTask : public Task {
5967
protected:
6068
Cookie& cookie;
6169
Connection& connection;
70+
cb::sasl::server::ServerContext& serverContext;
6271
std::string mechanism;
6372
std::string challenge;
6473
std::pair<cb::sasl::Error, cb::const_char_buffer> response{

daemon/start_sasl_auth_task.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "external_auth_manager_thread.h"
2222
#include "settings.h"
2323
#include <cbsasl/mechanism.h>
24+
#include <cbsasl/server.h>
2425
#include <logger/logger.h>
2526

2627
StartSaslAuthTask::StartSaslAuthTask(Cookie& cookie_,
@@ -41,7 +42,7 @@ Task::Status StartSaslAuthTask::execute() {
4142

4243
Task::Status StartSaslAuthTask::internal_auth() {
4344
connection.restartAuthentication();
44-
auto& server = connection.getSaslConn();
45+
auto& server = serverContext;
4546

4647
try {
4748
if (connection.isSslEnabled()) {
@@ -92,7 +93,7 @@ Task::Status StartSaslAuthTask::external_auth() {
9293

9394
bool StartSaslAuthTask::onlyRequestExternalAuthentication() {
9495
try {
95-
cb::rbac::createInitialContext(connection.getSaslConn().getUsername(),
96+
cb::rbac::createInitialContext(serverContext.getUsername(),
9697
cb::rbac::Domain::External);
9798
return true;
9899
} catch (const std::exception&) {
@@ -116,7 +117,7 @@ void StartSaslAuthTask::externalAuthResponse(cb::mcbp::Status status,
116117
void StartSaslAuthTask::successfull_external_auth() {
117118
try {
118119
response.first = cb::sasl::Error::OK;
119-
connection.getSaslConn().setDomain(cb::sasl::Domain::External);
120+
serverContext.setDomain(cb::sasl::Domain::External);
120121
} catch (const std::exception& e) {
121122
LOG_WARNING(R"({} successfull_external_auth() failed. UUID[{}] "{}")",
122123
connection.getId(),

0 commit comments

Comments
 (0)