apply E_USER_NOT_CONSENTED
[platform/framework/native/web.git] / src / controls / FWebCtrlAuthenticationChallenge.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
18 /**
19  * @file                FWebCtrlAuthenticationChallenge.cpp
20  * @brief               The file contains the definition of AuthenticationChallenge class.
21  *
22  * The file contains the definition of AuthenticationChallenge class.
23  */
24 #include <FBaseResult.h>
25 #include <FBaseSysLog.h>
26 #include <FWebCtrlAuthenticationChallenge.h>
27 #include <FSec_AccessController.h>
28 #include "FWebCtrl_AuthenticationChallengeImpl.h"
29
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34
35 namespace Tizen { namespace Web { namespace Controls
36 {
37
38
39 AuthenticationChallenge::AuthenticationChallenge(void)
40         : __pAuthenticationChallengeImpl(new (std::nothrow) _AuthenticationChallengeImpl())
41 {
42         SysTryReturnVoidResult(NID_WEB_CTRL, __pAuthenticationChallengeImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
43 }
44
45
46 AuthenticationChallenge::~AuthenticationChallenge(void)
47 {
48         delete __pAuthenticationChallengeImpl;
49         __pAuthenticationChallengeImpl = null;
50 }
51
52
53 void
54 AuthenticationChallenge::Process(const UserId& userId, const String& password)
55 {
56         SysAssertf(__pAuthenticationChallengeImpl != null, "Not yet constructed. Construct() should be called before use.");
57
58         ClearLastResult();
59         result r = E_SUCCESS;
60
61         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
62         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
63         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
64
65         __pAuthenticationChallengeImpl->Process(userId, password);
66
67         SysLog(NID_WEB_CTRL, "The current value of userId is %ls, password is %ls", userId.GetPointer(), password.GetPointer());
68 }
69
70
71 void
72 AuthenticationChallenge::Cancel(void)
73 {
74         SysAssertf(__pAuthenticationChallengeImpl != null, "Not yet constructed. Construct() should be called before use.");
75
76         ClearLastResult();
77         result r = E_SUCCESS;
78
79         r = _AccessController::CheckUserPrivilege(_PRV_WEB_SERVICE);
80         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
81         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
82
83         __pAuthenticationChallengeImpl->Cancel();
84 }
85
86
87 }}} // Tizen::Web::Controls