2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/user.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "icinga/user-ti.cpp"
|
2014-11-16 16:20:39 +01:00
|
|
|
#include "icinga/usergroup.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/notification.hpp"
|
|
|
|
#include "icinga/usergroup.hpp"
|
|
|
|
#include "base/objectlock.hpp"
|
2014-12-18 15:43:01 +01:00
|
|
|
#include "base/exception.hpp"
|
2013-02-24 08:26:10 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-01 12:07:52 +01:00
|
|
|
REGISTER_TYPE(User);
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void User::OnConfigLoaded()
|
2013-02-26 10:13:54 +01:00
|
|
|
{
|
2015-08-25 13:53:43 +02:00
|
|
|
ObjectImpl<User>::OnConfigLoaded();
|
2014-11-21 18:31:37 +01:00
|
|
|
|
2016-06-21 14:46:01 +02:00
|
|
|
SetTypeFilter(FilterArrayToInt(GetTypes(), Notification::GetTypeFilterMap(), ~0));
|
|
|
|
SetStateFilter(FilterArrayToInt(GetStates(), Notification::GetStateFilterMap(), ~0));
|
2014-11-21 18:31:37 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void User::OnAllConfigLoaded()
|
2014-11-21 18:31:37 +01:00
|
|
|
{
|
2015-08-25 13:53:43 +02:00
|
|
|
ObjectImpl<User>::OnAllConfigLoaded();
|
2014-11-21 18:31:37 +01:00
|
|
|
|
|
|
|
UserGroup::EvaluateObjectRules(this);
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
Array::Ptr groups = GetGroups();
|
2013-02-27 21:49:03 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
if (groups) {
|
2014-10-28 18:58:22 +01:00
|
|
|
groups = groups->ShallowClone();
|
|
|
|
|
2013-09-09 13:52:37 +02:00
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& name : groups) {
|
2013-08-20 11:06:04 +02:00
|
|
|
UserGroup::Ptr ug = UserGroup::GetByName(name);
|
2013-03-02 09:07:47 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
if (ug)
|
2014-11-08 21:17:16 +01:00
|
|
|
ug->ResolveGroupMembership(this, true);
|
2013-08-20 11:06:04 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 10:13:54 +01:00
|
|
|
}
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void User::Stop(bool runtimeRemoved)
|
2013-02-24 08:26:10 +01:00
|
|
|
{
|
2015-08-20 17:18:48 +02:00
|
|
|
ObjectImpl<User>::Stop(runtimeRemoved);
|
2013-08-20 11:06:04 +02:00
|
|
|
|
|
|
|
Array::Ptr groups = GetGroups();
|
|
|
|
|
|
|
|
if (groups) {
|
2013-09-09 13:52:37 +02:00
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& name : groups) {
|
2013-08-20 11:06:04 +02:00
|
|
|
UserGroup::Ptr ug = UserGroup::GetByName(name);
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
if (ug)
|
2014-11-08 21:17:16 +01:00
|
|
|
ug->ResolveGroupMembership(this, false);
|
2013-08-20 11:06:04 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-24 08:26:10 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
void User::AddGroup(const String& name)
|
|
|
|
{
|
2021-02-02 10:16:04 +01:00
|
|
|
std::unique_lock<std::mutex> lock(m_UserMutex);
|
2014-05-01 23:53:08 +02:00
|
|
|
|
|
|
|
Array::Ptr groups = GetGroups();
|
|
|
|
|
2014-05-02 00:38:46 +02:00
|
|
|
if (groups && groups->Contains(name))
|
|
|
|
return;
|
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
if (!groups)
|
2014-11-08 21:17:16 +01:00
|
|
|
groups = new Array();
|
2014-05-01 23:53:08 +02:00
|
|
|
|
|
|
|
groups->Add(name);
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
TimePeriod::Ptr User::GetPeriod() const
|
2013-03-21 13:42:46 +01:00
|
|
|
{
|
2014-04-09 10:25:23 +02:00
|
|
|
return TimePeriod::GetByName(GetPeriodRaw());
|
2013-08-08 08:30:19 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
void User::ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils)
|
2014-04-07 13:59:41 +02:00
|
|
|
{
|
2018-01-11 07:08:09 +01:00
|
|
|
ObjectImpl<User>::ValidateStates(lvalue, utils);
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
int filter = FilterArrayToInt(lvalue(), Notification::GetStateFilterMap(), 0);
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2016-06-21 14:46:01 +02:00
|
|
|
if (filter == -1 || (filter & ~(StateFilterUp | StateFilterDown | StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown)) != 0)
|
2017-11-30 18:09:38 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "states" }, "State filter is invalid."));
|
2014-11-30 23:32:13 +01:00
|
|
|
}
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
void User::ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils)
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
2018-01-11 07:08:09 +01:00
|
|
|
ObjectImpl<User>::ValidateTypes(lvalue, utils);
|
2016-03-24 09:15:09 +01:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
int filter = FilterArrayToInt(lvalue(), Notification::GetTypeFilterMap(), 0);
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2016-06-21 14:46:01 +02:00
|
|
|
if (filter == -1 || (filter & ~(NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved |
|
2017-12-19 15:50:05 +01:00
|
|
|
NotificationCustom | NotificationAcknowledgement | NotificationProblem | NotificationRecovery |
|
|
|
|
NotificationFlappingStart | NotificationFlappingEnd)) != 0)
|
2017-11-30 18:09:38 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, { "types" }, "Type filter is invalid."));
|
2014-04-07 13:59:41 +02:00
|
|
|
}
|