Refactor Password Policy 41/85841/4 accepted/tizen/common/20160905.171346 accepted/tizen/ivi/20160906.060931 accepted/tizen/mobile/20160906.060821 accepted/tizen/tv/20160906.060845 accepted/tizen/wearable/20160906.060912 submit/tizen/20160905.002202
authorSungjun, Lee <sjun221.lee@samsung.com>
Mon, 29 Aug 2016 08:35:40 +0000 (17:35 +0900)
committerSungjun, Lee <sjun221.lee@samsung.com>
Mon, 5 Sep 2016 09:03:51 +0000 (18:03 +0900)
Change-Id: Ie08376471a85d4c9909f6549e5b13c8cc30a2bc8
Signed-off-by: Sungjun, Lee <sjun221.lee@samsung.com>
libs/dpm/password.cpp
libs/password.cpp
policy/password.hxx
server/common.cmake
server/ivi.cmake
server/mobile.cmake
server/password-manager.cpp [new file with mode: 0644]
server/password-manager.h [new file with mode: 0644]
server/password.cpp
server/wearable.cmake

index 909edec..3337d9c 100644 (file)
@@ -33,7 +33,7 @@ EXPORT_API int dpm_password_set_quality(device_policy_manager_h handle, dpm_pass
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyQuality(quality);
+       return password.setQuality(quality);
 }
 
 EXPORT_API int dpm_password_get_quality(device_policy_manager_h handle, dpm_password_quality_e *quality)
@@ -44,7 +44,7 @@ EXPORT_API int dpm_password_get_quality(device_policy_manager_h handle, dpm_pass
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getPasswordPolicyQuality();
+       int ret = password.getQuality();
        if (ret < 0) {
                return -1;
        }
@@ -62,7 +62,7 @@ EXPORT_API int dpm_password_set_minimum_length(device_policy_manager_h handle, i
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyMinimumLength(value);
+       return password.setMinimumLength(value);
 }
 
 EXPORT_API int dpm_password_get_minimum_length(device_policy_manager_h handle, int *value)
@@ -73,7 +73,7 @@ EXPORT_API int dpm_password_get_minimum_length(device_policy_manager_h handle, i
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getPasswordPolicyMinimumLength();
+       int ret = password.getMinimumLength();
        if (ret < 0) {
                return -1;
        }
@@ -91,7 +91,7 @@ EXPORT_API int dpm_password_set_min_complex_chars(device_policy_manager_h handle
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setMinPasswordPolicyComplexChars(value);
+       return password.setMinComplexChars(value);
 }
 
 EXPORT_API int dpm_password_get_min_complex_chars(device_policy_manager_h handle, int *value)
@@ -102,7 +102,7 @@ EXPORT_API int dpm_password_get_min_complex_chars(device_policy_manager_h handle
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getMinPasswordPolicyComplexChars();
+       int ret = password.getMinComplexChars();
        if (ret < 0) {
                return -1;
        }
@@ -120,7 +120,7 @@ EXPORT_API int dpm_password_set_maximum_failed_attempts_for_wipe(device_policy_m
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setMaximumFailedPasswordPolicyForWipe(value);
+       return password.setMaximumFailedForWipe(value);
 }
 
 EXPORT_API int dpm_password_get_maximum_failed_attempts_for_wipe(device_policy_manager_h handle, int *value)
@@ -131,7 +131,7 @@ EXPORT_API int dpm_password_get_maximum_failed_attempts_for_wipe(device_policy_m
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getMaximumFailedPasswordPolicyForWipe();
+       int ret = password.getMaximumFailedForWipe();
        if (ret < 0) {
                return -1;
        }
@@ -149,7 +149,7 @@ EXPORT_API int dpm_password_set_expires(device_policy_manager_h handle, int valu
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyExpires(value);
+       return password.setExpires(value);
 }
 
 EXPORT_API int dpm_password_get_expires(device_policy_manager_h handle, int *value)
@@ -160,7 +160,7 @@ EXPORT_API int dpm_password_get_expires(device_policy_manager_h handle, int *val
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getPasswordPolicyExpires();
+       int ret = password.getExpires();
        if (ret < 0) {
                return -1;
        }
@@ -178,7 +178,7 @@ EXPORT_API int dpm_password_set_history(device_policy_manager_h handle, int valu
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyHistory(value);
+       return password.setHistory(value);
 }
 
 EXPORT_API int dpm_password_get_history(device_policy_manager_h handle, int *value)
@@ -189,7 +189,7 @@ EXPORT_API int dpm_password_get_history(device_policy_manager_h handle, int *val
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getPasswordPolicyHistory();
+       int ret = password.getHistory();
        if (ret < 0) {
                return -1;
        }
@@ -207,7 +207,7 @@ EXPORT_API int dpm_password_set_pattern(device_policy_manager_h handle, const ch
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyPattern(pattern);
+       return password.setPattern(pattern);
 }
 
 EXPORT_API int dpm_password_reset(device_policy_manager_h handle, const char *passwd)
@@ -218,7 +218,7 @@ EXPORT_API int dpm_password_reset(device_policy_manager_h handle, const char *pa
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.resetPasswordPolicy(passwd);
+       return password.reset(passwd);
 }
 
 EXPORT_API int dpm_password_enforce_change(device_policy_manager_h handle)
@@ -228,7 +228,7 @@ EXPORT_API int dpm_password_enforce_change(device_policy_manager_h handle)
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.enforcePasswordPolicyChange();
+       return password.enforceChange();
 }
 
 EXPORT_API int dpm_password_set_max_inactivity_time_device_lock(device_policy_manager_h handle, int value)
@@ -264,13 +264,13 @@ EXPORT_API int dpm_password_set_status(device_policy_manager_h handle, dpm_passw
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(status >= DPM_PASSWORD_STATUS_NORMAL &&
-                                       status <= DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED,
-                                       DPM_ERROR_INVALID_PARAMETER);
+                                  status <= DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED,
+                                  DPM_ERROR_INVALID_PARAMETER);
 
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.setPasswordPolicyStatus(status);
+       return password.setStatus(status);
 }
 
 EXPORT_API int dpm_password_get_status(device_policy_manager_h handle, dpm_password_status_e *status)
@@ -281,7 +281,7 @@ EXPORT_API int dpm_password_get_status(device_policy_manager_h handle, dpm_passw
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       int ret = password.getPasswordPolicyStatus();
+       int ret = password.getStatus();
        if (ret < 0) {
                return -1;
        }
@@ -298,7 +298,7 @@ EXPORT_API int dpm_password_delete_pattern(device_policy_manager_h handle)
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       return password.deletePasswordPolicyPattern();
+       return password.deletePattern();
 }
 
 EXPORT_API int dpm_password_get_pattern(device_policy_manager_h handle, char **pattern)
@@ -309,7 +309,7 @@ EXPORT_API int dpm_password_get_pattern(device_policy_manager_h handle, char **p
        DevicePolicyContext &client = GetDevicePolicyContext(handle);
        PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
-       *pattern = ::strdup(password.getPasswordPolicyPattern().c_str());
+       *pattern = ::strdup(password.getPattern().c_str());
 
        return DPM_ERROR_NONE;
 }
index 3bc250f..27a37bb 100644 (file)
@@ -26,145 +26,145 @@ PasswordPolicy::~PasswordPolicy()
 {
 }
 
-int PasswordPolicy::setPasswordPolicyQuality(const int quality)
+int PasswordPolicy::setQuality(const int quality)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyQuality", quality);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setQuality", quality);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getPasswordPolicyQuality()
+int PasswordPolicy::getQuality()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getPasswordPolicyQuality");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getQuality");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setPasswordPolicyMinimumLength(const int value)
+int PasswordPolicy::setMinimumLength(int value)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyMinimumLength", value);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setMinimumLength", value);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getPasswordPolicyMinimumLength()
+int PasswordPolicy::getMinimumLength()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getPasswordPolicyMinimumLength");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getMinimumLength");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setMinPasswordPolicyComplexChars(const int value)
+int PasswordPolicy::setMinComplexChars(int value)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setMinPasswordPolicyComplexChars", value);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setMinComplexChars", value);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getMinPasswordPolicyComplexChars()
+int PasswordPolicy::getMinComplexChars()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getMinPasswordPolicyComplexChars");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getMinComplexChars");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setMaximumFailedPasswordPolicyForWipe(const int value)
+int PasswordPolicy::setMaximumFailedForWipe(int value)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setMaximumFailedPasswordPolicyForWipe", value);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setMaximumFailedForWipe", value);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
-int PasswordPolicy::getMaximumFailedPasswordPolicyForWipe()
+int PasswordPolicy::getMaximumFailedForWipe()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getMaximumFailedPasswordPolicyForWipe");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getMaximumFailedForWipe");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setPasswordPolicyExpires(const int value)
+int PasswordPolicy::setExpires(int value)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyExpires", value);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setExpires", value);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getPasswordPolicyExpires()
+int PasswordPolicy::getExpires()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getPasswordPolicyExpires");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getExpires");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setPasswordPolicyHistory(const int value)
+int PasswordPolicy::setHistory(int value)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyHistory", value);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setHistory", value);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getPasswordPolicyHistory()
+int PasswordPolicy::getHistory()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getPasswordPolicyHistory");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getHistory");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setPasswordPolicyPattern(const std::string& pattern)
+int PasswordPolicy::setPattern(const std::string &pattern)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyPattern", pattern);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setPattern", pattern);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::resetPasswordPolicy(const std::string& passwd)
+int PasswordPolicy::reset(const std::string &passwd)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::resetPasswordPolicy", passwd);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::reset", passwd);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::enforcePasswordPolicyChange()
+int PasswordPolicy::enforceChange()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::enforcePasswordPolicyChange");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::enforceChange");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setMaxInactivityTimeDeviceLock(const int value)
+int PasswordPolicy::setMaxInactivityTimeDeviceLock(int value)
 {
        try {
                return context->methodCall<int>("PasswordPolicy::setMaxInactivityTimeDeviceLock", value);
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
@@ -173,53 +173,53 @@ int PasswordPolicy::getMaxInactivityTimeDeviceLock()
 {
        try {
                return context->methodCall<int>("PasswordPolicy::getMaxInactivityTimeDeviceLock");;
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setPasswordPolicyStatus(const int status)
+int PasswordPolicy::setStatus(int status)
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::setPasswordPolicyStatus", status);
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::setStatus", status);
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::getPasswordPolicyStatus()
+int PasswordPolicy::getStatus()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::getPasswordPolicyStatus");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::getStatus");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::deletePasswordPolicyPattern()
+int PasswordPolicy::deletePattern()
 {
        try {
-               return context->methodCall<int>("PasswordPolicy::deletePasswordPolicyPattern");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<int>("PasswordPolicy::deletePattern");
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-std::string PasswordPolicy::getPasswordPolicyPattern()
+std::string PasswordPolicy::getPattern()
 {
        std::string error("Error");
        try {
-               return context->methodCall<std::string>("PasswordPolicy::getPasswordPolicyPattern");
-       } catch (runtime::Exceptione) {
+               return context->methodCall<std::string>("PasswordPolicy::getPattern");
+       } catch (runtime::Exception &e) {
                return error;
        }
 }
 
-int PasswordPolicy::setMaximumCharacterOccurrences(const int value)
+int PasswordPolicy::setMaximumCharacterOccurrences(int value)
 {
        try {
                return context->methodCall<int>("PasswordPolicy::setMaximumCharacterOccurrences", value);
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
@@ -228,16 +228,16 @@ int PasswordPolicy::getMaximumCharacterOccurrences()
 {
        try {
                return context->methodCall<int>("PasswordPolicy::getMaximumCharacterOccurrences");
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setMaximumNumericSequenceLength(const int value)
+int PasswordPolicy::setMaximumNumericSequenceLength(int value)
 {
        try {
                return context->methodCall<int>("PasswordPolicy::setMaximumNumericSequenceLength", value);
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
@@ -246,16 +246,16 @@ int PasswordPolicy::getMaximumNumericSequenceLength()
 {
        try {
                return context->methodCall<int>("PasswordPolicy::getMaximumNumericSequenceLength");
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
 
-int PasswordPolicy::setForbiddenStrings(const std::vector<std::string>forbiddenStrings)
+int PasswordPolicy::setForbiddenStrings(const std::vector<std::string> &forbiddenStrings)
 {
        try {
                return context->methodCall<int>("PasswordPolicy::setForbiddenStrings", forbiddenStrings);
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return -1;
        }
 }
@@ -265,7 +265,7 @@ std::vector<std::string> PasswordPolicy::getForbiddenStrings()
        std::vector<std::string> error;
        try {
                return context->methodCall<std::vector<std::string>>("PasswordPolicy::getForbiddenStrings");
-       } catch (runtime::Exceptione) {
+       } catch (runtime::Exception &e) {
                return error;
        }
 }
index d53674c..7c148c3 100644 (file)
@@ -33,44 +33,43 @@ public:
        } PasswordPolicyQuality;
 
        typedef enum {
-               DPM_PASSWORD_STATUS_NORMAL,                           /**< Password normal status */
+               DPM_PASSWORD_STATUS_NORMAL,                  /**< Password normal status */
                DPM_PASSWORD_STATUS_CHANGED,                 /**< Password successfully changed */
                DPM_PASSWORD_STATUS_NOT_CHANGED,             /**< Password not changed */
                DPM_PASSWORD_STATUS_CHANGE_REQUIRED ,        /**< Password change required */
-               DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED,  /**< Password Max Attempts Exceeded*/
+               DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED,   /**< Password Max Attempts Exceeded*/
                DPM_PASSWORD_STATUS_MAX
        } PasswordPolicyStatus;
 
        PasswordPolicy(PolicyControlContext &ctxt);
        ~PasswordPolicy();
 
-       int setPasswordPolicyQuality(const int quality);
-       int getPasswordPolicyQuality();
-       int setPasswordPolicyMinimumLength(const int value);
-       int getPasswordPolicyMinimumLength();
-       int setMinPasswordPolicyComplexChars(const int value);
-       int getMinPasswordPolicyComplexChars();
-       int setMaximumFailedPasswordPolicyForWipe(const int value);
-       int getMaximumFailedPasswordPolicyForWipe();
-       int setPasswordPolicyExpires(const int value);
-       int getPasswordPolicyExpires();
-       int setPasswordPolicyHistory(const int value);
-       int getPasswordPolicyHistory();
-       int setPasswordPolicyPattern(const std::string &pattern);
-       int resetPasswordPolicy(const std::string &passwd);
-       int enforcePasswordPolicyChange();
-       int setMaxInactivityTimeDeviceLock(const int value);
+       int setQuality(int quality);
+       int getQuality();
+       int setMinimumLength(int value);
+       int getMinimumLength();
+       int setMinComplexChars(int value);
+       int getMinComplexChars();
+       int setMaximumFailedForWipe(int value);
+       int getMaximumFailedForWipe();
+       int setExpires(int value);
+       int getExpires();
+       int setHistory(int value);
+       int getHistory();
+       int setPattern(const std::string &pattern);
+       int reset(const std::string &passwd);
+       int enforceChange();
+       int setMaxInactivityTimeDeviceLock(int value);
        int getMaxInactivityTimeDeviceLock();
-       std::string getPasswordPolicyPolicy();
-       int setPasswordPolicyStatus(const int status);
-       int getPasswordPolicyStatus();
-       int deletePasswordPolicyPattern();
-       std::string getPasswordPolicyPattern();
-       int setMaximumCharacterOccurrences(const int value);
+       int setStatus(int status);
+       int getStatus();
+       int deletePattern();
+       std::string getPattern();
+       int setMaximumCharacterOccurrences(int value);
        int getMaximumCharacterOccurrences();
-       int setMaximumNumericSequenceLength(const int value);
+       int setMaximumNumericSequenceLength(int value);
        int getMaximumNumericSequenceLength();
-       int setForbiddenStrings(const std::vector<std::string> &forbiddenPasswds);
+       int setForbiddenStrings(const std::vector<std::string> &forbiddenStrings);
        std::vector<std::string> getForbiddenStrings();
 
 private:
index 791b0c4..5c0a65c 100644 (file)
@@ -19,6 +19,7 @@ SET(POLICY      ${POLICY}
                                location.cpp
                                password.cpp
                                krate.cpp
+                               password-manager.cpp
 )
 
 SET(DEPENDENCY  ${DEPENDENCY}
index a6c7953..9a585db 100644 (file)
@@ -19,6 +19,7 @@ SET(POLICY      ${POLICY}
                                location.cpp
                                password.cpp
                                krate.cpp
+                               password-manager.cpp
 )
 
 SET(DEPENDENCY  ${DEPENDENCY}
index a6c7953..9a585db 100644 (file)
@@ -19,6 +19,7 @@ SET(POLICY      ${POLICY}
                                location.cpp
                                password.cpp
                                krate.cpp
+                               password-manager.cpp
 )
 
 SET(DEPENDENCY  ${DEPENDENCY}
diff --git a/server/password-manager.cpp b/server/password-manager.cpp
new file mode 100644 (file)
index 0000000..9cfafa8
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <klay/exception.h>
+
+#include "password-manager.h"
+
+PasswordManager::PasswordManager(uid_t uid) :
+       user(uid)
+{
+       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to get auth instance");
+       }
+
+       auth_passwd_set_user(p_policy, user);
+}
+
+PasswordManager::~PasswordManager()
+{
+       auth_passwd_free_policy(p_policy);
+}
+
+void PasswordManager::setQuality(PasswordManager::QualityType quality)
+{
+       if (auth_passwd_set_quality(p_policy, quality) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to enforce password quality");
+       }
+}
+
+void PasswordManager::setMinimumLength(int value)
+{
+       if (auth_passwd_set_min_length(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set minimum length");
+       }
+}
+
+void PasswordManager::setMinimumComplexCharacters(int value)
+{
+       if (auth_passwd_set_min_complex_char_num(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set minimum complex characters");
+       }
+}
+
+void PasswordManager::setMaximumFailedForWipe(int value)
+{
+       if (auth_passwd_set_max_attempts(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set maximum failed count for wipe");
+       }
+}
+
+void PasswordManager::setExpires(int value)
+{
+       if (auth_passwd_set_validity(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set expire");
+       }
+}
+
+void PasswordManager::setHistory(int value)
+{
+       if (auth_passwd_set_history_size(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set history size");
+       }
+}
+
+void PasswordManager::setPattern(const std::string &pattern)
+{
+       if (auth_passwd_set_pattern(p_policy, pattern.c_str()) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set pattern");
+       }
+}
+
+void PasswordManager::deletePatern()
+{
+       if (auth_passwd_set_pattern(p_policy, NULL) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to delete pattern");
+       }
+}
+
+void PasswordManager::setMaximumCharacterOccurrences(int value)
+{
+       if (auth_passwd_set_max_char_occurrences(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set maximum character occurrences");
+       }
+}
+
+void PasswordManager::setMaximumNumericSequenceLength(int value)
+{
+       if (auth_passwd_set_max_num_seq_len(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set maximum numeric sequence length");
+       }
+}
+
+void PasswordManager::setForbiddenStrings(const std::vector<std::string> &forbiddenStrings)
+{
+       for (const std::string& str : forbiddenStrings) {
+               if (auth_passwd_set_forbidden_passwd(p_policy, str.c_str()) != AUTH_PASSWD_API_SUCCESS) {
+                       throw runtime::Exception("Failed to set forbidden strings");
+               }
+       }
+}
+
+void PasswordManager::enforce()
+{
+       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to enforce policy");
+       }
+}
+
+void PasswordManager::resetPassword(const std::string& password)
+{
+       if (auth_passwd_reset_passwd(AUTH_PWD_NORMAL, user, password.c_str()) != AUTH_PASSWD_API_SUCCESS) {
+               throw runtime::Exception("Failed to set reset password");
+       }
+}
diff --git a/server/password-manager.h b/server/password-manager.h
new file mode 100644 (file)
index 0000000..e04da90
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __DPM_PASSWORD_MANAGER_H__
+#define __DPM_PASSWORD_MANAGER_H__
+#include <sys/types.h>
+
+#include <vector>
+#include <string>
+
+#include <auth-passwd-admin.h>
+
+class PasswordManager {
+public:
+       typedef password_quality_type QualityType;
+
+       PasswordManager(uid_t uid);
+       ~PasswordManager();
+
+       void setQuality(QualityType quality);
+       void setMinimumLength(int value);
+       void setMinimumComplexCharacters(int value);
+       void setMaximumFailedForWipe(int value);
+       void setExpires(int value);
+       void setHistory(int value);
+       void setPattern(const std::string &pattern);
+       void deletePatern();
+       void setMaximumCharacterOccurrences(int value);
+       void setMaximumNumericSequenceLength(int value);
+       void setForbiddenStrings(const std::vector<std::string> &forbiddenStrings);
+       void resetPassword(const std::string& password);
+       void enforce();
+
+private:
+       uid_t user;
+       policy_h *p_policy;
+};
+#endif //!__DPM_PASSWORD_MANAGER_H__
index 5213320..b2cd1e5 100644 (file)
 #include <bundle.h>
 #include <notification.h>
 #include <system_settings.h>
-#include <auth-passwd-admin.h>
-#include <klay/auth/user.h>
 #include <klay/audit/logger.h>
 
 #include "privilege.h"
 #include "policy-builder.h"
+#include "password-manager.h"
 
 #include "password.hxx"
 
 #define SIMPLE_PASSWORD_LENGTH 4
-#define PASSWORD_EMPTY_STRING "\\n"
 
 namespace DevicePolicyManager {
 
 namespace {
 
-PasswordPolicy::PasswordPolicyQuality qualityType;
 std::string PasswordPattern;
 std::vector<std::string> ForbiddenStrings;
 
-inline int getPasswordPolicy(PolicyControlContext& ctx, const std::string& name)
+int PasswordStatus = 0;
+
+inline int getPasswordPolicy(PolicyControlContext &ctx, const std::string &name)
 {
        return ctx.getPolicy(name, ctx.getPeerUid());
 }
 
-inline int setPasswordPolicy(PolicyControlContext& ctx, const std::string& name, int value)
+inline int setPasswordPolicy(PolicyControlContext &ctx, const std::string &name, int value)
 {
        return ctx.setPolicy(name, value, "password", name);
 }
@@ -127,64 +126,24 @@ int createNotificationLaunch(void)
        return ret;
 }
 
-int transformValueFromIntToQualityType(const int quality, PasswordPolicy::PasswordPolicyQuality &changed_quality)
+inline PasswordManager::QualityType getPasswordQualityType(int quality)
 {
        switch (quality) {
        case PasswordPolicy::DPM_PASSWORD_QUALITY_UNSPECIFIED:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_UNSPECIFIED;
-               break;
+               return AUTH_PWD_QUALITY_UNSPECIFIED;
        case PasswordPolicy::DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD;
-               break;
+               return AUTH_PWD_QUALITY_UNSPECIFIED;
        case PasswordPolicy::DPM_PASSWORD_QUALITY_SOMETHING:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_SOMETHING;
-               break;
+               return AUTH_PWD_QUALITY_SOMETHING;
        case PasswordPolicy::DPM_PASSWORD_QUALITY_NUMERIC:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_NUMERIC;
-               break;
+               return AUTH_PWD_QUALITY_NUMERIC;
        case PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHABETIC:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHABETIC;
-               break;
+               return AUTH_PWD_QUALITY_ALPHABETIC;
        case PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHANUMERIC:
-               changed_quality = PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHANUMERIC;
-               break;
+               return AUTH_PWD_QUALITY_ALPHANUMERIC;
        default:
-               ERROR("unknown password quality");
-               return -1;
-               break;
+               throw runtime::Exception("Unknown quality type: " + std::to_string(quality));
        }
-
-       return 0;
-}
-
-int transformQualityFromDPMToAuth(const int dpm_quality, password_quality_type &auth_quality)
-{
-       switch (dpm_quality) {
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_UNSPECIFIED:
-               auth_quality = AUTH_PWD_QUALITY_UNSPECIFIED;
-               break;
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD:
-               auth_quality = AUTH_PWD_QUALITY_UNSPECIFIED;
-               break;
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_SOMETHING:
-               auth_quality = AUTH_PWD_QUALITY_SOMETHING;
-               break;
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_NUMERIC:
-               auth_quality = AUTH_PWD_QUALITY_NUMERIC;
-               break;
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHABETIC:
-               auth_quality = AUTH_PWD_QUALITY_ALPHABETIC;
-               break;
-       case PasswordPolicy::DPM_PASSWORD_QUALITY_ALPHANUMERIC:
-               auth_quality = AUTH_PWD_QUALITY_ALPHANUMERIC;
-               break;
-       default:
-               ERROR("unknown");
-               return -1;
-               break;
-       }
-
-       return 0;
 }
 
 } // namespace
@@ -192,31 +151,31 @@ int transformQualityFromDPMToAuth(const int dpm_quality, password_quality_type &
 PasswordPolicy::PasswordPolicy(PolicyControlContext &ctxt) :
        context(ctxt)
 {
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyQuality)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyMinimumLength)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMinPasswordPolicyComplexChars)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumFailedPasswordPolicyForWipe)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyExpires)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyHistory)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyPattern)(std::string));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::resetPasswordPolicy)(std::string));
-       ctxt.registerNonparametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::enforcePasswordPolicyChange));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setQuality)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMinimumLength)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMinComplexChars)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumFailedForWipe)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setExpires)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setHistory)(int));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPattern)(std::string));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::reset)(std::string));
+       ctxt.registerNonparametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::enforceChange));
        ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaxInactivityTimeDeviceLock)(int));
-       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setPasswordPolicyStatus)(int));
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getPasswordPolicyStatus));
-       ctxt.registerNonparametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::deletePasswordPolicyPattern));
+       ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setStatus)(int));
+       ctxt.registerNonparametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::deletePattern));
        ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumCharacterOccurrences)(int));
        ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumNumericSequenceLength)(int));
        ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setForbiddenStrings)(std::vector<std::string>));
 
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getPasswordPolicyQuality));
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getPasswordPolicyMinimumLength));
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMinPasswordPolicyComplexChars));
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumFailedPasswordPolicyForWipe));
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getPasswordPolicyExpires)());
-       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getPasswordPolicyHistory)());
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getStatus));
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getQuality));
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMinimumLength));
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMinComplexChars));
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumFailedForWipe));
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getExpires)());
+       ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getHistory)());
        ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaxInactivityTimeDeviceLock));
-       ctxt.registerNonparametricMethod(this, "", (std::string)(PasswordPolicy::getPasswordPolicyPattern));
+       ctxt.registerNonparametricMethod(this, "", (std::string)(PasswordPolicy::getPattern));
        ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumCharacterOccurrences));
        ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumNumericSequenceLength));
        ctxt.registerNonparametricMethod(this, "", (std::vector<std::string>)(PasswordPolicy::getForbiddenStrings));
@@ -228,272 +187,162 @@ PasswordPolicy::~PasswordPolicy()
 {
 }
 
-int PasswordPolicy::setPasswordPolicyQuality(const int quality)
+int PasswordPolicy::setQuality(int quality)
 {
-       policy_h *p_policy;
-       password_quality_type auth_quality_type = AUTH_PWD_QUALITY_UNSPECIFIED;
-
-       if (transformValueFromIntToQualityType(quality, qualityType) != 0) {
-               return -1;
-       }
-
-       if (transformQualityFromDPMToAuth(qualityType, auth_quality_type) != 0) {
-               return -1;
-       }
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_quality(p_policy, auth_quality_type) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setQuality(getPasswordQualityType(quality));
 
-       if (qualityType == PasswordPolicy::DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) {
-               if (auth_passwd_set_min_length(p_policy, SIMPLE_PASSWORD_LENGTH) != AUTH_PASSWD_API_SUCCESS) {
-                       auth_passwd_free_policy(p_policy);
-                       return -1;
+               if (quality == DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) {
+                       passwordManager.setMinimumLength(SIMPLE_PASSWORD_LENGTH);
                }
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        setPasswordPolicy(context, "password-quality", quality);
-       if (qualityType == PasswordPolicy::DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) {
+       if (quality == DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) {
                setPasswordPolicy(context, "password-minimum-length", SIMPLE_PASSWORD_LENGTH);
        }
 
        return 0;
 }
 
-int PasswordPolicy::getPasswordPolicyQuality()
+int PasswordPolicy::getQuality()
 {
        return getPasswordPolicy(context, "password-quality");
 }
 
-int PasswordPolicy::setPasswordPolicyMinimumLength(const int value)
+int PasswordPolicy::setMinimumLength(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_min_length(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
 
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+               passwordManager.setMinimumLength(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set minimum length");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-minimum-length", value);
 }
 
-int PasswordPolicy::getPasswordPolicyMinimumLength()
+int PasswordPolicy::getMinimumLength()
 {
        return getPasswordPolicy(context, "password-minimum-length");
 }
 
-int PasswordPolicy::setMinPasswordPolicyComplexChars(const int value)
+int PasswordPolicy::setMinComplexChars(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_min_complex_char_num(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setMinimumComplexCharacters(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set minimum complex characters");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-minimum-complexity", value);
 }
 
-int PasswordPolicy::getMinPasswordPolicyComplexChars()
+int PasswordPolicy::getMinComplexChars()
 {
        return getPasswordPolicy(context, "password-minimum-complexity");
 }
 
-int PasswordPolicy::setMaximumFailedPasswordPolicyForWipe(const int value)
+int PasswordPolicy::setMaximumFailedForWipe(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_max_attempts(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setMaximumFailedForWipe(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set maximum failed count for wipe");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-maximum-failure-count", (value == 0) ? UINT_MAX : value);
 }
 
-int PasswordPolicy::getMaximumFailedPasswordPolicyForWipe()
+int PasswordPolicy::getMaximumFailedForWipe()
 {
        unsigned int result = getPasswordPolicy(context, "password-maximum-failure-count");
-       return (result == UINT_MAX)? 0 : result;
+       return (result == UINT_MAX) ? 0 : result;
 }
 
-int PasswordPolicy::setPasswordPolicyExpires(const int value)
+int PasswordPolicy::setExpires(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_validity(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setExpires(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set expire");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-expired", (value == 0) ? UINT_MAX : value);
 }
 
-int PasswordPolicy::getPasswordPolicyExpires()
+int PasswordPolicy::getExpires()
 {
        unsigned int result = getPasswordPolicy(context, "password-expired");
-       return (result == UINT_MAX)? 0 : result;
+       return (result == UINT_MAX) ? 0 : result;
 }
 
-int PasswordPolicy::setPasswordPolicyHistory(const int value)
+int PasswordPolicy::setHistory(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_history_size(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setHistory(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set history size");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-history", value);
 }
 
-int PasswordPolicy::getPasswordPolicyHistory()
+int PasswordPolicy::getHistory()
 {
        return getPasswordPolicy(context, "password-history");
 }
 
-int PasswordPolicy::setPasswordPolicyPattern(const std::string &pattern)
+int PasswordPolicy::setPattern(const std::string &pattern)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_pattern(p_policy, pattern.c_str()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setPattern(pattern.c_str());
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to set pattern");
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        PasswordPattern = pattern;
-       if (PasswordPattern.compare("") == 0)
-               PasswordPattern = PASSWORD_EMPTY_STRING;
 
-       return 0;//SetPolicy(context, "password-pattern", PasswordPattern);
+       return 0;
 }
 
-int PasswordPolicy::resetPasswordPolicy(const std::string &passwd)
+int PasswordPolicy::reset(const std::string &passwd)
 {
-       int ret = 0;
-
-       if (auth_passwd_reset_passwd(AUTH_PWD_NORMAL, context.getPeerUid(), passwd.c_str()) != AUTH_PASSWD_API_SUCCESS) {
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.resetPassword(passwd);
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       return ret;
+       return 0;
 }
 
-int PasswordPolicy::enforcePasswordPolicyChange()
+int PasswordPolicy::enforceChange()
 {
        int ret = 0;
        int lock_type = 0;
@@ -507,18 +356,20 @@ int PasswordPolicy::enforcePasswordPolicyChange()
                ::bundle_add_str_array(b, "user-data", simple_user_data, 6);
        else
                ::bundle_add_str_array(b, "user-data", passwd_user_data, 6);
+
        ret = ::aul_launch_app_for_uid("org.tizen.dpm-syspopup", b, context.getPeerUid());
        ::bundle_free(b);
 
        if (ret < 0) {
                ERROR("Failed to launch Password Application.");
                return -1;
-       } else {
-               return setPasswordPolicy(context, "password-status", PasswordPolicy::DPM_PASSWORD_STATUS_CHANGE_REQUIRED);
        }
+
+       PasswordStatus = DPM_PASSWORD_STATUS_CHANGE_REQUIRED;
+       return 0;
 }
 
-int PasswordPolicy::setMaxInactivityTimeDeviceLock(const int value)
+int PasswordPolicy::setMaxInactivityTimeDeviceLock(int value)
 {
        return setPasswordPolicy(context, "password-inactivity-timeout", value);
 }
@@ -528,211 +379,119 @@ int PasswordPolicy::getMaxInactivityTimeDeviceLock()
        return getPasswordPolicy(context, "password-inactivity-timeout");
 }
 
-int PasswordPolicy::setPasswordPolicyStatus(const int status)
+int PasswordPolicy::setStatus(int status)
 {
-       int current_status = getPasswordPolicy(context, "password-status");
-
-       if (status >= PasswordPolicy::DPM_PASSWORD_STATUS_MAX) {
+       if (status >= DPM_PASSWORD_STATUS_MAX) {
                return -1;
        }
 
-       if (status == PasswordPolicy::DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED) {
+       if (status == DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED) {
                ERROR("Max Attempts Exceeded.");
                return -1;
        }
 
-       if (current_status == PasswordPolicy::DPM_PASSWORD_STATUS_CHANGE_REQUIRED) {
-               if (status == PasswordPolicy::DPM_PASSWORD_STATUS_CHANGED) {
-                       return setPasswordPolicy(context, "password-status", PasswordPolicy::DPM_PASSWORD_STATUS_NORMAL);
-               } else if (status == PasswordPolicy::DPM_PASSWORD_STATUS_NOT_CHANGED) {
+       if (PasswordStatus == DPM_PASSWORD_STATUS_CHANGE_REQUIRED) {
+               if (status == DPM_PASSWORD_STATUS_CHANGED) {
+                       PasswordStatus = DPM_PASSWORD_STATUS_NORMAL;
+                       return 0;
+               } else if (status == DPM_PASSWORD_STATUS_NOT_CHANGED) {
                        return createNotificationLaunch();
                }
-       } else if (current_status ==  PasswordPolicy::DPM_PASSWORD_STATUS_NORMAL) {
-               if (status == PasswordPolicy::DPM_PASSWORD_STATUS_CHANGE_REQUIRED) {
-                       return setPasswordPolicy(context, "password-status", status);
+       } else if (PasswordStatus == DPM_PASSWORD_STATUS_NORMAL) {
+               if (status == DPM_PASSWORD_STATUS_CHANGE_REQUIRED) {
+                       PasswordStatus = status;
+                       return 0;
                }
        }
 
        return -1;
 }
 
-int PasswordPolicy::getPasswordPolicyStatus()
+int PasswordPolicy::getStatus()
 {
-       int status = context.getPolicy("password-status");
-       return status;
+       return PasswordStatus;
 }
 
-int PasswordPolicy::deletePasswordPolicyPattern()
+int PasswordPolicy::deletePattern()
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_pattern(p_policy, NULL) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.deletePatern();
+               passwordManager.enforce();
+               PasswordPattern.clear();
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
-       PasswordPattern.clear();
-       return 0;//SetPolicy(context, "password-pattern", PASSWORD_EMPTY_STRING);
+       return 0;
 }
 
-std::string PasswordPolicy::getPasswordPolicyPattern()
+std::string PasswordPolicy::getPattern()
 {
-       PasswordPattern = getPasswordPolicy(context, "password-pattern");
-       if (PasswordPattern.compare(PASSWORD_EMPTY_STRING) == 0)
-               PasswordPattern = "";
-
        return PasswordPattern;
 }
 
-int PasswordPolicy::setMaximumCharacterOccurrences(const int value)
+int PasswordPolicy::setMaximumCharacterOccurrences(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_max_char_occurrences(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setMaximumCharacterOccurrences(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-maximum-character-occurrences", (value == 0) ? UINT_MAX : value);
 }
 
 int PasswordPolicy::getMaximumCharacterOccurrences()
 {
 
-    unsigned int result = getPasswordPolicy(context, "password-maximum-character-occurrences");
-       return (result == UINT_MAX)? 0 : result;
+       unsigned int result = getPasswordPolicy(context, "password-maximum-character-occurrences");
+       return (result == UINT_MAX) ? 0 : result;
 }
 
-int PasswordPolicy::setMaximumNumericSequenceLength(const int value)
+int PasswordPolicy::setMaximumNumericSequenceLength(int value)
 {
-       policy_h *p_policy;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_max_num_seq_len(p_policy, value) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
+               passwordManager.setMaximumNumericSequenceLength(value);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        return setPasswordPolicy(context, "password-numeric-sequences-length", (value == 0) ? UINT_MAX : value);
 }
 
 int PasswordPolicy::getMaximumNumericSequenceLength()
 {
        unsigned int result = getPasswordPolicy(context, "password-numeric-sequences-length");
-       return (result == UINT_MAX)? 0 : result;
+       return (result == UINT_MAX) ? 0 : result;
 }
 
 int PasswordPolicy::setForbiddenStrings(const std::vector<std::string> &forbiddenStrings)
 {
-       unsigned int count = 0;
-       policy_h *p_policy;
-       std::string xmlForbiddenStrings;
-
-       if (auth_passwd_new_policy(&p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               return -1;
-       }
-
-       if (auth_passwd_set_user(p_policy, context.getPeerUid()) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
-               return -1;
-       }
-
-       for (std::vector<std::string>::const_iterator iter = forbiddenStrings.begin(); iter != forbiddenStrings.end(); ++iter) {
-               if (auth_passwd_set_forbidden_passwd(p_policy, (*iter).c_str()) != AUTH_PASSWD_API_SUCCESS) {
-                       auth_passwd_free_policy(p_policy);
-                       return -1;
-               }
-       }
+       try {
+               PasswordManager passwordManager(context.getPeerUid());
 
-       if (auth_passwd_set_policy(p_policy) != AUTH_PASSWD_API_SUCCESS) {
-               auth_passwd_free_policy(p_policy);
+               passwordManager.setForbiddenStrings(forbiddenStrings);
+               passwordManager.enforce();
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
                return -1;
        }
 
-       auth_passwd_free_policy(p_policy);
-
        std::copy(forbiddenStrings.begin(), forbiddenStrings.end(), std::back_inserter(ForbiddenStrings));
-       for (std::vector<std::string>::const_iterator iter = forbiddenStrings.begin(); iter != forbiddenStrings.end(); ++iter) {
-               xmlForbiddenStrings += (*iter).c_str();
-               if (++count < forbiddenStrings.size())
-                       xmlForbiddenStrings += PASSWORD_EMPTY_STRING;
-       }
 
-       if (xmlForbiddenStrings.compare("") == 0) {
-               xmlForbiddenStrings = PASSWORD_EMPTY_STRING;
-       }
-
-       return 0;//SetPolicy(context, "password-forbidden-strings", xmlForbiddenStrings.c_str());
+       return 0;
 }
 
 std::vector<std::string> PasswordPolicy::getForbiddenStrings()
 {
-#if 0
-       unsigned int nPos;
-       std::string xmlForbiddenStrings;
-
-       xmlForbiddenStrings = getPasswordPolicy(context, "password-forbidden-strings");
-       ForbiddenStrings.clear();
-       while ((nPos = xmlForbiddenStrings.find_first_of(PASSWORD_EMPTY_STRING)) != xmlForbiddenStrings.npos) {
-               if (nPos > 0) {
-                       ForbiddenStrings.push_back(xmlForbiddenStrings.substr(0, nPos));
-               }
-               xmlForbiddenStrings = xmlForbiddenStrings.substr(nPos + 3);
-       }
-       if (xmlForbiddenStrings.length() > 0)
-               ForbiddenStrings.push_back(xmlForbiddenStrings.substr(0, nPos));
-
-       if ((*ForbiddenStrings.begin()).compare(PASSWORD_EMPTY_STRING) == 0)
-               *ForbiddenStrings.begin() = "";
-#endif
-
        return ForbiddenStrings;
 }
 
index 950cf6f..325dce8 100644 (file)
@@ -17,6 +17,7 @@ SET(POLICY      ${POLICY}
                                bluetooth.cpp
                                location.cpp
                                password.cpp
+                               password-manager.cpp
 )
 
 SET(DEPENDENCY  ${DEPENDENCY}