#pragma once #include #include #include #include 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