rublon-ssh/PAM/ssh/include/rublon/authentication_step_interface.hpp
Bartosz Wieczorek 700845e17a refactor
2023-08-22 13:34:40 +02:00

64 lines
2.4 KiB
C++

#pragma once
#include <rublon/pam.hpp>
#include <rublon/pam_action.hpp>
#include <rublon/core_handler_interface.hpp>
#include <rublon/utils.hpp>
namespace rublon {
template < typename Impl >
class AuthenticationStep {
protected:
std::string _systemToken;
std::string _tid;
public:
AuthenticationStep() {}
AuthenticationStep(std::string systemToken, std::string tid) : _systemToken{std::move(systemToken)}, _tid{std::move(tid)} {}
template < typename Handler_t >
auto fire(const CoreHandlerInterface< Handler_t > & coreHandler) const {
log(LogLevel::Info, "Starting %s step", static_cast< const Impl * >(this)->name);
return static_cast< const Impl * >(this)->handle(coreHandler);
}
template < typename Handler_t, typename PamInfo_t = LinuxPam >
auto fire(const CoreHandlerInterface< Handler_t > & coreHandler, const PamInfo_t & pam) const {
log(LogLevel::Info, "Starting %s step", static_cast< const Impl * >(this)->name);
return static_cast< const Impl * >(this)->handle(coreHandler, pam);
}
protected:
void addSystemToken(Document & body, RapidJSONPMRAlloc & alloc) const {
body.AddMember("systemToken", Value{this->_systemToken.c_str(), alloc}, alloc);
}
void addTid(Document & body, RapidJSONPMRAlloc & alloc) const {
body.AddMember("tid", Value{this->_tid.c_str(), alloc}, alloc);
}
template < typename HandlerReturn_t >
Error coreErrorHandler(const HandlerReturn_t & /*coreResponse*/) const {
// switch(coreResponse.error().errorClass) {
// case CoreHandlerError::ErrorClass::BadSigature:
// log(LogLevel::Error, "ErrorClass::BadSigature");
// return PamAction::decline;
// case CoreHandlerError::ErrorClass::CoreException: /// TODO exception handling
// log(LogLevel::Error, "ErrorClass::CoreException");
// return PamAction::decline; /// TODO accept?
// case CoreHandlerError::ErrorClass::ConnectionError:
// log(LogLevel::Error, "ErrorClass::ConnectionError");
// return PamAction::decline; /// TODO decline?
// case CoreHandlerError::ErrorClass::BrokenData:
// log(LogLevel::Error, "ErrorClass::BrokenData");
// return PamAction::decline;
// }
// return PamAction::decline;
return Error{Critical{}};
}
};
} // namespace rublon