LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EASPolicyManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef EASPOLICYMANAGER_H
23 #define EASPOLICYMANAGER_H
24 
25 #include "Common.h"
26 
27 #include <string>
28 #include "cjson/json.h"
29 #include "PtrArray.h"
30 
31 #include <lunaservice.h>
32 
33 #include <QObject>
34 
35 class EASPolicyManager;
36 class EASPolicy
37 {
38 public:
39  EASPolicy(bool isDevicePolicy = false)
40  : m_passwordRequired(false)
41  , m_maxRetries(0)
42  , m_minLength(1)
43  , m_isAlphaNumeric(false)
44  , m_allowSimplePassword(true)
45  , m_inactivityInSeconds(9998) // highest allowable inactivity timeout
46  , m_id("")
47  , m_revision (0)
48  , m_isDevicePolicy(isDevicePolicy)
49  , m_isDeleted(false)
50  {
51  }
52 
53  bool passwordRequired() const { return m_passwordRequired; }
54  bool requiresAlphaNumeric() const { return m_isAlphaNumeric; }
55  bool allowSimplePassword() const { return m_allowSimplePassword; }
56  uint32_t maxRetries() const { return m_maxRetries; }
57  uint32_t minLength() const { return m_minLength; }
58 
59  // returns a platform supported value for m_inactivityInSeconds
60  uint32_t maxInactivityInSeconds() const;
61  uint32_t clampInactivityInSeconds(uint32_t inactivityInSeconds) const;
62 
63  const std::string& id() const { return m_id; }
64 
65  json_object* toJSON() const;
66  json_object* toNewJSON() const;
67  bool fromJSON(json_object* policy);
68  bool fromNewJSON(json_object* policy);
69 
70  bool validMaxRetries() const { return m_passwordRequired && m_maxRetries > 1; }
71  bool validMinLength() const { return m_passwordRequired && m_minLength > 1; }
72  bool validInactivityInSeconds() const { return m_passwordRequired; }
73 
74  void merge(const EASPolicy* newPolicy);
75 
76 private:
77  bool operator== (const EASPolicy& r) const {
78  return (m_passwordRequired == r.m_passwordRequired &&
79  m_maxRetries == r.m_maxRetries &&
80  m_minLength == r.m_minLength &&
81  m_isAlphaNumeric == r.m_isAlphaNumeric &&
82  m_allowSimplePassword == r.m_allowSimplePassword &&
83  m_inactivityInSeconds == r.m_inactivityInSeconds);
84  }
85 
86  // policy properties
87  bool m_passwordRequired;
88  uint32_t m_maxRetries;
89  uint32_t m_minLength;
90  bool m_isAlphaNumeric;
91  bool m_allowSimplePassword;
92 
93  uint32_t m_inactivityInSeconds;
94 
95  std::string m_id;
96  int m_revision;
97  bool m_isDevicePolicy;
98  bool m_isDeleted;
99 
100  friend class EASPolicyManager;
101 };
102 
103 
104 class EASPolicyManager : public QObject
105 {
106  Q_OBJECT
107 
108 public:
109 
110  static EASPolicyManager* instance();
112 
113  bool load();
114 
115  bool policyPending() const { return (m_aggregate != 0 && !m_isEnforced); }
116  const EASPolicy * const getPolicy() const { return m_aggregate; }
117 
118  std::string getPolicyState() const;
119  json_object* getPolicyStatus() const;
120 
121  void passwordEnforced();
122 
123  uint32_t retriesLeft() const;
124  int decrementRetries();
125  int resetRetries();
126 
127 
129  void queryDevicePolicy();
130  void querySecurityPolicies();
131  void setDevicePolicy (json_object* policy = NULL);
132  void updateDevicePolicy (json_object* policies);
133  void watchSecurityPolicies();
135 
136  static bool cbSecurityPolicy (LSHandle *sh, LSMessage *message, void *data);
137  static bool cbWatchResponse (LSHandle *sh, LSMessage *message, void *data);
138  static bool cbDevicePolicy (LSHandle *sh, LSMessage *message, void *data);
139  static bool cbDevicePolicySaved (LSHandle *sh, LSMessage *message, void *data);
140  static bool cbTempPoliciesDeleted (LSHandle *sh, LSMessage *message, void *data);
141 
142 Q_SIGNALS:
143 
144  void signalPolicyChanged(const EASPolicy* const);
145 
146 private:
147 
149 
150  void save();
151 
152  void notifyPolicyChanged();
153 
154  LSHandle* m_service;
155 
156  bool m_isEnforced;
157  uint32_t m_retriesLeft;
158 
159  EASPolicy* m_aggregate;
160  int m_lastRev;
161  LSMessageToken m_callToken;
162 };
163 
164 #endif