Skip to content

Commit ae8fb34

Browse files
committed
Merge Refactored access control entry handling and improved identifier comparison by normalizing case (pr-3414)
cc03c72 - fix(core/acl): refactored access control entry handling and improved identifier comparison by normalizing case
2 parents 1da1551 + cc03c72 commit ae8fb34

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

code/client/citicore/se/Security.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ void Context::AddAccessControlEntry(const Principal& principal, const Object& ob
130130

131131
void Context::RemoveAccessControlEntry(const Principal& principal, const Object& object, AccessType type)
132132
{
133-
for (auto it = m_impl->m_aces.begin(); it != m_impl->m_aces.end(); )
133+
auto range = m_impl->m_aces.equal_range(object);
134+
for (auto it = range.first; it != range.second; )
134135
{
135-
if (it->first == object && it->second.principal == principal && it->second.type == type)
136+
if (it->second.principal == principal && it->second.type == type)
136137
{
137138
it = m_impl->m_aces.erase(it);
138139
}

code/client/citicore/se/Security.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Principal
88
inline explicit Principal(const std::string& principal)
99
{
1010
m_identifier = principal;
11+
std::transform(m_identifier.begin(), m_identifier.end(), m_identifier.begin(), ::tolower);
1112
}
1213

1314
inline const std::string& GetIdentifier() const
@@ -17,12 +18,12 @@ class Principal
1718

1819
inline bool operator<(const Principal& right) const
1920
{
20-
return _stricmp(m_identifier.c_str(), right.m_identifier.c_str()) < 0;
21+
return m_identifier < right.m_identifier;
2122
}
2223

2324
inline bool operator==(const Principal& right) const
2425
{
25-
return _stricmp(m_identifier.c_str(), right.m_identifier.c_str()) == 0;
26+
return m_identifier == right.m_identifier;
2627
}
2728

2829
private:
@@ -35,6 +36,7 @@ class Object
3536
inline explicit Object(const std::string& identifier)
3637
{
3738
m_identifier = identifier;
39+
std::transform(m_identifier.begin(), m_identifier.end(), m_identifier.begin(), ::tolower);
3840
}
3941

4042
inline const std::string& GetIdentifier() const
@@ -44,12 +46,12 @@ class Object
4446

4547
inline bool operator<(const Object& right) const
4648
{
47-
return _stricmp(m_identifier.c_str(), right.m_identifier.c_str()) < 0;
49+
return m_identifier < right.m_identifier;
4850
}
4951

5052
inline bool operator==(const Object& right) const
5153
{
52-
return _stricmp(m_identifier.c_str(), right.m_identifier.c_str()) == 0;
54+
return m_identifier == right.m_identifier;
5355
}
5456

5557
private:

0 commit comments

Comments
 (0)