Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / SimpleCodec / ServerInterceptor.cpp
blobc7485411606ec26d3bd900137dbff1770751244a
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);
27 ServerInterceptor::~ServerInterceptor ()
31 char *
32 ServerInterceptor::name ()
34 std::cout << "Calling ServerInterceptor name() method" << std::endl;
35 return CORBA::string_dup (this->myname_);
38 void
39 ServerInterceptor::destroy ()
41 std::cout << "Calling destroy()." << std::endl;
44 void
45 ServerInterceptor::receive_request_service_contexts (
46 PortableInterceptor::ServerRequestInfo_ptr)
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) {
75 for (int i=0; i<3; ++i) {
76 if ( gid == allowed_gid[i] )
78 permission_granted = true;
81 } else {
82 permission_granted = false;
83 std::cerr << "Could not extract GID from any." << std::endl;
87 if (permission_granted == true) {
88 std::cout << "Permission Granted " << std::endl;
90 else {
91 std::cout << "Permission Denied " << std::endl;;
95 void
96 ServerInterceptor::send_reply (
97 PortableInterceptor::ServerRequestInfo_ptr ri)
99 ACE_UNUSED_ARG(ri);
100 std::cout << "Calling send_reply()." << std::endl;
103 void
104 ServerInterceptor::send_exception (
105 PortableInterceptor::ServerRequestInfo_ptr ri)
107 ACE_UNUSED_ARG(ri);
108 std::cout << "Calling send_exception()." << std::endl;
111 void
112 ServerInterceptor::send_other (
113 PortableInterceptor::ServerRequestInfo_ptr ri)
115 ACE_UNUSED_ARG(ri);
116 std::cout << "Calling send_other()." << std::endl;