Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / IOR / ServerInterceptor.cpp
blob5dfa84b5172dc883b37933342a04b10ae0557883
1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "tao/OctetSeqC.h"
4 #include <iostream>
6 const IOP::ServiceId service_id = 0xdeed;
7 const CORBA::Long allowed_gid[4] = { 9006, 9007, 9008 };
8 const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"};
10 ServerInterceptor::ServerInterceptor (IOP::CodecFactory_var cf)
11 : myname_ ("Server_Authentication_Interceptor")
13 std::cout << "Calling ServerInterceptor constructor." << std::endl;
15 // Set up a structure that contains information necessary to
16 // create a GIOP 1.2 CDR encapsulation Codec.
17 IOP::Encoding encoding;
18 encoding.format = IOP::ENCODING_CDR_ENCAPS;
19 encoding.major_version = 1;
20 encoding.minor_version = 2;
22 // Obtain the CDR encapsulation Codec.
23 this->codec = cf->create_codec (encoding);
26 ServerInterceptor::~ServerInterceptor ()
30 char *
31 ServerInterceptor::name ()
33 std::cout << "Calling ServerInterceptor name() method" << std::endl;
34 return CORBA::string_dup (this->myname_);
37 void
38 ServerInterceptor::destroy ()
40 std::cout << "Calling destroy()." << std::endl;
43 void
44 ServerInterceptor::receive_request_service_contexts (
45 PortableInterceptor::ServerRequestInfo_ptr ri)
47 ACE_UNUSED_ARG(ri);
48 std::cout << "Calling receive_request_service_contexts()." << std::endl;
51 void
52 ServerInterceptor::receive_request (
53 PortableInterceptor::ServerRequestInfo_ptr ri)
55 bool permission_granted = false;
56 std::cout << "Calling receive_request()." << std::endl;
58 if (ri->target_is_a(restricted_interfaces[0])){
59 IOP::ServiceId id = service_id;
60 // Check that the request service context can be retrieved.
61 IOP::ServiceContext_var sc =
62 ri->get_request_service_context (id);
63 // need to construct an octet seq for decoding
64 CORBA::OctetSeq ocSeq = CORBA::OctetSeq(
65 sc->context_data.length(),
66 sc->context_data.length(),
67 sc->context_data.get_buffer(),
68 false);
70 CORBA::Any gid_as_any;
71 gid_as_any = *codec->decode(ocSeq);
73 CORBA::Long gid;
74 if (gid_as_any >>= gid)
76 for (int i=0; i<3; ++i) {
77 if ( gid == allowed_gid[i] )
79 permission_granted = true;
83 else
85 permission_granted = false;
86 std::cerr << "Could not extract GID from any." << std::endl;
90 if (permission_granted == true) {
91 std::cout << "Permission Granted " << std::endl;
93 else {
94 std::cout << "Permission Denied " << std::endl;;
98 void
99 ServerInterceptor::send_reply (
100 PortableInterceptor::ServerRequestInfo_ptr ri)
102 ACE_UNUSED_ARG(ri);
103 std::cout << "Calling send_reply()." << std::endl;
106 void
107 ServerInterceptor::send_exception (
108 PortableInterceptor::ServerRequestInfo_ptr ri)
110 ACE_UNUSED_ARG(ri);
111 std::cout << "Calling send_exception()." << std::endl;
114 void
115 ServerInterceptor::send_other (
116 PortableInterceptor::ServerRequestInfo_ptr ri)
118 ACE_UNUSED_ARG(ri);
119 std::cout << "Calling send_other()." << std::endl;