1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "tao/OctetSeqC.h"
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 ()
31 ServerInterceptor::name ()
33 std::cout
<< "Calling ServerInterceptor name() method" << std::endl
;
34 return CORBA::string_dup (this->myname_
);
38 ServerInterceptor::destroy ()
40 std::cout
<< "Calling destroy()." << std::endl
;
44 ServerInterceptor::receive_request_service_contexts (
45 PortableInterceptor::ServerRequestInfo_ptr
)
47 std::cout
<< "Calling receive_request_service_contexts()." << std::endl
;
51 ServerInterceptor::receive_request (
52 PortableInterceptor::ServerRequestInfo_ptr ri
)
54 bool permission_granted
= false;
55 std::cout
<< "Calling receive_request()." << std::endl
;
57 if (ri
->target_is_a(restricted_interfaces
[0])){
58 IOP::ServiceId id
= service_id
;
59 // Check that the request service context can be retrieved.
60 IOP::ServiceContext_var sc
=
61 ri
->get_request_service_context (id
);
62 // need to construct an octet seq for decoding
63 CORBA::OctetSeq ocSeq
= CORBA::OctetSeq(
64 sc
->context_data
.length(),
65 sc
->context_data
.length(),
66 sc
->context_data
.get_buffer(),
69 CORBA::Any gid_as_any
;
70 gid_as_any
= *codec
->decode(ocSeq
);
73 if (gid_as_any
>>= gid
) {
74 for (int i
=0; i
<3; ++i
) {
75 if ( gid
== allowed_gid
[i
] )
77 permission_granted
= true;
81 permission_granted
= false;
82 std::cerr
<< "Could not extract GID from any." << std::endl
;
86 if (permission_granted
== true) {
87 std::cout
<< "Permission Granted " << std::endl
;
90 std::cout
<< "Permission Denied " << std::endl
;
95 ServerInterceptor::send_reply (
96 PortableInterceptor::ServerRequestInfo_ptr ri
)
99 std::cout
<< "Calling send_reply()." << std::endl
;
103 ServerInterceptor::send_exception (
104 PortableInterceptor::ServerRequestInfo_ptr ri
)
107 std::cout
<< "Calling send_exception()." << std::endl
;
111 ServerInterceptor::send_other (
112 PortableInterceptor::ServerRequestInfo_ptr ri
)
115 std::cout
<< "Calling send_other()." << std::endl
;