rublon-ssh/PAM/ssh/include/rublon/authentication_step_interface.hpp
Bartosz Wieczorek e9b65c294e Fix tests
2023-08-01 15:44:23 +02:00

46 lines
1.6 KiB
C++

#pragma once
#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 step
log(Info, "Starting %s step", static_cast< const Impl * >(this)->name);
return static_cast< const Impl * >(this)->handle(coreHandler);
}
template < typename HandlerReturn_t >
PamAction 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;
}
}
};
} // namespace rublon