Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / DevGuideExamples / Security / ParticipatingApp / MessengerClient.cpp
bloba7e2813c2d2dd20bcfedb03f94aa8c35e67541ac
1 /* -*- C++ -*- */
3 #include "orbsvcs/SecurityC.h"
4 #include "MessengerC.h"
5 #include "ace/Get_Opt.h"
7 #if 0
8 The servers service configuration file
9 for this example is:
10 ---------------------------------------
11 # server.conf
12 dynamic SSLIOP_Factory Service_Object *
13 TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
14 "-SSLNoProtection \
15 -SSLAuthenticate SERVER_AND_CLIENT \
16 -SSLPrivateKey PEM:server_key.pem \
17 -SSLCertificate PEM:server_cert.pem"
19 static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
20 ---------------------------------------
22 The clients service configuration file
23 for this example is:
24 ---------------------------------------
25 # client.conf
26 dynamic SSLIOP_Factory Service_Object *
27 TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory()
28 "-SSLNoProtection \
29 -SSLAuthenticate SERVER \
30 -SSLPrivateKey PEM:client_key.pem \
31 -SSLCertificate PEM:client_cert.pem"
33 static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory"
34 ---------------------------------------
35 #endif
37 const ACE_TCHAR *ior = ACE_TEXT ("file://Messenger.ior");
39 int
40 parse_args (int argc, ACE_TCHAR *argv[])
42 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
43 int c;
45 while ((c = get_opts ()) != -1)
46 switch (c)
48 case 'k':
49 ior = get_opts.opt_arg ();
50 break;
52 case '?':
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-k <ior> "
57 "\n",
58 argv [0]),
59 -1);
61 // Indicates successful parsing of the command line
62 return 0;
65 int
66 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
68 try {
70 CORBA::ORB_var orb =
71 CORBA::ORB_init( argc, argv );
73 if (parse_args (argc, argv) != 0)
74 return 1;
76 CORBA::Object_var obj =
77 orb->string_to_object( ior );
79 Messenger_var messenger =
80 Messenger::_narrow( obj.in() );
82 CORBA::String_var message =
83 CORBA::string_dup( "Terminating messenger service!" );
85 messenger->send_message( "Chief of Security",
86 "New Directive",
87 message.inout() );
89 messenger->shutdown("Chief of Security");
91 Security::QOP qop =
92 Security::SecQOPIntegrityAndConfidentiality;
94 CORBA::Any want_protection;
95 want_protection <<= qop;
97 CORBA::Policy_var policy =
98 orb->create_policy (Security::SecQOPPolicy,
99 want_protection);
101 Security::EstablishTrust establish_trust;
102 establish_trust.trust_in_client = 0;
103 establish_trust.trust_in_target = 1;
105 CORBA::Any want_trust;
106 want_trust <<= establish_trust;
108 CORBA::Policy_var policy2 =
109 orb->create_policy (Security::SecEstablishTrustPolicy,
110 want_trust);
113 CORBA::PolicyList policy_list (2);
114 policy_list.length (1);
115 policy_list[0] =
116 CORBA::Policy::_duplicate (policy.in ());
117 policy_list.length (2);
118 policy_list[1] =
119 CORBA::Policy::_duplicate (policy2.in ());
122 CORBA::Object_var object =
123 obj->_set_policy_overrides (policy_list,
124 CORBA::SET_OVERRIDE);
126 Messenger_var messenger2 =
127 Messenger::_narrow( object.in() );
129 message =
130 CORBA::string_dup( "Terminating messenger service!" );
132 messenger2->send_message( "Chief of Security",
133 "New Directive",
134 message.inout() );
136 messenger2->shutdown("Chief of Security");
138 orb->destroy();
140 catch(const CORBA::Exception& ex)
142 ex._tao_print_exception("Client: main block");
143 return 1;
146 return 0;