Ports the fewo-webapp AuthInterceptor + requireAdmin onto three abstract
interfaces so consumer apps plug in their own user store, public paths,
and runtime config without forking:
auth/AuthPrincipal.hpp library-owned {id, username, role} value
auth/IAuthBackend.hpp resolveBy{Session,ApiKey,Cert}, hasActiveUsers,
deleteExpiredSessions
auth/IAuthPolicy.hpp isPublicPath, adminRoles, readonlyRoles,
setupModeActive (defaults: admin/readonly,
no public paths, setup off)
auth/IRuntimeConfig.hpp bindAddress, isLoopback
auth/AuthInterceptor.hpp intercept() running the same 6-step ladder as
fewo's original (public → setup → cert DN →
session/API key → CSRF → readonly)
auth/RequireRole.hpp requireUser + requireAdmin helpers reading
bundle data (config-driven role sets, not
hard-coded 'admin')
TokenHasher is passed in so the library doesn't prescribe SHA-256 vs.
whatever. Bundle keys match fewo's existing controllers so the consumer
migration in #418 is a straightforward adapter swap.
Smoke-compiled against oatpp 1.3.0 headers.
Closes fewo-webapp#413
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
32 lines
954 B
C++
32 lines
954 B
C++
#ifndef OATPP_AUTHKIT_AUTH_IRUNTIME_CONFIG_HPP
|
|
#define OATPP_AUTHKIT_AUTH_IRUNTIME_CONFIG_HPP
|
|
|
|
#include <string>
|
|
|
|
namespace oatpp_authkit {
|
|
|
|
/**
|
|
* @brief Runtime config surface the interceptor needs.
|
|
*
|
|
* Small enough that consumers typically implement it inline against their
|
|
* existing Config globals. Provided as an interface rather than a struct
|
|
* so the values can change at runtime (e.g. bind address flipping during
|
|
* test setup) without restarting the interceptor.
|
|
*/
|
|
class IRuntimeConfig {
|
|
public:
|
|
virtual ~IRuntimeConfig() = default;
|
|
|
|
/** @brief Host the service is bound to ("127.0.0.1", "::1", "0.0.0.0", ...). */
|
|
virtual std::string bindAddress() = 0;
|
|
|
|
/** @brief Convenience: true iff `bindAddress()` is a loopback literal. */
|
|
virtual bool isLoopback() {
|
|
const std::string a = bindAddress();
|
|
return a == "127.0.0.1" || a == "::1" || a == "localhost";
|
|
}
|
|
};
|
|
|
|
} // namespace oatpp_authkit
|
|
|
|
#endif
|