Leosac  0.8.0
Open Source Access Control
Leosac::Audit::AuditEntry Class Reference

Implementation of IAuditEntry, backed by ODB. More...

#include <AuditEntry.hpp>

+ Inheritance diagram for Leosac::Audit::AuditEntry:
+ Collaboration diagram for Leosac::Audit::AuditEntry:

Public Member Functions

 AuditEntry (const AuditEntry &)=delete
 
virtual ~AuditEntry ()=default
 
virtual AuditEntryId id () const override
 Retrieve the identifier of the entry. More...
 
virtual void finalize () override
 Mark the entry as finalized, and update it wrt the database. More...
 
virtual bool finalized () const override
 Is this entry finalized. More...
 
virtual void event_mask (const EventMask &mask) override
 Set the event mask for the entry. More...
 
virtual const EventMaskevent_mask () const override
 Retrieve the current event mask. More...
 
virtual void author (Auth::UserPtr user) override
 Set the author of the entry. More...
 
virtual Auth::UserId author_id () const override
 Retrieve the user id of the author of this entry. More...
 
virtual void set_parent (IAuditEntryPtr parent) override
 Set parent as the parent audit entry for this entry. More...
 
virtual IAuditEntryPtr parent () const override
 Retrieve the parent of this entry. More...
 
virtual void remove_parent () override
 Remove the parent-child relationship between this entry and its parent. More...
 
virtual size_t children_count () const override
 Returns the number of children that this entry has. More...
 
virtual size_t version () const override
 Returns the ODB version of the object. More...
 
virtual void reload () override
 Reload the object from the database. More...
 
virtual boost::posix_time::ptime timestamp () const override
 Retrieve unix timestamp. More...
 
void database (DBPtr db)
 Set the database pointer. More...
 
- Public Member Functions inherited from Leosac::Audit::IAuditEntry
 MAKE_VISITABLE ()
 
virtual std::string generate_description () const
 Generate a description for this event. More...
 
- Public Member Functions inherited from Leosac::Tools::IVisitable
virtual void accept (::Leosac::Tools::BaseVisitor &)=0
 Accept a visitor that may mutate this. More...
 
virtual void accept (::Leosac::Tools::BaseVisitor &) const =0
 Accept a visitor that will not mutate this. More...
 

Static Public Member Functions

static AuditEntryPtr get_last_audit (DBPtr db)
 Retrieve the last (finalized) audit entry. More...
 

Protected Member Functions

 AuditEntry ()
 

Protected Attributes

AuditEntryWPtr parent_
 
std::string msg_
 
Auth::UserLPtr author_
 The user at the source of the entry. More...
 
EventMask event_mask_
 
size_t duration_
 How long did it take for the Audit object to be finalized. More...
 
bool finalized_
 Audit entry are sometime persisted multiple time before reaching their final state. More...
 
DBPtr database_
 Pointer to the database. More...
 
Tools::ElapsedTimeCounter etc_
 Keep track of how long the object has been alive. More...
 

Private Member Functions

void odb_callback (odb::callback_event e, odb::database &) const
 Implementation of an ODB callback. More...
 

Private Attributes

AuditEntryId id_
 
boost::posix_time::ptime timestamp_
 
std::vector< AuditEntryPtrchildren_
 
const size_t version_
 

Friends

class odb::access
 

Additional Inherited Members

- Static Protected Member Functions inherited from Leosac::Tools::IVisitable
template<class T >
static bool visitor_dispatch (T &visited, BaseVisitor &visitor, bool abort_on_failure)
 

Detailed Description

Implementation of IAuditEntry, backed by ODB.

This class, as well as all its child are backed by ODB, and are therefore persisted in a SQL database.

See also
IAuditEntry

Definition at line 45 of file AuditEntry.hpp.

Constructor & Destructor Documentation

◆ AuditEntry() [1/2]

AuditEntry::AuditEntry ( )
protected

Definition at line 31 of file AuditEntry.cpp.

◆ AuditEntry() [2/2]

Leosac::Audit::AuditEntry::AuditEntry ( const AuditEntry )
delete

◆ ~AuditEntry()

virtual Leosac::Audit::AuditEntry::~AuditEntry ( )
virtualdefault

Member Function Documentation

◆ author()

void AuditEntry::author ( Auth::UserPtr  user)
overridevirtual

Set the author of the entry.

The author is the user that is responsible (aka at the source) of the event.

Pre-Conditions:

  • The user pointer, if not null, must point to an already persisted user object.

Implements Leosac::Audit::IAuditEntry.

Definition at line 88 of file AuditEntry.cpp.

◆ author_id()

Auth::UserId AuditEntry::author_id ( ) const
overridevirtual

Retrieve the user id of the author of this entry.

It may returns 0, which is not a valid user_id.

Implements Leosac::Audit::IAuditEntry.

Definition at line 149 of file AuditEntry.cpp.

◆ children_count()

size_t AuditEntry::children_count ( ) const
overridevirtual

Returns the number of children that this entry has.

Implements Leosac::Audit::IAuditEntry.

Definition at line 123 of file AuditEntry.cpp.

◆ database()

void AuditEntry::database ( DBPtr  db)

Set the database pointer.

This is used by the DBService.

Definition at line 144 of file AuditEntry.cpp.

◆ event_mask() [1/2]

const EventMask & AuditEntry::event_mask ( ) const
overridevirtual

Retrieve the current event mask.

Implements Leosac::Audit::IAuditEntry.

Definition at line 83 of file AuditEntry.cpp.

◆ event_mask() [2/2]

void AuditEntry::event_mask ( const EventMask mask)
overridevirtual

Set the event mask for the entry.

Parameters
mask

Implements Leosac::Audit::IAuditEntry.

Definition at line 77 of file AuditEntry.cpp.

◆ finalize()

void AuditEntry::finalize ( )
overridevirtual

Mark the entry as finalized, and update it wrt the database.

Calling finalize() on an already finalized entry has no effect.

Subclasses must prevent modification of every attributes once this method has been called.

Pre-Conditions:

  • Must be in a database transaction.
Warning
While updating the object state in the database, the transaction itself is not commit()ed. Make sure to commit the transaction to guarantee that the audit is stored in the database.

Implements Leosac::Audit::IAuditEntry.

Definition at line 57 of file AuditEntry.cpp.

◆ finalized()

bool AuditEntry::finalized ( ) const
overridevirtual

Is this entry finalized.

Implements Leosac::Audit::IAuditEntry.

Definition at line 72 of file AuditEntry.cpp.

◆ get_last_audit()

AuditEntryPtr AuditEntry::get_last_audit ( DBPtr  db)
static

Retrieve the last (finalized) audit entry.

Definition at line 161 of file AuditEntry.cpp.

◆ id()

AuditEntryId AuditEntry::id ( ) const
overridevirtual

Retrieve the identifier of the entry.

An id of 0 means that the entry is not persisted yet.

Implements Leosac::Audit::IAuditEntry.

Definition at line 39 of file AuditEntry.cpp.

◆ odb_callback()

void AuditEntry::odb_callback ( odb::callback_event  e,
odb::database &  db 
) const
private

Implementation of an ODB callback.

The callback will make sure to update the parent (if any). This is to ensure that parent-child relationship are persisted when saving the child.

Note that the reverse is not needed, because the child must always be fully saved before the parent gets its final update.

Definition at line 44 of file AuditEntry.cpp.

◆ parent()

IAuditEntryPtr AuditEntry::parent ( ) const
overridevirtual

Retrieve the parent of this entry.

Implements Leosac::Audit::IAuditEntry.

Definition at line 139 of file AuditEntry.cpp.

◆ reload()

void AuditEntry::reload ( )
overridevirtual

Reload the object from the database.

Pre-Conditions:

  • Must be in a database transaction.
Note
Be careful as internal change made to the object will be lost when reload()ing the object.

Implements Leosac::Audit::IAuditEntry.

Definition at line 133 of file AuditEntry.cpp.

◆ remove_parent()

void AuditEntry::remove_parent ( )
overridevirtual

Remove the parent-child relationship between this entry and its parent.

This effectively also remove this from the children of its current parent.

Note
This is a no-op is there is already no parent.

Implements Leosac::Audit::IAuditEntry.

Definition at line 111 of file AuditEntry.cpp.

◆ set_parent()

void AuditEntry::set_parent ( IAuditEntryPtr  parent)
overridevirtual

Set parent as the parent audit entry for this entry.

The set_parent() will copy the parent's author to this->author_ if there currently is no author assigned to the entry.

Pre-Conditions:

  • Shall be already persisted (otherwise we might give the parent a non persisted child, resulting in foreign key issue).
  • Shall have no parent.
  • The parent must be a non-null, already persisted object.
  • parent must be of type AuditEntryPtr. This should always be the case.

Post-Conditions:

  • Will have a parent.
  • This object will be somewhere in parent->children_ array.

Implements Leosac::Audit::IAuditEntry.

Definition at line 95 of file AuditEntry.cpp.

◆ timestamp()

boost::posix_time::ptime AuditEntry::timestamp ( ) const
overridevirtual

Retrieve unix timestamp.

Implements Leosac::Audit::IAuditEntry.

Definition at line 156 of file AuditEntry.cpp.

◆ version()

size_t AuditEntry::version ( ) const
overridevirtual

Returns the ODB version of the object.

This call is for debugging purpose.

Implements Leosac::Audit::IAuditEntry.

Definition at line 128 of file AuditEntry.cpp.

Friends And Related Function Documentation

◆ odb::access

friend class odb::access
friend

Definition at line 155 of file AuditEntry.hpp.

Member Data Documentation

◆ author_

Auth::UserLPtr Leosac::Audit::AuditEntry::author_
protected

The user at the source of the entry.

May be null.

Definition at line 116 of file AuditEntry.hpp.

◆ children_

std::vector<AuditEntryPtr> Leosac::Audit::AuditEntry::children_
private

Definition at line 103 of file AuditEntry.hpp.

◆ database_

DBPtr Leosac::Audit::AuditEntry::database_
protected

Pointer to the database.

Required to implement finalize().

Manually set by Audit::Factory.

Definition at line 142 of file AuditEntry.hpp.

◆ duration_

size_t Leosac::Audit::AuditEntry::duration_
protected

How long did it take for the Audit object to be finalized.

Definition at line 124 of file AuditEntry.hpp.

◆ etc_

Tools::ElapsedTimeCounter Leosac::Audit::AuditEntry::etc_
protected

Keep track of how long the object has been alive.

This helps populates the duration_ field.

Definition at line 149 of file AuditEntry.hpp.

◆ event_mask_

EventMask Leosac::Audit::AuditEntry::event_mask_
protected

Definition at line 119 of file AuditEntry.hpp.

◆ finalized_

bool Leosac::Audit::AuditEntry::finalized_
protected

Audit entry are sometime persisted multiple time before reaching their final state.

When set to true, this flag indicates that the audit entry has reach its final status. This is useful to detect incomplete audit entry.

Definition at line 133 of file AuditEntry.hpp.

◆ id_

AuditEntryId Leosac::Audit::AuditEntry::id_
private

Definition at line 97 of file AuditEntry.hpp.

◆ msg_

std::string Leosac::Audit::AuditEntry::msg_
protected

Definition at line 110 of file AuditEntry.hpp.

◆ parent_

AuditEntryWPtr Leosac::Audit::AuditEntry::parent_
protected

Definition at line 107 of file AuditEntry.hpp.

◆ timestamp_

boost::posix_time::ptime Leosac::Audit::AuditEntry::timestamp_
private

Definition at line 100 of file AuditEntry.hpp.

◆ version_

const size_t Leosac::Audit::AuditEntry::version_
private

Definition at line 153 of file AuditEntry.hpp.


The documentation for this class was generated from the following files: