22 crow::SimpleApp &app, std::shared_ptr<rest_server_context> ctx) {
25 CROW_ROUTE(app,
"/api/v1/security/users")
26 .methods(crow::HTTPMethod::POST)([ctx](
const crow::request &req) {
28 res.add_header(
"Content-Type",
"application/json");
30 if (!ctx->security_manager) {
32 "Security manager not configured");
37 auto x = crow::json::load(req.body);
44 if (!x.has(
"username") || !x.has(
"id")) {
52 user.
id = x[
"id"].s();
53 user.username = x[
"username"].s();
56 auto result = ctx->security_manager->create_user(user);
57 if (result.is_err()) {
59 "CREATE_FAILED",
"Failed to create user");
70 CROW_ROUTE(app,
"/api/v1/security/users/<string>/roles")
71 .methods(crow::HTTPMethod::POST)([ctx](
const crow::request &req,
72 std::string user_id) {
74 res.add_header(
"Content-Type",
"application/json");
76 if (!ctx->security_manager) {
78 "Security manager not configured");
83 auto x = crow::json::load(req.body);
84 if (!x || !x.has(
"role")) {
90 std::string role_str = x[
"role"].s();
98 auto result = ctx->security_manager->assign_role(user_id, *role_opt);
99 if (result.is_err()) {
std::optional< Role > parse_role(std::string_view str)
Parse Role from string.
void register_security_endpoints_impl(crow::SimpleApp &app, std::shared_ptr< rest_server_context > ctx)
Register security endpoints with the Crow app.
std::string make_error_json(std::string_view code, std::string_view message)
Create JSON error response body with details.
std::string make_success_json(std::string_view message="OK")
Create success response with optional message.
Common types and utilities for REST API.
Role definitions for RBAC.
Security API endpoints for REST server.
Represents a user in the system.
User definition for RBAC.