tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / src / services / ace / logic / security_controller.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * This class simply redirects the access requests to access control engine.
18  * The aim is to hide access control engine specific details from WRT modules.
19  * It also implements WRT_INTERFACE.h interfaces, so that ACE could access
20  * WRT specific and other information during the decision making.
21  *
22  * @file    security_controller.cpp
23  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
24  * @author  Ming Jin(ming79.jin@samsung.com)
25  * @version 1.0
26  * @brief   Implementation file for security controller
27  */
28 #include <security_controller.h>
29 #include <ace/PolicyEnforcementPoint.h>
30 #include <ace/WRT_INTERFACE.h>
31 //#include <engine/PolicyEvaluatorFactory.h>
32 //#include <logic/attribute_facade.h>
33 #include <dpl/singleton_impl.h>
34 #include <dpl/log/log.h>
35 #include <security_logic.h>
36 #include <security_caller.h>
37
38 IMPLEMENT_SINGLETON(SecurityController)
39
40 struct SecurityController::Impl
41 {
42     SecurityLogic logic;
43 };
44
45 SecurityController::SecurityController()
46 {
47     m_impl.reset(new Impl);
48 }
49
50 SecurityController::~SecurityController()
51 {
52 }
53
54 void SecurityController::OnEventReceived(
55     const SecurityControllerEvents::InitializeSyncEvent & /* event */)
56 {
57     SecurityCallerSingleton::Instance().Run();
58     m_impl->logic.initialize();
59 }
60
61 void SecurityController::OnEventReceived(
62         const SecurityControllerEvents::UpdatePolicySyncEvent& /* event */)
63 {
64     m_impl->logic.updatePolicy();
65 }
66
67 void SecurityController::OnEventReceived(
68     const SecurityControllerEvents::TerminateSyncEvent & /*event*/)
69 {
70     SecurityCallerSingleton::Instance().Quit();
71     m_impl->logic.terminate();
72 }
73
74 void SecurityController::OnEventReceived(
75     const SecurityControllerEvents::CheckFunctionCallSyncEvent &ev)
76 {
77     *ev.GetArg0() = m_impl->logic.checkFunctionCall(ev.GetArg1());
78 }
79
80 void SecurityController::OnEventReceived(
81     const SecurityControllerEvents::CheckRuntimeCallSyncEvent &ev)
82 {
83     *ev.GetArg0() = m_impl->logic.checkFunctionCall(ev.GetArg1(), ev.GetArg2());
84 }
85
86 void SecurityController::OnEventReceived(
87             const SecurityControllerEvents::ValidatePopupResponseEvent &ev)
88 {
89     m_impl->logic.validatePopupResponse(ev.GetArg0(),
90                                         ev.GetArg1(),
91                                         ev.GetArg2(),
92                                         ev.GetArg3(),
93                                         ev.GetArg4());
94 }