1 #include "ServerInterceptor.h"
2 #include "tao/PI_Server/ServerRequestInfoA.h"
3 #include "ace/OS_NS_string.h"
4 #if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY == 1)
10 const IOP::ServiceId service_id
= 0xdeed;
11 const unsigned int num_allowed_users
= 4;
12 static const char* allowed_users
[num_allowed_users
+1] =
13 {"Ron Klein", "Scott Case", "Mark Hodge", "Greg Black", 0};
14 const char* restricted_interfaces
[1] = {"IDL:Messenger:1.0"};
16 ServerInterceptor::ServerInterceptor (void)
17 : myname_ ("Server_Authentication_Interceptor")
19 std::cout
<< "Calling ServerInterceptor constructor." << std::endl
;
22 ServerInterceptor::~ServerInterceptor ()
27 ServerInterceptor::name ()
29 std::cout
<< "Calling ServerInterceptor name() method" << std::endl
;
30 return CORBA::string_dup (this->myname_
);
34 ServerInterceptor::destroy ()
36 std::cout
<< "Calling destroy()." << std::endl
;
40 ServerInterceptor::receive_request_service_contexts (
41 PortableInterceptor::ServerRequestInfo_ptr ri
)
44 std::cout
<< "Calling receive_request_service_contexts()." << std::endl
;
48 ServerInterceptor::receive_request (
49 PortableInterceptor::ServerRequestInfo_ptr ri
)
51 bool permission_granted
= false;
52 std::cout
<< "Calling receive_request()." << std::endl
;
54 if (ri
->target_is_a(restricted_interfaces
[0])){
55 IOP::ServiceId id
= service_id
;
56 // Check that the request service context can be retrieved.
57 IOP::ServiceContext_var sc
=
58 ri
->get_request_service_context (id
);
60 CORBA::OctetSeq ocSeq
= sc
->context_data
;
63 reinterpret_cast<const char *> (ocSeq
.get_buffer ());
65 for (unsigned int i
=0; i
<num_allowed_users
; ++i
) {
66 if (ACE_OS::strcmp (buf
, allowed_users
[i
]) == 0)
68 permission_granted
= true;
73 if (permission_granted
== true) {
74 std::cout
<< "Permission Granted " << std::endl
;
77 std::cout
<< "Permission Denied " << std::endl
;
78 throw CORBA::NO_PERMISSION();
83 ServerInterceptor::send_reply (
84 PortableInterceptor::ServerRequestInfo_ptr ri
)
87 std::cout
<< "Calling send_reply()." << std::endl
;
91 ServerInterceptor::send_exception (
92 PortableInterceptor::ServerRequestInfo_ptr ri
)
95 std::cout
<< "Calling send_exception()." << std::endl
;
99 ServerInterceptor::send_other (
100 PortableInterceptor::ServerRequestInfo_ptr ri
)
103 std::cout
<< "Calling send_other()." << std::endl
;