blob: 6d665982ba37202df80bfccb5cae80ebc4695fd0 [file] [log] [blame]
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +05301/*
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
Abhilash Raju93804eb2024-10-01 00:24:43 -050017#include "json_serializer.hpp"
18
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053019#include <sdbusplus/bus.hpp>
20#include <sdbusplus/server/object.hpp>
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053021#include <xyz/openbmc_project/Object/Delete/server.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -060022#include <xyz/openbmc_project/User/Attributes/server.hpp>
Abhilash Rajua1a754c2024-07-25 05:43:40 -050023#include <xyz/openbmc_project/User/MultiFactorAuthConfiguration/server.hpp>
24#include <xyz/openbmc_project/User/TOTPAuthenticator/server.hpp>
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053025namespace phosphor
26{
27namespace user
28{
29
30namespace Base = sdbusplus::xyz::openbmc_project;
Ratan Gupta1af12232018-11-03 00:35:38 +053031using UsersIface = Base::User::server::Attributes;
Abhilash Rajua1a754c2024-07-25 05:43:40 -050032
33using TOTPAuthenticatorIface = Base::User::server::TOTPAuthenticator;
Ratan Gupta1af12232018-11-03 00:35:38 +053034using DeleteIface = Base::Object::server::Delete;
Abhilash Rajua1a754c2024-07-25 05:43:40 -050035using Interfaces = sdbusplus::server::object_t<UsersIface, DeleteIface,
36 TOTPAuthenticatorIface>;
37using MultiFactorAuthType = sdbusplus::common::xyz::openbmc_project::user::
38 MultiFactorAuthConfiguration::Type;
Abhilash Raju93804eb2024-10-01 00:24:43 -050039using MultiFactorAuthConfiguration =
40 sdbusplus::common::xyz::openbmc_project::user::MultiFactorAuthConfiguration;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053041// Place where all user objects has to be created
42constexpr auto usersObjPath = "/xyz/openbmc_project/user";
43
44class UserMgr; // Forward declaration for UserMgr.
45
46/** @class Users
47 * @brief Lists User objects and it's properties
48 */
Ratan Gupta1af12232018-11-03 00:35:38 +053049class Users : public Interfaces
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053050{
51 public:
52 Users() = delete;
Abhilash Raju93804eb2024-10-01 00:24:43 -050053 ~Users();
Patrick Williams9638afb2021-02-22 17:16:24 -060054 Users(const Users&) = delete;
55 Users& operator=(const Users&) = delete;
56 Users(Users&&) = delete;
57 Users& operator=(Users&&) = delete;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053058
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 */
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050068 Users(sdbusplus::bus_t& bus, const char* path,
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053069 std::vector<std::string> groups, std::string priv, bool enabled,
Patrick Williams9638afb2021-02-22 17:16:24 -060070 UserMgr& parent);
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053071
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
Nan Zhoufef63032022-10-25 00:07:12 +000084 void setUserPrivilege(const std::string& value);
85
86 void setUserGroups(const std::vector<std::string>& groups);
87
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053088 /** @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 */
Patrick Williams88a82db2025-02-01 08:22:37 -050097 std::vector<std::string> userGroups(
98 std::vector<std::string> value) override;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +053099
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
Nan Zhou6b6f2d82022-10-25 00:07:17 +0000110 void setUserEnabled(bool value);
111
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530112 /** @brief update user enabled state
113 *
114 * @param[in] value - bool value
115 */
116 bool userEnabled(bool value) override;
117
Richard Marian Thomaiyarc7045192018-06-13 16:51:00 +0530118 /** @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
Joseph Reynolds3ab6cc22020-03-03 14:09:03 -0600129 /** @brief indicates if the user's password is expired
130 *
131 **/
Nan Zhouf3fb77c2022-08-29 17:51:59 +0000132 bool userPasswordExpired(void) const override;
Joseph Reynolds3ab6cc22020-03-03 14:09:03 -0600133
Abhilash Rajua1a754c2024-07-25 05:43:40 -0500134 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);
Abhilash Raju93804eb2024-10-01 00:24:43 -0500146 void load(JsonSerializer& serializer);
Abhilash Rajua1a754c2024-07-25 05:43:40 -0500147
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530148 private:
Abhilash Rajua1a754c2024-07-25 05:43:40 -0500149 bool checkMfaStatus() const;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530150 std::string userName;
Patrick Williams9638afb2021-02-22 17:16:24 -0600151 UserMgr& manager;
Richard Marian Thomaiyar9f630d92018-05-24 10:49:10 +0530152};
153
154} // namespace user
155} // namespace phosphor