Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / DevGuideExamples / PortableInterceptors / Auth / ServerInterceptor.cpp
blob2a0088f5f8f034a0127f9aae30dac0773f4664e1
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)
5 #include <iostream>
6 #else
7 #include <iostream.h>
8 #endif
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 ()
26 char *
27 ServerInterceptor::name ()
29 std::cout << "Calling ServerInterceptor name() method" << std::endl;
30 return CORBA::string_dup (this->myname_);
33 void
34 ServerInterceptor::destroy ()
36 std::cout << "Calling destroy()." << std::endl;
39 void
40 ServerInterceptor::receive_request_service_contexts (
41 PortableInterceptor::ServerRequestInfo_ptr ri)
43 ACE_UNUSED_ARG(ri);
44 std::cout << "Calling receive_request_service_contexts()." << std::endl;
47 void
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;
62 const char * buf =
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;
76 else {
77 std::cout << "Permission Denied " << std::endl;
78 throw CORBA::NO_PERMISSION();
82 void
83 ServerInterceptor::send_reply (
84 PortableInterceptor::ServerRequestInfo_ptr ri)
86 ACE_UNUSED_ARG(ri);
87 std::cout << "Calling send_reply()." << std::endl;
90 void
91 ServerInterceptor::send_exception (
92 PortableInterceptor::ServerRequestInfo_ptr ri)
94 ACE_UNUSED_ARG(ri);
95 std::cout << "Calling send_exception()." << std::endl;
98 void
99 ServerInterceptor::send_other (
100 PortableInterceptor::ServerRequestInfo_ptr ri)
102 ACE_UNUSED_ARG(ri);
103 std::cout << "Calling send_other()." << std::endl;