tizen 2.3 release
[framework/web/wearable/wrt-security.git] / ace / engine / Subject.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 #include <dpl/log/log.h>
17 #include <dpl/foreach.h>
18
19 #include <ace/Subject.h>
20
21 bool Subject::matchSubject(const AttributeSet *attrSet,
22         bool &isUndetermined) const
23 {
24     bool result = true;
25     Attribute::MatchResult match = Attribute::MatchResult::MRUndetermined;
26
27     FOREACH(it, targetAttributes)
28     {
29         AttributeSet::const_iterator attr =
30             std::find_if(attrSet->begin(),
31                          attrSet->end(),
32                          AceDB::BaseAttribute::UnaryPredicate(&(*it)));
33         if (attr == attrSet->end()) {
34             LogError("Cannot find attribute value for " << *(it->getName()));
35             Assert(false &&
36                    "Attribute for subject hasn't been found."
37                    "It shoud not happen. This attribute should be undetermined,"
38                    "not missing");
39             result = false; //According to BONDI 1.0 for signle subject all attributes must match
40             isUndetermined = true;
41             break;
42         }
43
44         match = it->matchAttributes(&(*(*attr)));
45
46         if (match == Attribute::MatchResult::MRUndetermined) {
47             result = false;
48             isUndetermined = true;
49             ///          LogError("Subject doesn match and UNDETERMINED");
50             break; //According to BONDI 1.0 for signle subject all attributes must match
51         } else if (match == Attribute::MatchResult::MRFalse) {
52             result = false;
53             //            LogError("Subject doesn match and DETERMINED");
54             break; //According to BONDI 1.0 for signle subject all attributes must match
55         }
56     }
57
58     return result;
59 }
60
61 const std::list<Attribute>& Subject::getTargetAttributes() const
62 {
63     return targetAttributes;
64 }
65