1
// **********************************************************************
3
// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5
// This copy of Ice is licensed to you under the terms described in the
6
// ICE_LICENSE file included in this distribution.
8
// **********************************************************************
10
#include <Ice/Application.h>
11
#include <Glacier2/PermissionsVerifier.h>
12
#include <Glacier2/Session.h>
13
#include <TestCommon.h>
14
#include <IceSSL/Plugin.h>
21
void testContext(bool ssl, const Ice::Context& context)
23
Ice::Context ctx = context;
26
test(ctx["_con.type"] == "tcp");
27
test(ctx["_con.localPort"] == "12347");
31
test(ctx["_con.type"] == "ssl");
32
test(ctx["_con.localPort"] == "12348");
34
test(ctx["_con.localAddress"] == "127.0.0.1");
35
test(ctx["_con.remotePort"] != "");
36
test(ctx["_con.remoteAddress"] == "127.0.0.1");
41
class PermissionsVerifierI : public Glacier2::PermissionsVerifier
46
checkPermissions(const string& userId, const string& password, string& reason, const Ice::Current& current) const
48
testContext(userId == "ssl", current.ctx);
53
class SSLPermissionsVerifierI : public Glacier2::SSLPermissionsVerifier
58
authorize(const Glacier2::SSLInfo& info, string&, const Ice::Current& current) const
60
testContext(true, current.ctx);
62
IceSSL::CertificatePtr cert = IceSSL::Certificate::decode(info.certs[0]);
63
test(cert->getIssuerDN() == IceSSL::DistinguishedName(
64
"emailAddress=info@zeroc.com,CN=ZeroC Test CA,OU=Ice,O=ZeroC\\, Inc.,"
65
"L=Palm Beach Gardens,ST=Florida,C=US"));
66
test(cert->getSubjectDN() == IceSSL::DistinguishedName(
67
"CN=Client,emailAddress=info@zeroc.com,OU=Ice,O=ZeroC\\, Inc.,ST=Florida,C=US"));
68
test(cert->checkValidity());
74
class SessionI : public Glacier2::Session
78
SessionI(bool shutdown, bool ssl) : _shutdown(shutdown), _ssl(ssl)
83
destroy(const Ice::Current& current)
85
testContext(_ssl, current.ctx);
90
Ice::Context::const_iterator p = current.ctx.find("SSL.Active");
91
assert(p != current.ctx.end() && p->second == "1");
94
current.adapter->remove(current.id);
97
current.adapter->getCommunicator()->shutdown();
102
ice_ping(const Ice::Current& current)
104
testContext(_ssl, current.ctx);
109
const bool _shutdown;
113
class SessionManagerI : public Glacier2::SessionManager
117
virtual Glacier2::SessionPrx
118
create(const string& userId, const Glacier2::SessionControlPrx&, const Ice::Current& current)
120
testContext(userId == "ssl", current.ctx);
122
Glacier2::SessionPtr session = new SessionI(false, userId == "ssl");
123
return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session));
127
class SSLSessionManagerI : public Glacier2::SSLSessionManager
131
virtual Glacier2::SessionPrx
132
create(const Glacier2::SSLInfo& info, const Glacier2::SessionControlPrx&, const Ice::Current& current)
134
testContext(true, current.ctx);
136
test(info.remoteHost == "127.0.0.1");
137
test(info.localHost == "127.0.0.1");
138
test(info.localPort == 12348);
142
IceSSL::CertificatePtr cert = IceSSL::Certificate::decode(info.certs[0]);
143
test(cert->getIssuerDN() == IceSSL::DistinguishedName(
144
"emailAddress=info@zeroc.com,CN=ZeroC Test CA,OU=Ice,O=ZeroC\\, Inc.,L=Palm Beach Gardens,"
146
test(cert->getSubjectDN() == IceSSL::DistinguishedName(
147
"CN=Client,emailAddress=info@zeroc.com,OU=Ice,O=ZeroC\\, Inc.,ST=Florida,C=US"));
148
test(cert->checkValidity());
150
catch(const IceSSL::CertificateReadException&)
155
Glacier2::SessionPtr session = new SessionI(true, true);
156
return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session));
160
class SessionServer : public Ice::Application
164
virtual int run(int, char*[]);
168
main(int argc, char* argv[])
171
return app.main(argc, argv);
175
SessionServer::run(int argc, char* argv[])
177
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints(
178
"SessionServer", "tcp -h 127.0.0.1 -p 12350");
179
adapter->add(new PermissionsVerifierI, communicator()->stringToIdentity("verifier"));
180
adapter->add(new SSLPermissionsVerifierI, communicator()->stringToIdentity("sslverifier"));
181
adapter->add(new SessionManagerI, communicator()->stringToIdentity("sessionmanager"));
182
adapter->add(new SSLSessionManagerI, communicator()->stringToIdentity("sslsessionmanager"));
184
communicator()->waitForShutdown();