summaryrefslogtreecommitdiffstats
path: root/phosphor-ldap-mapper/ldap_mapper_entry.cpp
blob: 95f381d0ff3d2ee3826912466e42fdedeea63757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <experimental/filesystem>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/User/Common/error.hpp>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include "config.h"
#include "ldap_mapper_entry.hpp"
#include "ldap_mapper_mgr.hpp"
#include "ldap_mapper_serialize.hpp"

namespace phosphor
{
namespace user
{

using namespace phosphor::logging;
using InvalidArgument =
    sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
using Argument = xyz::openbmc_project::Common::InvalidArgument;

LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
                                 const std::string &groupName,
                                 const std::string &privilege,
                                 LDAPMapperMgr &parent) :
    Ifaces(bus, path, true),
    id(std::stol(std::experimental::filesystem::path(path).filename())),
    manager(parent)
{
    Ifaces::privilege(privilege, true);
    Ifaces::groupName(groupName, true);
    Ifaces::emit_object_added();
}

LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
                                 LDAPMapperMgr &parent) :
    Ifaces(bus, path, true),
    id(std::stol(std::experimental::filesystem::path(path).filename())),
    manager(parent)
{
}

void LDAPMapperEntry::delete_(void)
{
    manager.deletePrivilegeMapper(id);
}

std::string LDAPMapperEntry::groupName(std::string value)
{
    if (value == Ifaces::groupName())
    {
        return value;
    }

    manager.checkPrivilegeMapper(value);
    auto val = Ifaces::groupName(value);
    serialize(*this, id);
    return val;
}

std::string LDAPMapperEntry::privilege(std::string value)
{
    if (value == Ifaces::privilege())
    {
        return value;
    }

    manager.checkPrivilegeLevel(value);
    auto val = Ifaces::privilege(value);
    serialize(*this, id);
    return val;
}

} // namespace user
} // namespace phosphor
OpenPOWER on IntegriCloud