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
26 #include <dpl/ace/PolicyInformationPoint.h>
29 #include <dpl/log/log.h>
31 #include <dpl/assert.h>
32 #include <dpl/foreach.h>
34 #include <dpl/ace/Attribute.h>
35 #include <dpl/ace-dao-ro/BaseAttribute.h>
37 using namespace AceDB;
39 PolicyInformationPoint::~PolicyInformationPoint()
43 /* gather attributes values from adequate interfaces */
44 PipResponse PolicyInformationPoint::getAttributesValues(const Request* request,
45 AttributeSet* attributes)
47 int subjectReturn = 0;
48 int resourceReturn = 0;
49 int operationReturn = 0;
50 int functionReturn = 0;
51 /* create query lists */
52 createQueries(attributes);
54 /* check if subject attributes query has any elements*/
55 if (!subjectAttributesQuery.empty()) {
56 /* get Subject Attributes */
57 subjectReturn = wrtInterface->getAttributesValues(
59 &subjectAttributesQuery);
62 AttributeSet::const_iterator iter2;
63 FOREACH(iter, subjectAttributesQuery)
65 if (iter->second == NULL) {
66 Attribute attr(*(iter->first));
67 attr.setType(Attribute::Type::Subject);
68 iter2 = std::find_if(attributes->begin(),
70 BaseAttribute::UnaryPredicate(&attr));
71 Assert(iter2 != attributes->end() && "This should not happen, "
72 "the attribute MUST be in attribute set");
73 (*iter2)->setUndetermind(true);
77 /* check if resource attributes query has any elements*/
78 if (!resourceAttributesQuery.empty()) {
79 /* get Resource Attributes */
80 resourceReturn = resourceInformation->getAttributesValues(
82 &resourceAttributesQuery);
84 resourceReturn <<= ERROR_SHIFT_RESOURCE;
87 FOREACH(iter, resourceAttributesQuery)
89 if (iter->second == NULL) {
90 LogInfo("Found undetermined attribute");
91 Attribute attr(*(iter->first));
92 attr.setType(Attribute::Type::Resource);
93 iter2 = std::find_if(attributes->begin(),
95 BaseAttribute::UnaryPredicate(&attr));
96 Assert(iter2 != attributes->end() && "This should not happen, "
97 "the attribute MUST be in attribute set");
98 (*iter2)->setUndetermind(true);
102 /* check if resource attributes query has any elements*/
103 if (!environmentAttributesQuery.empty()) {
104 /* get enviroment attributes */
105 operationReturn = operationSystem->getAttributesValues(
107 &environmentAttributesQuery);
109 operationReturn <<= ERROR_SHIFT_OS;
112 FOREACH(iter, environmentAttributesQuery)
114 if (iter->second == NULL) {
115 //it doesnt change uniqueness of a set element so we can const_cast
116 Attribute attr(*(iter->first));
117 attr.setType(Attribute::Type::Environment);
118 iter2 = find_if(attributes->begin(),
120 BaseAttribute::UnaryPredicate(&attr));
121 Assert(iter2 != attributes->end() && "This should not happen, "
122 "the attribute MUST be in attribute set");
123 (*iter2)->setUndetermind(true);
127 /* check if functionParam attributes query has any elements*/
128 if (!functionParamAttributesQuery.empty() && request->getFunctionParam()) {
129 /* get params attributes */
130 functionReturn = request->getFunctionParam()->getAttributesValues(
132 &functionParamAttributesQuery);
134 functionReturn <<= ERROR_SHIFT_FP;
137 FOREACH(iter, functionParamAttributesQuery)
139 if (iter->second == NULL) {
140 //it doesnt change uniqueness of a set element so we can const_cast
141 Attribute attr(*(iter->first));
142 attr.setType(Attribute::Type::FunctionParam);
143 iter2 = find_if(attributes->begin(),
145 BaseAttribute::UnaryPredicate(&attr));
146 Assert(iter2 != attributes->end() && "This should not happen, "
147 "the attribute MUST be in attribute set");
148 (*iter2)->setUndetermind(true);
152 /** clear query lists*/
153 resourceAttributesQuery.clear();
154 environmentAttributesQuery.clear();
155 subjectAttributesQuery.clear();
156 functionParamAttributesQuery.clear();
158 return subjectReturn | resourceReturn | operationReturn | functionReturn;
161 /** create query lists */
162 void PolicyInformationPoint::createQueries(AttributeSet* attributes)
164 AttributeSet::const_iterator it;
166 enum Attribute::Type type;
168 /**iterate all attributes and split them into adequate query */
169 FOREACH (it, *attributes) {
170 type = (*it)->getType();
173 case Attribute::Type::Subject:
174 subjectAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
178 case Attribute::Type::Environment:
179 environmentAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
183 case Attribute::Type::Resource:
184 resourceAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),
188 case Attribute::Type::FunctionParam:
189 functionParamAttributesQuery.push_back(ATTRIBUTE((*it)->getName(),