Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
dc96556
Begin auth-db module
joshusooyaa Jul 30, 2025
ea1cedd
Set up constructor for AuthDBInstance
joshusooyaa Jul 30, 2025
51d77c8
Fix log message
joshusooyaa Jul 30, 2025
5a249c6
Update cmake list
joshusooyaa Jul 30, 2025
043da1b
Merge branch 'develop' into auth-db
joshusooyaa Jul 30, 2025
e943529
Fix namespace typo
joshusooyaa Jul 30, 2025
3df4cbc
Add missing virtual function
joshusooyaa Jul 30, 2025
c98c9e6
Implement on_service_event
joshusooyaa Jul 30, 2025
81d009f
Finish AuthDBModule declarations
joshusooyaa Jul 31, 2025
ed068c4
Add config setup for AuthDB
joshusooyaa Jul 31, 2025
bc99773
Fix log for config setup
joshusooyaa Jul 31, 2025
26fb7d9
Refactor
joshusooyaa Aug 1, 2025
020946f
Add AuthResult struct
joshusooyaa Aug 1, 2025
e26839f
Start handle_bus_msg implementation
joshusooyaa Aug 4, 2025
3c3ad1e
Implement update_and_log_auth_result_msg
joshusooyaa Aug 4, 2025
c84e2ff
Implement handle_kernel_msg
joshusooyaa Aug 4, 2025
85164a8
Begin handle_auth implementation
joshusooyaa Aug 4, 2025
0d14b2e
Update handle_auth to pass by pointer
joshusooyaa Aug 4, 2025
218b2e9
Set up fetch credentials from database structure
joshusooyaa Aug 4, 2025
648f037
Implement get_user
joshusooyaa Aug 4, 2025
e286f54
Merge branch 'develop' into auth-db
joshusooyaa Aug 4, 2025
0dd4bf2
Fix compilation errors
joshusooyaa Aug 4, 2025
426ddd4
Implement find_credentials_by_card_id
joshusooyaa Aug 4, 2025
8ded91b
Build profile for authentication
joshusooyaa Aug 4, 2025
a9f3989
Implement is_access_granted
joshusooyaa Aug 4, 2025
8c086af
Add audit logging on auth event
joshusooyaa Aug 5, 2025
d54d4d9
Add state to lbgipod message handling
joshusooyaa Aug 6, 2025
3a2eb9c
Add noise filtering in authentication
joshusooyaa Aug 11, 2025
c93dd64
Update auth-db module readme
joshusooyaa Aug 11, 2025
8709cf2
Remove uncessary method
joshusooyaa Aug 11, 2025
1f23e6d
Add targets to authentication mapping
joshusooyaa Aug 12, 2025
b8396dc
Check users and groups for access
joshusooyaa Aug 12, 2025
4c97fbf
Fix EventType values for proper FlagSet indexing
joshusooyaa Aug 13, 2025
ede14e9
Remove required AuditEntry parent
joshusooyaa Aug 13, 2025
fc03be6
Merge branch 'libgpiod' into doorman-schedules
joshusooyaa Aug 18, 2025
7bf08d8
Add clear_schedules
joshusooyaa Aug 19, 2025
e5deec6
Begin db logic for door schedules
joshusooyaa Aug 19, 2025
e78964f
Fetch doors to configure schedule for
joshusooyaa Aug 19, 2025
d7d9c9b
Add open door schedules from db to doors
joshusooyaa Aug 19, 2025
9e9fa20
Begin logic for adding close door schedules
joshusooyaa Aug 20, 2025
249b5ad
Add 24_7 closed schedule to doors with no schedule
joshusooyaa Aug 20, 2025
90f67fd
Group and insert closed full days
joshusooyaa Aug 20, 2025
5ec1a77
Sort tf vector for future creation of closed schedule
joshusooyaa Aug 20, 2025
394d31f
Improve tf var name clarity
joshusooyaa Aug 20, 2025
e7498a2
Add closed timeframes to door schedule
joshusooyaa Aug 20, 2025
8ad4d7e
Log door open and closed schedules
joshusooyaa Aug 20, 2025
cdf1441
Refresh schedules every 60 seconds
joshusooyaa Aug 20, 2025
14e7118
Fix closed tfs not adding correctly
joshusooyaa Aug 20, 2025
697fec1
Adjust closed timeframe start/end times
joshusooyaa Aug 20, 2025
ad478c8
Set logging level through config
joshusooyaa Aug 21, 2025
48dcbc5
Toggle logging through config for websockapi
joshusooyaa Aug 21, 2025
43f9ed5
Fix bits threshold to greater/less than or equal
joshusooyaa Aug 21, 2025
eda9e16
Fix inverse schedule logic
joshusooyaa Aug 25, 2025
0d2a2ed
Fix duplicate doorman objects
joshusooyaa Aug 26, 2025
8df9c6d
Prevent always closed from denying access events
joshusooyaa Aug 26, 2025
af2fd4f
Fix cmake for auth-db
joshusooyaa Aug 26, 2025
0f42114
Fix return
joshusooyaa Aug 26, 2025
6e3ecba
Update cmake
joshusooyaa Aug 26, 2025
97d1f95
Merge remote-tracking branch 'upstream/develop' into auth-db
joshusooyaa Aug 27, 2025
5a788c6
Fix build dependency order
joshusooyaa Aug 27, 2025
836ad6f
Merge remote-tracking branch 'upstream/develop' into auth-db
joshusooyaa Sep 2, 2025
1ad1dfe
Merge profile schedules
joshusooyaa Sep 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmake/UseODB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ function(odb_compile outvar)
list(APPEND ODB_ARGS "-I${dir}")
endforeach()

file(REMOVE_RECURSE "${ODB_COMPILE_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${ODB_COMPILE_OUTPUT_DIR}")
if(NOT EXISTS "${ODB_COMPILE_OUTPUT_DIR}")
file(MAKE_DIRECTORY "${ODB_COMPILE_OUTPUT_DIR}")
endif()

foreach(input ${PARAM_FILES})
get_filename_component(fname "${input}" NAME_WE)
Expand Down
2 changes: 0 additions & 2 deletions src/core/audit/AuditFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ IAuthEventPtr Factory::AuthEvent(const DBPtr &database, Cred::ICredentialPtr cre
ASSERT_LOG(database, "Database cannot be null.");
ASSERT_LOG(credential, "Credential must be non null.");
ASSERT_LOG(!door.empty(), "Door must be set.");
ASSERT_LOG(parent, "Parent must be non null.");
ASSERT_LOG(parent->id(), "Parent must be already persisted.");

AuditEntryPtr parent_odb;
if (parent && parent->id())
Expand Down
133 changes: 59 additions & 74 deletions src/core/audit/AuditFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,80 +124,65 @@ using ZoneEventPtr = std::shared_ptr<ZoneEvent>;

enum class EventType
{
/**
* Admin & System Event Types
*/
AL_SYSTEM = 0x1000,
/**
* User Event Types
*/
AL_USER = 0x2000,

WSAPI_CALL = 0x00 & AL_SYSTEM,

USER_CREATED = 0x10 & AL_SYSTEM,
USER_DELETED = 0x11 & AL_SYSTEM,
USER_EDITED = 0x12 & AL_SYSTEM,
USER_PASSWORD_CHANGED = 0x13 & AL_SYSTEM,
/**
* An attempt to change the password failed.
*/
USER_PASSWORD_CHANGE_FAILURE = 0x14 & AL_SYSTEM,

GROUP_CREATED = 0x20 & AL_SYSTEM,
GROUP_UPDATED = 0x21 & AL_SYSTEM,
GROUP_DELETED = 0x22 & AL_SYSTEM,
/**
* Someone joined the group.
*/
GROUP_MEMBERSHIP_JOINED = 0x23 & AL_SYSTEM,
/**
* Someone left the group.
*/
GROUP_MEMBERSHIP_LEFT = 0x24 & AL_SYSTEM,

CREDENTIAL_DELETED = 0x30 & AL_SYSTEM,
CREDENTIAL_CREATED = 0x31 & AL_SYSTEM,
CREDENTIAL_UPDATED = 0x32 & AL_SYSTEM,

SCHEDULE_CREATED = 0x40 & AL_SYSTEM,
SCHEDULE_DELETED = 0x41 & AL_SYSTEM,
SCHEDULE_UPDATED = 0x42 & AL_SYSTEM,

DOOR_CREATED = 0x50 & AL_SYSTEM,
DOOR_UPDATED = 0x51 & AL_SYSTEM,
DOOR_DELETED = 0x52 & AL_SYSTEM,
/**
* This event is linked to door. It is generated
* by the Schedule CRUD manager. It's used to let a door
* know that it may have been removed from a mapping.
*
* Fixme: Currently this event is triggered for every door in a mapping
* everytime a schedule is updated.
*/
MAPPING_MAY_HAVE_CHANGED = 0x53 & AL_SYSTEM,

ACCESS_POINT_CREATED = 0x60 & AL_SYSTEM,
ACCESS_POINT_UPDATED = 0x61 & AL_SYSTEM,
ACCESS_POINT_DELETED = 0x62 & AL_SYSTEM,

ZONE_CREATED = 0x70 & AL_SYSTEM,
ZONE_UPDATED = 0x71 & AL_SYSTEM,
ZONE_DELETED = 0x72 & AL_SYSTEM,

UPDATE_CREATED = 0x80 & AL_SYSTEM,
UPDATE_ACKED = 0x81 & AL_SYSTEM,
UPDATE_CANCELLED = 0x81 & AL_SYSTEM,

DOOR_OPENED = 0x10 & AL_USER,
DOOR_OPENED_MANUALLY = 0x11 & AL_USER,
DOOR_FORCED = 0x12 & AL_USER,
DOOR_FORCED_END = 0x13 & AL_USER,

AUTH_GRANTED = 0x20 & AL_USER,
AUTH_DENIED = 0x21 & AL_USER,

LAST__ = 0xffff
// 0..63 reserved to keep masks within 64-bit numeric serialization

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand why this enum values & flag use have to be changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have been changed because we were getting something like this:
USER_CREATED = 0x10 & AL_SYSTEM being 0x10 & 0x1000 which is 0x00 because:

0x10:   0000 0000 0001 0000
0x1000: 0001 0000 0000 0000
        -------------------
&:      0000 0000 0000 0000  = 0x00

So everything was defaulting to 0x00. As a result, when the code called

if (event_mask_ & EventType::AUTH_GRANTED)
    ss << "Access Granted to Credential " << generate_credential_description() << ".";
else if (event_mask_ & EventType::AUTH_DENIED)
    ss << "Access Denied to Credential " << generate_credential_description() << ".";

It would always result in

ss << "Access Granted to Credential " << generate_credential_description() << ".";

I used sequential numbers as a fix to simplify it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes indeed. You're right that was an issue/mistake, but I would prefer to keep using flags logic to be able to easily filter USER and SYSTEMS records if required. It would be better to fix the enum values with the original expected values in my opinion, that means replacing & by |.
eg. USER_CREATED = 0x10 & AL_SYSTEM => USER_CREATED = 0x10 | AL_SYSTEM


// 0..15 System/Admin
WSAPI_CALL = 0,
USER_CREATED = 1,
USER_DELETED = 2,
USER_EDITED = 3,
USER_PASSWORD_CHANGED = 4,
USER_PASSWORD_CHANGE_FAILURE = 5,

// 16..23 Groups
GROUP_CREATED = 16,
GROUP_UPDATED = 17,
GROUP_DELETED = 18,
GROUP_MEMBERSHIP_JOINED = 19,
GROUP_MEMBERSHIP_LEFT = 20,

// 24..27 Credentials
CREDENTIAL_CREATED = 24,
CREDENTIAL_UPDATED = 25,
CREDENTIAL_DELETED = 26,

// 28..30 Schedules
SCHEDULE_CREATED = 28,
SCHEDULE_UPDATED = 29,
SCHEDULE_DELETED = 30,

// 31..35 Doors
DOOR_CREATED = 31,
DOOR_UPDATED = 32,
DOOR_DELETED = 33,
MAPPING_MAY_HAVE_CHANGED = 34,

// 36..38 Access points
ACCESS_POINT_CREATED = 36,
ACCESS_POINT_UPDATED = 37,
ACCESS_POINT_DELETED = 38,

// 39..41 Zones
ZONE_CREATED = 39,
ZONE_UPDATED = 40,
ZONE_DELETED = 41,

// 42..44 Updates
UPDATE_CREATED = 42,
UPDATE_ACKED = 43,
UPDATE_CANCELLED = 44,

// 45..48 Door usage
DOOR_OPENED = 45,
DOOR_OPENED_MANUALLY = 46,
DOOR_FORCED = 47,
DOOR_FORCED_END = 48,

// 49..50 Auth outcomes
AUTH_GRANTED = 49,
AUTH_DENIED = 50,

LAST__ = 64
};

using EventMask = FlagSet<EventType>;
Expand Down
5 changes: 5 additions & 0 deletions src/core/auth/AuthTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void AuthTarget::add_always_close_sched(Leosac::Tools::IScheduleCPtr const &sche
always_close_.push_back(sched);
}

void AuthTarget::clear_schedules() {
always_open_.clear();
always_close_.clear();
}

Leosac::Hardware::FGPIO *AuthTarget::gpio() const
{
return gpio_.get();
Expand Down
5 changes: 5 additions & 0 deletions src/core/auth/AuthTarget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class AuthTarget
*/
bool is_always_closed(const std::chrono::system_clock::time_point &tp) const;

/**
* Clear schedules (helper for refreshing schedules)
*/
void clear_schedules();

/*
* Reset the door the its expected default state at the current time.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/core/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void Kernel::configure_logger()
bool use_database = false;
std::string syslog_min_level = "WARNING";
std::shared_ptr<spdlog::logger> console;
std::string console_level = "DEBUG";

// Drop existing logger, if any. (This is for the case of a "in process" restart)
spdlog::drop("syslog");
Expand All @@ -382,6 +383,7 @@ void Kernel::configure_logger()
use_syslog = log_cfg_node->get<bool>("enable_syslog", true);
use_database = log_cfg_node->get<bool>("enable_database", false);
syslog_min_level = log_cfg_node->get<std::string>("min_syslog", "WARNING");
console_level = log_cfg_node->get<std::string>("console_level", "DEBUG");
}
if (use_syslog)
{
Expand All @@ -399,7 +401,9 @@ void Kernel::configure_logger()
else
console = spdlog::create(
"console", {std::make_shared<spdlog::sinks::stdout_sink_mt>()});
console->set_level(spdlog::level::debug);

console->set_level(static_cast<spdlog::level::level_enum>(
LogHelper::log_level_from_string(console_level)));
}

const ModuleManager &Kernel::module_manager() const
Expand Down
6 changes: 5 additions & 1 deletion src/modules/auth/auth-db/AuthDBFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@

#pragma once

#include <memory>

namespace Leosac
{
namespace Module
{
namespace Auth
{
class AuthDBInstance;
using AuthDBInstancePtr = std::shared_ptr<AuthDBInstance>;
using AuthDBInstanceId = unsigned long long;
}
}
}
}
Loading
Loading