2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 // @ Project : Access Control Engine
21 // @ File Name : PolicyInformationPoint.cpp
22 // @ Date : 2009-05-06
30 #include <ace/PolicyInformationPoint.h>
31 #include <ace/ConfigurationManager.h>
33 #include <dpl/log/log.h>
34 #include <dpl/assert.h>
35 #include <dpl/foreach.h>
37 #include <ace/Attribute.h>
38 #include <ace-dao-ro/BaseAttribute.h>
39 #include <ace-dao-ro/AceDAOReadOnly.h>
41 using namespace AceDB;
43 PolicyInformationPoint::PolicyInformationPoint(IWebRuntime *wrt,
44 IResourceInformation *resource,
45 IOperationSystem *system) : wrtInterface(wrt),
46 resourceInformation(resource),
47 operationSystem(system)
49 AceDB::AceDAOReadOnly::attachToThreadRO();
52 PolicyInformationPoint::~PolicyInformationPoint()
54 AceDB::AceDAOReadOnly::detachFromThread();
57 /* gather attributes values from adequate interfaces */
58 PipResponse PolicyInformationPoint::getAttributesValues(const Request* request,
59 AttributeSet* attributes)
61 int subjectReturn = 0;
62 int resourceReturn = 0;
63 int operationReturn = 0;
64 int functionReturn = 0;
65 /* create query lists */
66 createQueries(attributes);
68 /* check if subject attributes query has any elements*/
69 if (!subjectAttributesQuery.empty()) {
70 /* get Subject Attributes */
71 subjectReturn = wrtInterface->getAttributesValues(
73 &subjectAttributesQuery);
76 AttributeSet::const_iterator iter2;
77 FOREACH(iter, subjectAttributesQuery)
79 if (iter->second == NULL) {
80 Attribute attr(*(iter->first));
81 attr.setType(Attribute::Type::Subject);
82 iter2 = std::find_if(attributes->begin(),
84 BaseAttribute::UnaryPredicate(&attr));
85 Assert(iter2 != attributes->end() && "This should not happen, "
86 "the attribute MUST be in attribute set");
87 (*iter2)->setUndetermind(true);
91 /* check if resource attributes query has any elements*/
92 if (!resourceAttributesQuery.empty()) {
93 /* get Resource Attributes */
94 resourceReturn = resourceInformation->getAttributesValues(
96 &resourceAttributesQuery);
98 resourceReturn <<= ERROR_SHIFT_RESOURCE;
101 FOREACH(iter, resourceAttributesQuery)
103 if (iter->second == NULL) {
104 LogInfo("Found undetermined attribute");
105 Attribute attr(*(iter->first));
106 attr.setType(Attribute::Type::Resource);
107 iter2 = std::find_if(attributes->begin(),
109 BaseAttribute::UnaryPredicate(&attr));
110 Assert(iter2 != attributes->end() && "This should not happen, "
111 "the attribute MUST be in attribute set");
112 (*iter2)->setUndetermind(true);
116 /* check if resource attributes query has any elements*/
117 if (!environmentAttributesQuery.empty()) {
118 /* get enviroment attributes */
119 operationReturn = operationSystem->getAttributesValues(
121 &environmentAttributesQuery);
123 operationReturn <<= ERROR_SHIFT_OS;
126 FOREACH(iter, environmentAttributesQuery)
128 if (iter->second == NULL) {
129 //it doesnt change uniqueness of a set element so we can const_cast
130 Attribute attr(*(iter->first));
131 attr.setType(Attribute::Type::Environment);
132 iter2 = find_if(attributes->begin(),
134 BaseAttribute::UnaryPredicate(&attr));
135 Assert(iter2 != attributes->end() && "This should not happen, "
136 "the attribute MUST be in attribute set");
137 (*iter2)->setUndetermind(true);
141 /* check if functionParam attributes query has any elements*/
142 if (!functionParamAttributesQuery.empty() && request->getFunctionParam()) {
143 /* get params attributes */
144 functionReturn = request->getFunctionParam()->getAttributesValues(
146 &functionParamAttributesQuery);
148 functionReturn <<= ERROR_SHIFT_FP;
151 FOREACH(iter, functionParamAttributesQuery)
153 if (iter->second == NULL) {
154 //it doesnt change uniqueness of a set element so we can const_cast
155 Attribute attr(*(iter->first));
156 attr.setType(Attribute::Type::FunctionParam);
157 iter2 = find_if(attributes->begin(),
159 BaseAttribute::UnaryPredicate(&attr));
160 Assert(iter2 != attributes->end() && "This should not happen, "
161 "the attribute MUST be in attribute set");
162 (*iter2)->setUndetermind(true);
166 // Here we must add to attributes proper marking of policy type
167 // (Tizen or WAC widget)
169 * This part of code seems odd here, but we don't want to keep it in
170 * attribute fascade, as it is maintained by ACE clients and we are not
171 * sure if this kind of distinction between different policies will be ok
174 * This is somehow private part of ACE, so it may be moved into
175 * separate ACEAttributeFascade kind of a class in (already planned)
176 * refactoring, when moving to new, C-only API for ACE.
178 if (widgetParamAttributesQuery.empty()) {
179 LogError("No attrbutes of WidgetParam type present - "
180 "should be widget type at least");
182 LogDebug("WidgetParam type atributes present, searching for widget type");
183 FOREACH(iter, widgetParamAttributesQuery) {
184 const std::string *name = iter->first;
185 if (POLICY_WIDGET_TYPE_ATTRIBUTE_NAME == *name) {
186 LogDebug("Widget type attribute found");
188 // Extracting widget type
189 std::list<std::string> attrValue;
191 AceDB::AppTypes appType =
192 AceDB::AceDAOReadOnly::getWidgetType(
193 request->getWidgetHandle());
195 case AceDB::AppTypes::Tizen : {
196 attrValue.push_back(POLICY_NAME_TIZEN);
197 LogDebug("==== Using Tizen policy in PIP ====");
199 case AceDB::AppTypes::WAC20 : {
200 attrValue.push_back(POLICY_NAME_WAC2_0);
201 LogDebug("==== Using WAC policy in PIP ====");
204 LogError("Invalid widget type");
207 } Catch (AceDB::AceDAOReadOnly::Exception::DatabaseError)
209 LogError("Couldn't find widget for handle "
210 << request->getWidgetHandle());
213 // Setting real attribute value
214 Attribute attr(*(iter->first));
215 attr.setType(Attribute::Type::WidgetParam);
216 iter2 = find_if(attributes->begin(),
218 BaseAttribute::UnaryPredicate(&attr));
219 Assert(iter2 != attributes->end() && "This should not happen, "
220 "the attribute MUST be in attribute set");
221 (*iter2)->setUndetermind(false);
222 (*iter2)->setValue(attrValue);
227 /** clear query lists*/
228 resourceAttributesQuery.clear();
229 environmentAttributesQuery.clear();
230 subjectAttributesQuery.clear();
231 functionParamAttributesQuery.clear();
232 widgetParamAttributesQuery.clear();
234 return subjectReturn | resourceReturn | operationReturn | functionReturn;
237 /** create query lists */
238 void PolicyInformationPoint::createQueries(AttributeSet* attributes)
240 AttributeSet::const_iterator it;
242 enum Attribute::Type type;
244 /**iterate all attributes and split them into adequate query */
245 FOREACH (it, *attributes) {
246 type = (*it)->getType();
249 case Attribute::Type::Subject:
250 subjectAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
254 case Attribute::Type::Environment:
255 environmentAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
259 case Attribute::Type::Resource:
260 resourceAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
264 case Attribute::Type::FunctionParam:
265 functionParamAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
269 case Attribute::Type::WidgetParam:
270 widgetParamAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),