1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "ace/OS_NS_string.h"
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 ()
13 : myname_ ("Server_Authentication_Interceptor")
15 std::cout
<< "Calling ServerInterceptor constructor." << std::endl
;
18 ServerInterceptor::~ServerInterceptor ()
23 ServerInterceptor::name ()
25 std::cout
<< "Calling ServerInterceptor name() method" << std::endl
;
26 return CORBA::string_dup (this->myname_
);
30 ServerInterceptor::destroy ()
32 std::cout
<< "Calling destroy()." << std::endl
;
36 ServerInterceptor::receive_request_service_contexts (
37 PortableInterceptor::ServerRequestInfo_ptr ri
)
40 std::cout
<< "Calling receive_request_service_contexts()." << std::endl
;
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
;
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
;
73 std::cout
<< "Permission Denied " << std::endl
;
78 ServerInterceptor::send_reply (
79 PortableInterceptor::ServerRequestInfo_ptr ri
)
82 std::cout
<< "Calling send_reply()." << std::endl
;
86 ServerInterceptor::send_exception (PortableInterceptor::ServerRequestInfo_ptr ri
)
89 std::cout
<< "Calling send_exception()." << std::endl
;
93 ServerInterceptor::send_other (PortableInterceptor::ServerRequestInfo_ptr ri
)
96 std::cout
<< "Calling send_other()." << std::endl
;