1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************
#include <Glacier2/PermissionsVerifier.h>
#include <Glacier2/NullPermissionsVerifier.h>
#include <Ice/Ice.h>
using namespace Ice;
using namespace std;
namespace
{
class NullPermissionsVerifier : public Glacier2::PermissionsVerifier
{
public:
#ifdef ICE_CPP11_MAPPING
bool checkPermissions(string, string, string&, const Current&) const
#else
bool checkPermissions(const string&, const string&, string&, const Current&) const
#endif
{
return true;
}
};
class NullSSLPermissionsVerifier : public Glacier2::SSLPermissionsVerifier
{
public:
#ifdef ICE_CPP11_MAPPING
virtual bool
authorize(Glacier2::SSLInfo, string&, const Ice::Current&) const
#else
virtual bool
authorize(const Glacier2::SSLInfo&, string&, const Ice::Current&) const
#endif
{
return true;
}
};
class Init
{
public:
Init(const CommunicatorPtr&, const string&, const vector<string>&);
private:
string checkPermissionVerifier(const string&);
void createObjects();
const CommunicatorPtr _communicator;
ObjectAdapterPtr _adapter;
Identity _nullPVId;
Identity _nullSSLPVId;
};
Init::Init(const CommunicatorPtr& communicator, const string& category, const vector<string>& props) :
_communicator(communicator)
{
_nullPVId.name = "NullPermissionsVerifier";
_nullPVId.category = category;
_nullSSLPVId.name = "NullSSLPermissionsVerifier";
_nullSSLPVId.category = category;
Ice::PropertiesPtr properties = _communicator->getProperties();
for(vector<string>::const_iterator p = props.begin(); p != props.end(); ++p)
{
string val = properties->getProperty(*p);
if(!val.empty())
{
//
// Check permission verifier proxy. It returns a non-empty
// value with the new stringified proxy if the property
// needs to be rewritten.
//
val = checkPermissionVerifier(val);
if(!val.empty())
{
properties->setProperty(*p, val);
}
}
}
}
string
Init::checkPermissionVerifier(const string& val)
{
// Check if it's in proxy format
try
{
ObjectPrxPtr prx = _communicator->stringToProxy(val);
if(prx->ice_getIdentity() == _nullPVId || prx->ice_getIdentity() == _nullSSLPVId)
{
createObjects();
}
}
catch(const ProxyParseException&)
{
// check if it's actually a stringified identity
// (with typically missing " " because the category contains a space)
if(val == _communicator->identityToString(_nullPVId))
{
createObjects();
return _adapter->createProxy(_nullPVId)->ice_toString(); // Return valid proxy to rewrite the property
}
else if(val == _communicator->identityToString(_nullSSLPVId))
{
createObjects();
return _adapter->createProxy(_nullSSLPVId)->ice_toString(); // Return valid proxy to rewrite the property
}
// Otherwise let the service report this incorrectly formatted proxy
}
return string();
}
void
Init::createObjects()
{
if(!_adapter)
{
_adapter = _communicator->createObjectAdapter(""); // colloc-only adapter
_adapter->add(ICE_MAKE_SHARED(NullPermissionsVerifier), _nullPVId);
_adapter->add(ICE_MAKE_SHARED(NullSSLPermissionsVerifier), _nullSSLPVId);
_adapter->activate();
}
}
}
namespace Glacier2Internal
{
void
setupNullPermissionsVerifier(const CommunicatorPtr& communicator, const string& category, const vector<string>& props)
{
Init init(communicator, category, props);
}
}
|