Add E_USER_NOT_CONSENTED error
[platform/framework/native/net.git] / src / http / FNetHttpHttpAuthentication.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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                FNetHttpHttpAuthentication.cpp
20  * @brief               This is the implementation file for HttpAuthentication class.
21  *
22  * This file contains the implementation of HttpAuthentication class.
23  */
24
25 #include <FBaseString.h>
26 #include <FNetHttpHttpAuthentication.h>
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include "FNetHttp_HttpAuthenticationImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Net { namespace Http
35 {
36
37 HttpAuthentication::HttpAuthentication(void)
38 {
39         __pHttpAuthenticationImpl = new (std::nothrow) _HttpAuthenticationImpl();
40         SysTryReturnVoidResult(NID_NET_HTTP, __pHttpAuthenticationImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
41 }
42
43 HttpAuthentication::~HttpAuthentication(void)
44 {
45         if (__pHttpAuthenticationImpl != null)
46         {
47                 delete __pHttpAuthenticationImpl;
48                 __pHttpAuthenticationImpl = null;
49         }
50 }
51
52 String*
53 HttpAuthentication::GetRealmN(void) const
54 {
55         result r = E_SUCCESS;
56
57         r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
58         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
59         SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
60
61         String* pRealm = __pHttpAuthenticationImpl->GetRealmN();
62         if (IsFailed(r))
63         {
64                 SysLogException(NID_NET_HTTP, r, "[%s] Propagating.", GetErrorMessage(r));
65
66                 if (pRealm != null)
67                         delete pRealm;
68
69                 return null;
70         }
71
72         return pRealm;
73 }
74
75 NetHttpAuthScheme
76 HttpAuthentication::GetAuthScheme(void) const
77 {
78         result r = E_SUCCESS;
79
80         r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
81         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
82         SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, NET_HTTP_AUTH_NONE, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
83
84         NetHttpAuthScheme scheme = __pHttpAuthenticationImpl->GetAuthScheme();
85         r = GetLastResult();
86         SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, NET_HTTP_AUTH_NONE, r, "[%s] Propagating.", GetErrorMessage(r));
87
88         return scheme;
89 }
90
91 HttpTransaction*
92 HttpAuthentication::SetCredentials(HttpCredentials& credentials)
93 {
94         result r = E_SUCCESS;
95
96         r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
97         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
98         SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
99
100         HttpTransaction* pTransaction = __pHttpAuthenticationImpl->SetCredentials(credentials);
101         r = GetLastResult();
102         SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         return pTransaction;
105 }
106
107 } } } // Tizen::Net::Http