Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable Local Authorization module #303

Merged
merged 2 commits into from
May 20, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- File index ([#270](https://github.com/matth-x/MicroOcpp/pull/270))
- Config `Cst_TxStartOnPowerPathClosed` to put back TxStartPoint ([#271](https://github.com/matth-x/MicroOcpp/pull/271))
- Build flag `MO_ENABLE_V16_RESERVATION=0` disables Reservation module ([#302](https://github.com/matth-x/MicroOcpp/pull/302))
- Build flag `MO_ENABLE_LOCAL_AUTH=0` disables LocalAuthList module ([#303](https://github.com/matth-x/MicroOcpp/pull/303))
- Function `bool isConnected()` in `Connection` interface ([#282](https://github.com/matth-x/MicroOcpp/pull/282))
- Build flags for customizing memory limits of SmartCharging ([#260](https://github.com/matth-x/MicroOcpp/pull/260))
- SConscript ([#287](https://github.com/matth-x/MicroOcpp/pull/287))
Expand Down
3 changes: 3 additions & 0 deletions src/MicroOcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
model.setConnectors(std::move(connectors));
model.setHeartbeatService(std::unique_ptr<HeartbeatService>(
new HeartbeatService(*context)));

#if MO_ENABLE_LOCAL_AUTH
model.setAuthorizationService(std::unique_ptr<AuthorizationService>(
new AuthorizationService(*context, filesystem)));
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
model.setReservationService(std::unique_ptr<ReservationService>(
Expand Down
6 changes: 6 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Model/Authorization/AuthorizationData.h>

using namespace MicroOcpp;
Expand Down Expand Up @@ -152,3 +156,5 @@ MicroOcpp::AuthorizationStatus MicroOcpp::deserializeAuthorizationStatus(const c
return AuthorizationStatus::UNDEFINED;
}
}

#endif //MO_ENABLE_LOCAL_AUTH
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef MO_AUTHORIZATIONDATA_H
#define MO_AUTHORIZATIONDATA_H

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Operations/CiStrings.h>
#include <MicroOcpp/Core/Time.h>
#include <ArduinoJson.h>
Expand Down Expand Up @@ -64,4 +68,5 @@ class AuthorizationData {

}

#endif //MO_ENABLE_LOCAL_AUTH
#endif
6 changes: 6 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Model/Authorization/AuthorizationList.h>
#include <MicroOcpp/Debug.h>

Expand Down Expand Up @@ -194,3 +198,5 @@ void AuthorizationList::writeJson(JsonArray authListOut, bool compact) {
size_t AuthorizationList::size() {
return localAuthorizationList.size();
}

#endif //MO_ENABLE_LOCAL_AUTH
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef MO_AUTHORIZATIONLIST_H
#define MO_AUTHORIZATIONLIST_H

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Model/Authorization/AuthorizationData.h>
#include <vector>

Expand Down Expand Up @@ -41,4 +45,5 @@ class AuthorizationList {

}

#endif //MO_ENABLE_LOCAL_AUTH
#endif
6 changes: 6 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
#include <MicroOcpp/Model/ConnectorBase/Connector.h>
#include <MicroOcpp/Core/FilesystemUtils.h>
Expand Down Expand Up @@ -192,3 +196,5 @@ void AuthorizationService::notifyAuthorization(const char *idTag, JsonObject idT
context.initiateRequest(std::move(statusNotification));
}
}

#endif //MO_ENABLE_LOCAL_AUTH
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/Authorization/AuthorizationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef MO_AUTHORIZATIONSERVICE_H
#define MO_AUTHORIZATIONSERVICE_H

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Model/Authorization/AuthorizationList.h>
#include <MicroOcpp/Core/FilesystemAdapter.h>
#include <MicroOcpp/Core/Configuration.h>
Expand Down Expand Up @@ -39,4 +43,5 @@ class AuthorizationService {

}

#endif //MO_ENABLE_LOCAL_AUTH
#endif
28 changes: 18 additions & 10 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,14 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {

MO_DBG_DEBUG("Begin transaction process (%s), prepare", idTag != nullptr ? idTag : "");

AuthorizationData *localAuth = nullptr;
bool localAuthFound = false;
const char *parentIdTag = nullptr; //locally stored parentIdTag
bool offlineBlockedAuth = false; //if offline authorization will be blocked by local auth list entry

//check local OCPP whitelist
if (model.getAuthorizationService()) {
localAuth = model.getAuthorizationService()->getLocalAuthorization(idTag);
#if MO_ENABLE_LOCAL_AUTH
if (auto authService = model.getAuthorizationService()) {
auto localAuth = authService->getLocalAuthorization(idTag);

//check authorization status
if (localAuth && localAuth->getAuthorizationStatus() != AuthorizationStatus::Accepted) {
Expand All @@ -611,21 +613,26 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
offlineBlockedAuth = true;
localAuth = nullptr;
}

if (localAuth) {
localAuthFound = true;
parentIdTag = localAuth->getParentIdTag();
}
}
#endif //MO_ENABLE_LOCAL_AUTH

int reservationId = -1;
bool offlineBlockedResv = false; //if offline authorization will be blocked by reservation

#if MO_ENABLE_V16_RESERVATION
//check if blocked by reservation
#if MO_ENABLE_V16_RESERVATION
if (model.getReservationService()) {
const char *parentIdTag = localAuth ? localAuth->getParentIdTag() : nullptr;

auto reservation = model.getReservationService()->getReservation(
connectorId,
idTag,
parentIdTag);

if (reservation) {
reservationId = reservation->getReservationId();
}
Expand All @@ -645,12 +652,14 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
} else {
//parentIdTag unkown but local authorization failed in any case
MO_DBG_INFO("connector %u reserved - no local auth", connectorId);
localAuth = nullptr;
localAuthFound = false;
}
}
}
#else
(void)parentIdTag;
#endif //MO_ENABLE_V16_RESERVATION

transaction = allocateTransaction();

if (!transaction) {
Expand All @@ -668,7 +677,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
transaction->setBeginTimestamp(model.getClock().now());

//check for local preauthorization
if (localAuth && localPreAuthorizeBool && localPreAuthorizeBool->getBool()) {
if (localAuthFound && localPreAuthorizeBool && localPreAuthorizeBool->getBool()) {
MO_DBG_DEBUG("Begin transaction process (%s), preauthorized locally", idTag != nullptr ? idTag : "");

if (reservationId >= 0) {
Expand Down Expand Up @@ -735,7 +744,6 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
});

//capture local auth and reservation check in for timeout handler
bool localAuthFound = localAuth;
authorize->setOnTimeoutListener([this, tx,
offlineBlockedAuth,
offlineBlockedResv,
Expand Down
4 changes: 4 additions & 0 deletions src/MicroOcpp/Model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void Model::setHeartbeatService(std::unique_ptr<HeartbeatService> hs) {
capabilitiesUpdated = true;
}

#if MO_ENABLE_LOCAL_AUTH
void Model::setAuthorizationService(std::unique_ptr<AuthorizationService> as) {
authorizationService = std::move(as);
capabilitiesUpdated = true;
Expand All @@ -172,6 +173,7 @@ void Model::setAuthorizationService(std::unique_ptr<AuthorizationService> as) {
AuthorizationService *Model::getAuthorizationService() {
return authorizationService.get();
}
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
void Model::setReservationService(std::unique_ptr<ReservationService> rs) {
Expand Down Expand Up @@ -283,12 +285,14 @@ void Model::updateSupportedStandardProfiles() {
}
}

#if MO_ENABLE_LOCAL_AUTH
if (authorizationService) {
if (!strstr(supportedFeatureProfilesString->getString(), "LocalAuthListManagement")) {
if (!buf.empty()) buf += ',';
buf += "LocalAuthListManagement";
}
}
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
if (reservationService) {
Expand Down
12 changes: 10 additions & 2 deletions src/MicroOcpp/Model/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ class MeteringService;
class FirmwareService;
class DiagnosticsService;
class HeartbeatService;
class AuthorizationService;
class BootService;
class ResetService;

#if MO_ENABLE_LOCAL_AUTH
class AuthorizationService;
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
class ReservationService;
#endif //MO_ENABLE_V16_RESERVATION
Expand Down Expand Up @@ -51,10 +54,13 @@ class Model {
std::unique_ptr<FirmwareService> firmwareService;
std::unique_ptr<DiagnosticsService> diagnosticsService;
std::unique_ptr<HeartbeatService> heartbeatService;
std::unique_ptr<AuthorizationService> authorizationService;
std::unique_ptr<BootService> bootService;
std::unique_ptr<ResetService> resetService;

#if MO_ENABLE_LOCAL_AUTH
std::unique_ptr<AuthorizationService> authorizationService;
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
std::unique_ptr<ReservationService> reservationService;
#endif //MO_ENABLE_V16_RESERVATION
Expand Down Expand Up @@ -113,8 +119,10 @@ class Model {

void setHeartbeatService(std::unique_ptr<HeartbeatService> heartbeatService);

#if MO_ENABLE_LOCAL_AUTH
void setAuthorizationService(std::unique_ptr<AuthorizationService> authorizationService);
AuthorizationService *getAuthorizationService();
#endif //MO_ENABLE_LOCAL_AUTH

#if MO_ENABLE_V16_RESERVATION
void setReservationService(std::unique_ptr<ReservationService> reservationService);
Expand Down
6 changes: 4 additions & 2 deletions src/MicroOcpp/Operations/Authorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ void Authorize::processConf(JsonObject payload){
MO_DBG_INFO("Request has been denied. Reason: %s", idTagInfo);
}

if (model.getAuthorizationService()) {
model.getAuthorizationService()->notifyAuthorization(idTag, payload["idTagInfo"]);
#if MO_ENABLE_LOCAL_AUTH
if (auto authService = model.getAuthorizationService()) {
authService->notifyAuthorization(idTag, payload["idTagInfo"]);
}
#endif //MO_ENABLE_LOCAL_AUTH
}

void Authorize::processReq(JsonObject payload){
Expand Down
6 changes: 6 additions & 0 deletions src/MicroOcpp/Operations/GetLocalListVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Operations/GetLocalListVersion.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
Expand Down Expand Up @@ -31,3 +35,5 @@ std::unique_ptr<DynamicJsonDocument> GetLocalListVersion::createConf(){
}
return doc;
}

#endif //MO_ENABLE_LOCAL_AUTH
6 changes: 6 additions & 0 deletions src/MicroOcpp/Operations/GetLocalListVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef MO_GETLOCALLISTVERSION_H
#define MO_GETLOCALLISTVERSION_H

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Core/Operation.h>

namespace MicroOcpp {
Expand All @@ -28,4 +32,6 @@ class GetLocalListVersion : public Operation {

} //end namespace Ocpp16
} //end namespace MicroOcpp

#endif //MO_ENABLE_LOCAL_AUTH
#endif
6 changes: 6 additions & 0 deletions src/MicroOcpp/Operations/SendLocalList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Operations/SendLocalList.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
Expand Down Expand Up @@ -64,3 +68,5 @@ std::unique_ptr<DynamicJsonDocument> SendLocalList::createConf(){

return doc;
}

#endif //MO_ENABLE_LOCAL_AUTH
6 changes: 6 additions & 0 deletions src/MicroOcpp/Operations/SendLocalList.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef MO_SENDLOCALLIST_H
#define MO_SENDLOCALLIST_H

#include <MicroOcpp/Version.h>

#if MO_ENABLE_LOCAL_AUTH

#include <MicroOcpp/Core/Operation.h>

namespace MicroOcpp {
Expand Down Expand Up @@ -35,4 +39,6 @@ class SendLocalList : public Operation {

} //end namespace Ocpp16
} //end namespace MicroOcpp

#endif //MO_ENABLE_LOCAL_AUTH
#endif
3 changes: 3 additions & 0 deletions src/MicroOcpp/Operations/StartTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <MicroOcpp/Model/Transactions/TransactionStore.h>
#include <MicroOcpp/Model/Transactions/Transaction.h>
#include <MicroOcpp/Debug.h>
#include <MicroOcpp/Version.h>

using MicroOcpp::Ocpp16::StartTransaction;

Expand Down Expand Up @@ -151,9 +152,11 @@ void StartTransaction::processConf(JsonObject payload) {
transaction->getStartSync().confirm();
transaction->commit();

#if MO_ENABLE_LOCAL_AUTH
if (auto authService = model.getAuthorizationService()) {
authService->notifyAuthorization(transaction->getIdTag(), payload["idTagInfo"]);
}
#endif //MO_ENABLE_LOCAL_AUTH
}

void StartTransaction::processReq(JsonObject payload) {
Expand Down
3 changes: 3 additions & 0 deletions src/MicroOcpp/Operations/StopTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <MicroOcpp/Model/Transactions/TransactionStore.h>
#include <MicroOcpp/Model/Transactions/Transaction.h>
#include <MicroOcpp/Debug.h>
#include <MicroOcpp/Version.h>

using MicroOcpp::Ocpp16::StopTransaction;

Expand Down Expand Up @@ -202,9 +203,11 @@ void StopTransaction::processConf(JsonObject payload) {

MO_DBG_INFO("Request has been accepted!");

#if MO_ENABLE_LOCAL_AUTH
if (auto authService = model.getAuthorizationService()) {
authService->notifyAuthorization(transaction->getIdTag(), payload["idTagInfo"]);
}
#endif //MO_ENABLE_LOCAL_AUTH
}

bool StopTransaction::processErr(const char *code, const char *description, JsonObject details) {
Expand Down
Loading
Loading