1 /*
2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "password_policy_query.h"
17
18 #include "edm_log.h"
19 #include "password_policy.h"
20 #include "password_policy_utils.h"
21 #include "password_policy_serializer.h"
22
23 namespace OHOS {
24 namespace EDM {
25
26 constexpr int32_t WITHOUT_ADMIN = 1;
27
GetPolicyName()28 std::string PasswordPolicyQuery::GetPolicyName()
29 {
30 return PolicyName::POLICY_PASSWORD_POLICY;
31 }
32
GetPermission(IPlugin::PermissionType,const std::string & permissionTag)33 std::string PasswordPolicyQuery::GetPermission(IPlugin::PermissionType, const std::string &permissionTag)
34 {
35 if (permissionTag == EdmConstants::PERMISSION_TAG_SYSTEM_API) {
36 return "";
37 }
38 return EdmPermission::PERMISSION_ENTERPRISE_MANAGE_SECURITY;
39 }
40
QueryPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)41 ErrCode PasswordPolicyQuery::QueryPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
42 int32_t userId)
43 {
44 PasswordPolicy policy;
45 if (data.ReadInt32() == WITHOUT_ADMIN) {
46 PasswordPolicyUtils passwordPolicyUtils;
47 if (!passwordPolicyUtils.GetPasswordPolicy(policy)) {
48 EDMLOGE("LocationPolicyPlugin set location failed. GetPasswordPolicy error.");
49 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
50 }
51 } else {
52 if (!PasswordSerializer::GetInstance()->Deserialize(policyData, policy)) {
53 EDMLOGD("PasswordPolicyPlugin Deserialize error!");
54 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
55 }
56 }
57 reply.WriteInt32(ERR_OK);
58 reply.WriteString(policy.complexityReg);
59 reply.WriteInt64(policy.validityPeriod);
60 reply.WriteString(policy.additionalDescription);
61 return ERR_OK;
62 }
63 } // namespace EDM
64 } // namespace OHOS