Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

New implementation of the gRPC set, get and authorize. #287

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions kuksa-val-server/include/AccessChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
#define __ACCESSCHECKER_H__

#include "IAccessChecker.hpp"
#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

class IAuthenticator;


class AccessChecker : public IAccessChecker {
private:
std::shared_ptr<IAuthenticator> tokenValidator;
bool checkSignalAccess(const kuksa::kuksaChannel& channel, const std::string& path, const std::string& requiredPermission);
bool checkSignalAccess(const KuksaChannel& channel, const std::string& path, const std::string& requiredPermission);

public:
AccessChecker(std::shared_ptr<IAuthenticator> vdator);

bool checkReadAccess(kuksa::kuksaChannel &channel, const VSSPath &path) override;
bool checkReadAccess(KuksaChannel &channel, const VSSPath &path) override;

bool checkWriteAccess(kuksa::kuksaChannel &channel, const VSSPath &path) override;
bool checkWriteAccess(KuksaChannel &channel, const VSSPath &path) override;

bool checkPathWriteAccess(kuksa::kuksaChannel &channel, const jsoncons::json &paths) override;
bool checkPathWriteAccess(KuksaChannel &channel, const jsoncons::json &paths) override;
};

#endif
8 changes: 4 additions & 4 deletions kuksa-val-server/include/Authenticator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class Authenticator : public IAuthenticator {
string algorithm = "RS256";
std::shared_ptr<ILogger> logger;

int validateToken(kuksa::kuksaChannel& channel, string authToken);
int validateToken(KuksaChannel& channel, string authToken);

public:
Authenticator(std::shared_ptr<ILogger> loggerUtil, string secretkey, string algorithm);

int validate(kuksa::kuksaChannel &channel,
int validate(KuksaChannel &channel,
string authToken);

void updatePubKey(string key);
bool isStillValid(kuksa::kuksaChannel &channel);
void resolvePermissions(kuksa::kuksaChannel &channel);
bool isStillValid(KuksaChannel &channel);
void resolvePermissions(KuksaChannel &channel);

static string getPublicKeyFromFile(string fileName, std::shared_ptr<ILogger> logger);
};
Expand Down
41 changes: 0 additions & 41 deletions kuksa-val-server/include/GrpcConnection.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* Robert Bosch GmbH - initial API and functionality
* *****************************************************************************
*/
#ifndef __WSCHANNEL_H__
#define __WSCHANNEL_H__
#ifndef __KUKSA_CHANNEL_H__
#define __KUKSA_CHANNEL_H__

#include <stdint.h>
#include <jsoncons/json.hpp>
Expand All @@ -22,7 +22,7 @@ using namespace std;
using namespace jsoncons;
using jsoncons::json;

class WsChannel {
class KuksaChannel {
public:
enum class Type {
WEBSOCKET_PLAIN,
Expand Down
9 changes: 3 additions & 6 deletions kuksa-val-server/include/SubscriptionHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class VssDatabase;
class WsServer;
class ILogger;


using SubConnId = uint64_t;
using SubscriptionId = boost::uuids::uuid;

// Subscription ID: Client ID
struct UUIDHasher
{
Expand All @@ -57,7 +53,7 @@ struct UUIDHasher
return (uuid_hasher(k));
}
};
using subscriptions_t = std::unordered_map<SubscriptionId, SubConnId, UUIDHasher>;
using subscriptions_t = std::unordered_map<SubscriptionId, ConnectionId, UUIDHasher>;
using subscription_keys_t = struct subscription_keys {
std::string path;
std::string attribute;
Expand All @@ -84,6 +80,7 @@ struct SubscriptionKeyHasher {
class SubscriptionHandler : public ISubscriptionHandler {
private:
std::unordered_map<subscription_keys_t, subscriptions_t, SubscriptionKeyHasher> subscriptions;
std::unordered_map<subscription_keys_t, subscriptions_t, SubscriptionKeyHasher> grpcSubscriptions;

std::shared_ptr<ILogger> logger;
std::shared_ptr<IServer> server;
Expand All @@ -107,7 +104,7 @@ class SubscriptionHandler : public ISubscriptionHandler {
void addPublisher(std::shared_ptr<IPublisher> publisher){
publishers_.push_back(publisher);
}
SubscriptionId subscribe(kuksa::kuksaChannel& channel,
SubscriptionId subscribe(KuksaChannel& channel,
std::shared_ptr<IVssDatabase> db,
const std::string &path, const std::string& attr);
int unsubscribe(SubscriptionId subscribeID);
Expand Down
22 changes: 10 additions & 12 deletions kuksa-val-server/include/VssCommandProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "IVssCommandProcessor.hpp"
#include "VSSRequestValidator.hpp"
#include "WsChannel.hpp"
#include "KuksaChannel.hpp"
#include "IAccessChecker.hpp"

class IVssDatabase;
Expand All @@ -39,23 +39,21 @@ class VssCommandProcessor : public IVssCommandProcessor {
std::shared_ptr<IAccessChecker> accessValidator_;
VSSRequestValidator *requestValidator;

std::string processUpdateMetaData(kuksa::kuksaChannel& channel, jsoncons::json& request);
std::string processAuthorizeWithPermManager(kuksa::kuksaChannel &channel, const std::string & request_id,
std::string processUpdateMetaData(KuksaChannel& channel, jsoncons::json& request);
std::string processAuthorizeWithPermManager(KuksaChannel &channel, const std::string & request_id,
const std::string & client, const std::string& clientSecret);

std::string getPathFromRequest(const jsoncons::json &req, bool *gen1_compat);
std::string processUpdateVSSTree(kuksa::kuksaChannel& channel, jsoncons::json &request);
std::string processUpdateVSSTree(KuksaChannel& channel, jsoncons::json &request);

public:
std::string processGetMetaData(jsoncons::json &request);
std::string processAuthorize(kuksa::kuksaChannel& channel, const std::string & request_id,
std::string processAuthorize(KuksaChannel& channel, const std::string & request_id,
const std::string & token);
std::string processGet2(kuksa::kuksaChannel &channel, jsoncons::json &request);
std::string processSet2(kuksa::kuksaChannel &channel, jsoncons::json &request);
std::string processGetTarget(kuksa::kuksaChannel &channel, jsoncons::json &request);
std::string processSetTarget(kuksa::kuksaChannel &channel, jsoncons::json &request);
std::string processSubscribe(kuksa::kuksaChannel& channel, jsoncons::json &request);
std::string processUnsubscribe(kuksa::kuksaChannel &channel, jsoncons::json &request);
std::string processGet2(KuksaChannel &channel, jsoncons::json &request);
std::string processSet2(KuksaChannel &channel, jsoncons::json &request);
std::string processSubscribe(KuksaChannel& channel, jsoncons::json &request);
std::string processUnsubscribe(KuksaChannel &channel, jsoncons::json &request);

VssCommandProcessor(std::shared_ptr<ILogger> loggerUtil,
std::shared_ptr<IVssDatabase> database,
Expand All @@ -64,7 +62,7 @@ class VssCommandProcessor : public IVssCommandProcessor {
std::shared_ptr<ISubscriptionHandler> subhandler);
~VssCommandProcessor();

std::string processQuery(const std::string &req_json, kuksa::kuksaChannel& channel);
std::string processQuery(const std::string &req_json, KuksaChannel& channel);
};

#endif
4 changes: 2 additions & 2 deletions kuksa-val-server/include/VssDatabase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class VssDatabase : public IVssDatabase {


void updateJsonTree(jsoncons::json& sourceTree, const jsoncons::json& jsonTree);
void updateJsonTree(kuksa::kuksaChannel& channel, jsoncons::json& value) override;
void updateMetaData(kuksa::kuksaChannel& channel, const VSSPath& path, const jsoncons::json& newTree) override;
void updateJsonTree(KuksaChannel& channel, jsoncons::json& value) override;
void updateMetaData(KuksaChannel& channel, const VSSPath& path, const jsoncons::json& newTree) override;
jsoncons::json getMetaData(const VSSPath& path) override;

jsoncons::json setSignal(const VSSPath &path, const std::string& attr, jsoncons::json &value) override; //gen2 version
Expand Down
4 changes: 2 additions & 2 deletions kuksa-val-server/include/WebSockHttpFlexServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define __WEBSOCKHTTPFLEXSERVER_H__

#include "IServer.hpp"
#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

#include <boost/asio/ssl/context.hpp>
#include <vector>
Expand Down Expand Up @@ -63,7 +63,7 @@ class WebSockHttpFlexServer : public IServer {
* @param channel Connection identifier
* @return Response JSON message for client
*/
std::string HandleRequest(const std::string &req_json, kuksa::kuksaChannel &channel);
std::string HandleRequest(const std::string &req_json, KuksaChannel &channel);
public:
WebSockHttpFlexServer(std::shared_ptr<ILogger> loggerUtil,
std::shared_ptr<IRestHandler> rest2jsonUtil);
Expand Down
8 changes: 4 additions & 4 deletions kuksa-val-server/include/interface/IAccessChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
#include <jsoncons/json.hpp>

#include "VSSPath.hpp"
#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

class IAccessChecker {
public:
virtual ~IAccessChecker() {}

virtual bool checkPathWriteAccess(kuksa::kuksaChannel &channel, const jsoncons::json &paths) = 0;
virtual bool checkReadAccess(kuksa::kuksaChannel &channel, const VSSPath &path) = 0;
virtual bool checkWriteAccess(kuksa::kuksaChannel &channel, const VSSPath &path) = 0;
virtual bool checkPathWriteAccess(KuksaChannel &channel, const jsoncons::json &paths) = 0;
virtual bool checkReadAccess(KuksaChannel &channel, const VSSPath &path) = 0;
virtual bool checkWriteAccess(KuksaChannel &channel, const VSSPath &path) = 0;


};
Expand Down
8 changes: 4 additions & 4 deletions kuksa-val-server/include/interface/IAuthenticator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <memory>
#include <string>

#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

using namespace std;

Expand All @@ -27,11 +27,11 @@ class IAuthenticator {
public:
virtual ~IAuthenticator() {}

virtual int validate(kuksa::kuksaChannel &channel,
virtual int validate(KuksaChannel &channel,
string authToken) = 0;
virtual void updatePubKey(string key) = 0;
virtual bool isStillValid(kuksa::kuksaChannel &channel) = 0;
virtual void resolvePermissions(kuksa::kuksaChannel &channel) = 0;
virtual bool isStillValid(KuksaChannel &channel) = 0;
virtual void resolvePermissions(KuksaChannel &channel) = 0;
};

#endif
4 changes: 2 additions & 2 deletions kuksa-val-server/include/interface/ISubscriptionHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "IServer.hpp"
#include "VSSPath.hpp"

#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

class VssDatabase;
class WsServer;
Expand All @@ -35,7 +35,7 @@ class ISubscriptionHandler {
public:
virtual ~ISubscriptionHandler() {}

virtual SubscriptionId subscribe(kuksa::kuksaChannel& channel,
virtual SubscriptionId subscribe(KuksaChannel& channel,
std::shared_ptr<IVssDatabase> db,
const std::string &path, const std::string& attr) = 0;
virtual int unsubscribe(SubscriptionId subscribeID) = 0;
Expand Down
4 changes: 2 additions & 2 deletions kuksa-val-server/include/interface/IVssCommandProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string>

#include <jsoncons/json.hpp>
#include "kuksa.pb.h"
#include "KuksaChannel.hpp"

/**
* @class IVssCommandProcessor
Expand All @@ -37,7 +37,7 @@ class IVssCommandProcessor {
* @return JSON formated response string
*/
virtual std::string processQuery(const std::string &req_json,
kuksa::kuksaChannel& channel) = 0;
KuksaChannel& channel) = 0;
};

#endif
6 changes: 3 additions & 3 deletions kuksa-val-server/include/interface/IVssDatabase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#include <jsoncons/json.hpp>
#include <boost/filesystem.hpp>

#include "kuksa.pb.h"
#include "KuksaChannel.hpp"
#include "VSSPath.hpp"

class IVssDatabase {
public:
virtual ~IVssDatabase() {}

virtual void initJsonTree(const boost::filesystem::path &fileName) = 0;
virtual void updateJsonTree(kuksa::kuksaChannel& channel, jsoncons::json& value) = 0;
virtual void updateMetaData(kuksa::kuksaChannel& channel, const VSSPath& path, const jsoncons::json& value) = 0;
virtual void updateJsonTree(KuksaChannel& channel, jsoncons::json& value) = 0;
virtual void updateMetaData(KuksaChannel& channel, const VSSPath& path, const jsoncons::json& value) = 0;
virtual jsoncons::json getMetaData(const VSSPath &path) = 0;

virtual jsoncons::json setSignal(const VSSPath &path, const std::string& attr, jsoncons::json &value) = 0; //gen2 version
Expand Down
Loading