Commit 3e1c82a0 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Minor refactoring for authorization check

parent 486d7cdb
......@@ -67,12 +67,7 @@ QuarkDBNode::QuarkDBNode(const Configuration &config, const RaftTimeouts &t,
bootEnd = std::chrono::steady_clock::now();
}
LinkStatus QuarkDBNode::dispatch(Connection *conn, RedisRequest &req) {
// Authentication command?
if(req.getCommandType() == CommandType::AUTHENTICATION) {
return authDispatcher.dispatch(conn, req);
}
bool QuarkDBNode::isAuthenticated(Connection *conn) const {
// Always permit access if:
// - No password is set. (duh)
// - Link is from localhost, AND we don't require that all localhost connections be authenticated.
......@@ -80,8 +75,17 @@ LinkStatus QuarkDBNode::dispatch(Connection *conn, RedisRequest &req) {
conn->authorization = true;
}
return conn->authorization;
}
LinkStatus QuarkDBNode::dispatch(Connection *conn, RedisRequest &req) {
// Authentication command?
if(req.getCommandType() == CommandType::AUTHENTICATION) {
return authDispatcher.dispatch(conn, req);
}
// We need to be authenticated past this point. Are we?
if(!conn->authorization) {
if(!isAuthenticated(conn)) {
return conn->noauth("Authentication required.");
}
......
......@@ -63,6 +63,8 @@ public:
}
private:
bool isAuthenticated(Connection *conn) const;
std::unique_ptr<ShardDirectory> shardDirectoryOwnership;
std::unique_ptr<Shard> shard;
......
......@@ -30,11 +30,11 @@ namespace quarkdb {
class QuarkDBNode;
class AuthenticationDispatcher : public Dispatcher {
class AuthenticationDispatcher {
public:
AuthenticationDispatcher(const std::string &secret);
virtual LinkStatus dispatch(Connection *conn, RedisRequest &req) override final;
LinkStatus dispatch(Connection *conn, RedisRequest &req);
RedisEncodedResponse dispatch(const RedisRequest &req, bool &authorized, std::unique_ptr<Authenticator> &authenticator);
private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment