SL3_CredentialsCurator.cpp

Go to the documentation of this file.
00001 // $Id: SL3_CredentialsCurator.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Security/SL3_CredentialsCurator.h"
00004 #include "orbsvcs/Security/SL3_CredentialsAcquirerFactory.h"
00005 
00006 
00007 ACE_RCSID (Security,
00008            SL3_CredentialsCurator,
00009            "$Id: SL3_CredentialsCurator.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 namespace TAO
00014 {
00015   namespace SL3
00016   {
00017     static const size_t CREDENTIALS_TABLE_SIZE = 128;
00018   }
00019 }
00020 
00021 TAO::SL3::CredentialsCurator::CredentialsCurator (void)
00022   : lock_ (),
00023     acquirer_factories_ (),
00024     credentials_table_ (TAO::SL3::CREDENTIALS_TABLE_SIZE)
00025 {
00026 }
00027 
00028 TAO::SL3::CredentialsCurator::~CredentialsCurator (void)
00029 {
00030   const Factory_Iterator fend = this->acquirer_factories_.end ();
00031   for (Factory_Iterator i = this->acquirer_factories_.begin ();
00032        i != fend;
00033        ++i)
00034     {
00035       // Deallocate the Acquistion Method.
00036       CORBA::string_free (const_cast<char *> ((*i).ext_id_));
00037 
00038       delete (*i).int_id_;
00039     }
00040 
00041   this->acquirer_factories_.close ();
00042 
00043   const Credentials_Iterator end = this->credentials_table_.end ();
00044   for (Credentials_Iterator j = this->credentials_table_.begin ();
00045        j != end;
00046        ++j)
00047     {
00048       // Deallocate the CredentialsId.
00049       CORBA::string_free (const_cast<char *> ((*j).ext_id_));
00050     }
00051 
00052   this->credentials_table_.close ();
00053 }
00054 
00055 TAO::SL3::CredentialsCurator_ptr
00056 TAO::SL3::CredentialsCurator::_duplicate (TAO::SL3::CredentialsCurator_ptr obj)
00057 {
00058   if (!CORBA::is_nil (obj))
00059     obj->_add_ref ();
00060 
00061   return obj;
00062 }
00063 
00064 TAO::SL3::CredentialsCurator_ptr
00065 TAO::SL3::CredentialsCurator::_narrow (CORBA::Object_ptr obj)
00066 {
00067   return TAO::SL3::CredentialsCurator::_duplicate (
00068              dynamic_cast<TAO::SL3::CredentialsCurator *> (obj));
00069 }
00070 
00071 TAO::SL3::CredentialsCurator_ptr
00072 TAO::SL3::CredentialsCurator::_nil (void)
00073 {
00074   return (CredentialsCurator *) 0;
00075 }
00076 
00077 SecurityLevel3::AcquisitionMethodList *
00078 TAO::SL3::CredentialsCurator::supported_methods (void)
00079 {
00080   SecurityLevel3::AcquisitionMethodList * list;
00081   ACE_NEW_THROW_EX (list,
00082                     SecurityLevel3::AcquisitionMethodList,
00083                     CORBA::NO_MEMORY ());
00084   SecurityLevel3::AcquisitionMethodList_var methods = list;
00085 
00086   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00087                     guard,
00088                     this->lock_,
00089                     0);
00090 
00091   methods->length (this->acquirer_factories_.current_size ());
00092 
00093   CORBA::ULong n = 0;
00094 
00095   const Factory_Iterator end = this->acquirer_factories_.end ();
00096   for (Factory_Iterator i = this->acquirer_factories_.begin ();
00097        i != end;
00098        ++i)
00099     {
00100       methods[n++] = CORBA::string_dup ((*i).ext_id_);
00101     }
00102 
00103   return methods._retn ();
00104 }
00105 
00106 SecurityLevel3::CredentialsAcquirer_ptr
00107 TAO::SL3::CredentialsCurator::acquire_credentials (
00108     const char * acquisition_method,
00109     const CORBA::Any & acquisition_arguments)
00110 {
00111   TAO::SL3::CredentialsAcquirerFactory * factory;
00112 
00113   if (this->acquirer_factories_.find (acquisition_method,
00114                                       factory) == 0)
00115     {
00116       return factory->make (this,
00117                             acquisition_arguments);
00118     }
00119 
00120   throw CORBA::BAD_PARAM ();
00121 
00122 }
00123 
00124 SecurityLevel3::OwnCredentialsList *
00125 TAO::SL3::CredentialsCurator::default_creds_list (void)
00126 {
00127   SecurityLevel3::OwnCredentialsList * list;
00128   ACE_NEW_THROW_EX (list,
00129                     SecurityLevel3::OwnCredentialsList,
00130                     CORBA::NO_MEMORY ());
00131 
00132   SecurityLevel3::OwnCredentialsList_var creds_list = list;
00133 
00134   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00135                     guard,
00136                     this->lock_,
00137                     0);
00138 
00139   creds_list->length (this->credentials_table_.current_size ());
00140 
00141   CORBA::ULong n = 0;
00142 
00143   const Credentials_Iterator end = this->credentials_table_.end ();
00144   for (Credentials_Iterator i = this->credentials_table_.begin ();
00145        i != end;
00146        ++i)
00147     {
00148       creds_list[n++] =
00149         SecurityLevel3::OwnCredentials::_duplicate ((*i).int_id_.in());
00150     }
00151 
00152   return creds_list._retn ();
00153 }
00154 
00155 SecurityLevel3::CredentialsIdList *
00156 TAO::SL3::CredentialsCurator::default_creds_ids (void)
00157 {
00158   SecurityLevel3::CredentialsIdList * list;
00159   ACE_NEW_THROW_EX (list,
00160                     SecurityLevel3::CredentialsIdList,
00161                     CORBA::NO_MEMORY ());
00162   SecurityLevel3::CredentialsIdList_var creds_ids = list;
00163 
00164   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00165                     guard,
00166                     this->lock_,
00167                     0);
00168 
00169   creds_ids->length (this->credentials_table_.current_size ());
00170 
00171   CORBA::ULong n = 0;
00172 
00173   const Credentials_Iterator end = this->credentials_table_.end ();
00174   for (Credentials_Iterator i = this->credentials_table_.begin ();
00175        i != end;
00176        ++i)
00177     {
00178       creds_ids[n++] = CORBA::string_dup ((*i).ext_id_);
00179     }
00180 
00181   return creds_ids._retn ();
00182 }
00183 
00184 SecurityLevel3::OwnCredentials_ptr
00185 TAO::SL3::CredentialsCurator::get_own_credentials (
00186     const char * credentials_id)
00187 {
00188   Credentials_Table::ENTRY * entry;
00189 
00190   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00191                     guard,
00192                     this->lock_,
00193                     SecurityLevel3::OwnCredentials::_nil ());
00194 
00195   if (this->credentials_table_.find (credentials_id, entry) != 0)
00196     {
00197       return SecurityLevel3::OwnCredentials::_nil ();
00198     }
00199 
00200   return
00201     SecurityLevel3::OwnCredentials::_duplicate (entry->int_id_.in ());
00202 }
00203 
00204 void
00205 TAO::SL3::CredentialsCurator::release_own_credentials (
00206     const char * credentials_id)
00207 {
00208   Credentials_Table::ENTRY * entry;
00209 
00210   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00211 
00212   if (this->credentials_table_.find (credentials_id, entry) == 0)
00213     {
00214       // Deallocate the external ID (a const char *) before unbinding.
00215       CORBA::string_free (const_cast<char *> (entry->ext_id_));
00216 
00217       (void) this->credentials_table_.unbind (entry);
00218     }
00219 }
00220 
00221 void
00222 TAO::SL3::CredentialsCurator:: register_acquirer_factory (
00223   const char * acquisition_method,
00224   TAO::SL3::CredentialsAcquirerFactory * factory)
00225 {
00226   if (acquisition_method == 0 || factory == 0)
00227     throw CORBA::BAD_PARAM ();
00228 
00229   CORBA::String_var method = CORBA::string_dup (acquisition_method);
00230 
00231   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00232 
00233   const int result =
00234     this->acquirer_factories_.bind (method.in (), factory);
00235 
00236   if (result == 1)  // Entry already exists in table.
00237     throw CORBA::BAD_INV_ORDER ();
00238   else if (result == -1)  // Failure.
00239     throw CORBA::INTERNAL ();
00240 
00241 
00242   // CredentialsCurator now owns the acquisition method id.
00243   (void) method._retn ();
00244 
00245   // Otherwise success!
00246 }
00247 
00248 void
00249 TAO::SL3::CredentialsCurator::_tao_add_own_credentials (
00250   SecurityLevel3::OwnCredentials_ptr credentials)
00251 {
00252   CORBA::String_var credentials_id =
00253     credentials->creds_id ();
00254 
00255   SecurityLevel3::OwnCredentials_var creds =
00256     SecurityLevel3::OwnCredentials::_duplicate (credentials);
00257 
00258   if (this->credentials_table_.bind (credentials_id.in (),
00259                                      creds) != 0)
00260     {
00261       throw CORBA::NO_RESOURCES ();
00262     }
00263 
00264  // CredentialsCurator nows owns the id.
00265   (void) credentials_id._retn ();
00266 }
00267 
00268 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 16:09:36 2008 for TAO_Security by doxygen 1.3.6