Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Null_Cipher / client.cpp
blob2f05d6995ebf91e1a8b96abd9e1374a8b00a61a4
1 // -*- C++ -*-
3 #include "ace/Get_Opt.h"
5 #include "FooC.h"
6 #include "ace/SString.h"
7 #include "orbsvcs/SecurityC.h"
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 const char *cert_file = "cacert.pem";
12 void
13 null_cipher_test (CORBA::ORB_ptr orb,
14 CORBA::Object_ptr obj)
16 Security::QOP qop = Security::SecQOPIntegrity;
17 // Security::EstablishTrust establish_trust = {0,1};
19 CORBA::Any protection;
20 //CORBA::Any trust;
22 protection <<= qop;
23 //trust <<= establish_trust;
25 CORBA::PolicyList policy_list (2);
26 policy_list.length (1);
27 policy_list[0] =
28 orb->create_policy (Security::SecQOPPolicy, protection);
29 // policy_list[1] =
30 // orb->create_policy (Security::SecEstablishTrustPolicy, trust);
32 // Create an object reference that uses plain IIOP (i.e. no
33 // protection).
34 CORBA::Object_var object =
35 obj->_set_policy_overrides (policy_list,
36 CORBA::SET_OVERRIDE);
38 Foo_var server =
39 Foo::_narrow (object.in ());
41 if (CORBA::is_nil (server.in ()))
43 ACE_ERROR ((LM_ERROR,
44 "(%P|%t) ERROR: Object reference <%s> is "
45 "nil.\n",
46 ior));
48 throw CORBA::INTERNAL ();
51 try
53 // This invocation should result in a CORBA::NO_PERMISSION
54 // exception.
55 server->shutdown ();
57 catch (const CORBA::NO_PERMISSION&)
59 ACE_DEBUG ((LM_INFO,
60 "(%P|%t) Received CORBA::NO_PERMISSION from "
61 "server\n"));
67 int
68 parse_args (int argc, ACE_TCHAR *argv[])
70 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
71 int c;
73 while ((c = get_opts ()) != -1)
74 switch (c)
76 case 'k':
77 ior = get_opts.opt_arg ();
78 break;
79 case '?':
80 default:
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "Usage: %s "
83 "-k <ior> "
84 "\n",
85 argv [0]),
86 -1);
88 // Indicates successful parsing of the command line
89 return 0;
92 int
93 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
95 try
97 CORBA::ORB_var orb =
98 CORBA::ORB_init (argc, argv);
100 if (parse_args (argc, argv) != 0)
101 return 1;
103 CORBA::Object_var object =
104 orb->string_to_object (ior);
106 null_cipher_test (orb.in (), object.in ());
108 orb->destroy ();
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception ("Caught exception:");
113 return 1;
116 ACE_DEBUG ((LM_DEBUG,
117 "\n"
118 "Secure_Invocation test passed.\n"));
120 return 0;