xref: /openbmc/phosphor-user-manager/users.hpp (revision 93804eba13ade6aebfa38eaac5349b560b5cae33)
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #pragma once
17 #include "json_serializer.hpp"
18 
19 #include <sdbusplus/bus.hpp>
20 #include <sdbusplus/server/object.hpp>
21 #include <xyz/openbmc_project/Object/Delete/server.hpp>
22 #include <xyz/openbmc_project/User/Attributes/server.hpp>
23 #include <xyz/openbmc_project/User/MultiFactorAuthConfiguration/server.hpp>
24 #include <xyz/openbmc_project/User/TOTPAuthenticator/server.hpp>
25 namespace phosphor
26 {
27 namespace user
28 {
29 
30 namespace Base = sdbusplus::xyz::openbmc_project;
31 using UsersIface = Base::User::server::Attributes;
32 
33 using TOTPAuthenticatorIface = Base::User::server::TOTPAuthenticator;
34 using DeleteIface = Base::Object::server::Delete;
35 using Interfaces = sdbusplus::server::object_t<UsersIface, DeleteIface,
36                                                TOTPAuthenticatorIface>;
37 using MultiFactorAuthType = sdbusplus::common::xyz::openbmc_project::user::
38     MultiFactorAuthConfiguration::Type;
39 using MultiFactorAuthConfiguration =
40     sdbusplus::common::xyz::openbmc_project::user::MultiFactorAuthConfiguration;
41 // Place where all user objects has to be created
42 constexpr auto usersObjPath = "/xyz/openbmc_project/user";
43 
44 class UserMgr; // Forward declaration for UserMgr.
45 
46 /** @class Users
47  *  @brief Lists User objects and it's properties
48  */
49 class Users : public Interfaces
50 {
51   public:
52     Users() = delete;
53     ~Users();
54     Users(const Users&) = delete;
55     Users& operator=(const Users&) = delete;
56     Users(Users&&) = delete;
57     Users& operator=(Users&&) = delete;
58 
59     /** @brief Constructs UserMgr object.
60      *
61      *  @param[in] bus  - sdbusplus handler
62      *  @param[in] path - D-Bus path
63      *  @param[in] groups - users group list
64      *  @param[in] priv - users privilege
65      *  @param[in] enabled - user enabled state
66      *  @param[in] parent - user manager - parent object
67      */
68     Users(sdbusplus::bus_t& bus, const char* path,
69           std::vector<std::string> groups, std::string priv, bool enabled,
70           UserMgr& parent);
71 
72     /** @brief delete user method.
73      *  This method deletes the user as requested
74      *
75      */
76     void delete_(void) override;
77 
78     /** @brief update user privilege
79      *
80      *  @param[in] value - User privilege
81      */
82     std::string userPrivilege(std::string value) override;
83 
84     void setUserPrivilege(const std::string& value);
85 
86     void setUserGroups(const std::vector<std::string>& groups);
87 
88     /** @brief lists user privilege
89      *
90      */
91     std::string userPrivilege(void) const override;
92 
93     /** @brief update user groups
94      *
95      *  @param[in] value - User groups
96      */
97     std::vector<std::string> userGroups(
98         std::vector<std::string> value) override;
99 
100     /** @brief list user groups
101      *
102      */
103     std::vector<std::string> userGroups(void) const override;
104 
105     /** @brief lists user enabled state
106      *
107      */
108     bool userEnabled(void) const override;
109 
110     void setUserEnabled(bool value);
111 
112     /** @brief update user enabled state
113      *
114      *  @param[in] value - bool value
115      */
116     bool userEnabled(bool value) override;
117 
118     /** @brief lists user locked state for failed attempt
119      *
120      **/
121     bool userLockedForFailedAttempt(void) const override;
122 
123     /** @brief unlock user locked state for failed attempt
124      *
125      * @param[in]: value - false - unlock user account, true - no action taken
126      **/
127     bool userLockedForFailedAttempt(bool value) override;
128 
129     /** @brief indicates if the user's password is expired
130      *
131      **/
132     bool userPasswordExpired(void) const override;
133 
getUserName() const134     std::string getUserName() const
135     {
136         return userName;
137     }
138     bool secretKeyIsValid() const override;
139     std::string createSecretKey() override;
140     bool verifyOTP(std::string otp) override;
141     bool secretKeyGenerationRequired() const override;
142     void clearSecretKey() override;
143     MultiFactorAuthType bypassedProtocol(MultiFactorAuthType value,
144                                          bool skipSignal) override;
145     void enableMultiFactorAuth(MultiFactorAuthType type, bool value);
146     void load(JsonSerializer& serializer);
147 
148   private:
149     bool checkMfaStatus() const;
150     std::string userName;
151     UserMgr& manager;
152 };
153 
154 } // namespace user
155 } // namespace phosphor
156