Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / PICurrent / ServerInterceptor.cpp
blob0c2241c53129ee28319001f6360865d424137e3b
1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "ace/OS_NS_string.h"
4 #include <iostream>
6 const IOP::ServiceId service_id = 0xdeed;
7 const unsigned int num_allowed_users = 4;
8 static const char* allowed_users[num_allowed_users+1] =
9 {"Ron Klein", "Scott Case", "Mark Hodge", "Greg Black", 0};
10 const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"};
12 ServerInterceptor::ServerInterceptor (void)
13 : myname_ ("Server_Authentication_Interceptor")
15 std::cout << "Calling ServerInterceptor constructor." << std::endl;
18 ServerInterceptor::~ServerInterceptor ()
22 char *
23 ServerInterceptor::name ()
25 std::cout << "Calling ServerInterceptor name() method" << std::endl;
26 return CORBA::string_dup (this->myname_);
29 void
30 ServerInterceptor::destroy ()
32 std::cout << "Calling destroy()." << std::endl;
35 void
36 ServerInterceptor::receive_request_service_contexts (
37 PortableInterceptor::ServerRequestInfo_ptr ri)
39 ACE_UNUSED_ARG(ri);
40 std::cout << "Calling receive_request_service_contexts()." << std::endl;
43 void
44 ServerInterceptor::receive_request (
45 PortableInterceptor::ServerRequestInfo_ptr ri)
47 bool permission_granted = false;
48 std::cout << "Calling receive_request()." << std::endl;
50 if (ri->target_is_a(restricted_interfaces[0])){
51 IOP::ServiceId id = service_id;
52 // Check that the request service context can be retrieved.
53 IOP::ServiceContext_var sc =
54 ri->get_request_service_context (id);
56 CORBA::OctetSeq ocSeq = sc->context_data;
58 const char * buf =
59 reinterpret_cast<const char *> (ocSeq.get_buffer ());
61 for (unsigned int i=0; i<num_allowed_users; ++i) {
62 if (ACE_OS::strcmp (buf, allowed_users[i]) == 0)
64 permission_granted = true;
69 if (permission_granted == true) {
70 std::cout << "Permission Granted " << std::endl;
72 else {
73 std::cout << "Permission Denied " << std::endl;;
77 void
78 ServerInterceptor::send_reply (
79 PortableInterceptor::ServerRequestInfo_ptr ri)
81 ACE_UNUSED_ARG(ri);
82 std::cout << "Calling send_reply()." << std::endl;
85 void
86 ServerInterceptor::send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
88 ACE_UNUSED_ARG(ri);
89 std::cout << "Calling send_exception()." << std::endl;
92 void
93 ServerInterceptor::send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
95 ACE_UNUSED_ARG(ri);
96 std::cout << "Calling send_other()." << std::endl;