00001
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 "SL3_CredentialsCurator.cpp,v 1.7 2006/03/14 06:14:35 jtc Exp")
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
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
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 ACE_ENV_ARG_DECL_NOT_USED)
00067 {
00068 return TAO::SL3::CredentialsCurator::_duplicate (
00069 dynamic_cast<TAO::SL3::CredentialsCurator *> (obj));
00070 }
00071
00072 TAO::SL3::CredentialsCurator_ptr
00073 TAO::SL3::CredentialsCurator::_nil (void)
00074 {
00075 return (CredentialsCurator *) 0;
00076 }
00077
00078 SecurityLevel3::AcquisitionMethodList *
00079 TAO::SL3::CredentialsCurator::supported_methods (ACE_ENV_SINGLE_ARG_DECL)
00080 ACE_THROW_SPEC ((CORBA::SystemException))
00081 {
00082 SecurityLevel3::AcquisitionMethodList * list;
00083 ACE_NEW_THROW_EX (list,
00084 SecurityLevel3::AcquisitionMethodList,
00085 CORBA::NO_MEMORY ());
00086 SecurityLevel3::AcquisitionMethodList_var methods = list;
00087
00088 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00089 guard,
00090 this->lock_,
00091 0);
00092
00093 methods->length (this->acquirer_factories_.current_size ());
00094
00095 CORBA::ULong n = 0;
00096
00097 const Factory_Iterator end = this->acquirer_factories_.end ();
00098 for (Factory_Iterator i = this->acquirer_factories_.begin ();
00099 i != end;
00100 ++i)
00101 {
00102 methods[n++] = CORBA::string_dup ((*i).ext_id_);
00103 }
00104
00105 return methods._retn ();
00106 }
00107
00108 SecurityLevel3::CredentialsAcquirer_ptr
00109 TAO::SL3::CredentialsCurator::acquire_credentials (
00110 const char * acquisition_method,
00111 const CORBA::Any & acquisition_arguments
00112 ACE_ENV_ARG_DECL)
00113 ACE_THROW_SPEC ((CORBA::SystemException))
00114 {
00115 TAO::SL3::CredentialsAcquirerFactory * factory;
00116
00117 if (this->acquirer_factories_.find (acquisition_method,
00118 factory) == 0)
00119 {
00120 return factory->make (this,
00121 acquisition_arguments
00122 ACE_ENV_ARG_PARAMETER);
00123 }
00124
00125 ACE_THROW_RETURN (CORBA::BAD_PARAM (),
00126 SecurityLevel3::CredentialsAcquirer::_nil ());
00127
00128 }
00129
00130 SecurityLevel3::OwnCredentialsList *
00131 TAO::SL3::CredentialsCurator::default_creds_list (ACE_ENV_SINGLE_ARG_DECL)
00132 ACE_THROW_SPEC ((CORBA::SystemException))
00133 {
00134 SecurityLevel3::OwnCredentialsList * list;
00135 ACE_NEW_THROW_EX (list,
00136 SecurityLevel3::OwnCredentialsList,
00137 CORBA::NO_MEMORY ());
00138 ACE_CHECK_RETURN (0);
00139
00140 SecurityLevel3::OwnCredentialsList_var creds_list = list;
00141
00142 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00143 guard,
00144 this->lock_,
00145 0);
00146
00147 creds_list->length (this->credentials_table_.current_size ());
00148
00149 CORBA::ULong n = 0;
00150
00151 const Credentials_Iterator end = this->credentials_table_.end ();
00152 for (Credentials_Iterator i = this->credentials_table_.begin ();
00153 i != end;
00154 ++i)
00155 {
00156 creds_list[n++] =
00157 SecurityLevel3::OwnCredentials::_duplicate ((*i).int_id_.in());
00158 }
00159
00160 return creds_list._retn ();
00161 }
00162
00163 SecurityLevel3::CredentialsIdList *
00164 TAO::SL3::CredentialsCurator::default_creds_ids (ACE_ENV_SINGLE_ARG_DECL)
00165 ACE_THROW_SPEC ((CORBA::SystemException))
00166 {
00167 SecurityLevel3::CredentialsIdList * list;
00168 ACE_NEW_THROW_EX (list,
00169 SecurityLevel3::CredentialsIdList,
00170 CORBA::NO_MEMORY ());
00171 SecurityLevel3::CredentialsIdList_var creds_ids = list;
00172
00173 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00174 guard,
00175 this->lock_,
00176 0);
00177
00178 creds_ids->length (this->credentials_table_.current_size ());
00179
00180 CORBA::ULong n = 0;
00181
00182 const Credentials_Iterator end = this->credentials_table_.end ();
00183 for (Credentials_Iterator i = this->credentials_table_.begin ();
00184 i != end;
00185 ++i)
00186 {
00187 creds_ids[n++] = CORBA::string_dup ((*i).ext_id_);
00188 }
00189
00190 return creds_ids._retn ();
00191 }
00192
00193 SecurityLevel3::OwnCredentials_ptr
00194 TAO::SL3::CredentialsCurator::get_own_credentials (
00195 const char * credentials_id
00196 ACE_ENV_ARG_DECL_NOT_USED)
00197 ACE_THROW_SPEC ((CORBA::SystemException))
00198 {
00199 Credentials_Table::ENTRY * entry;
00200
00201 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00202 guard,
00203 this->lock_,
00204 SecurityLevel3::OwnCredentials::_nil ());
00205
00206 if (this->credentials_table_.find (credentials_id, entry) != 0)
00207 {
00208 return SecurityLevel3::OwnCredentials::_nil ();
00209 }
00210
00211 return
00212 SecurityLevel3::OwnCredentials::_duplicate (entry->int_id_.in ());
00213 }
00214
00215 void
00216 TAO::SL3::CredentialsCurator::release_own_credentials (
00217 const char * credentials_id
00218 ACE_ENV_ARG_DECL_NOT_USED)
00219 ACE_THROW_SPEC ((CORBA::SystemException))
00220 {
00221 Credentials_Table::ENTRY * entry;
00222
00223 ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00224
00225 if (this->credentials_table_.find (credentials_id, entry) == 0)
00226 {
00227
00228 CORBA::string_free (const_cast<char *> (entry->ext_id_));
00229
00230 (void) this->credentials_table_.unbind (entry);
00231 }
00232 }
00233
00234 void
00235 TAO::SL3::CredentialsCurator:: register_acquirer_factory (
00236 const char * acquisition_method,
00237 TAO::SL3::CredentialsAcquirerFactory * factory
00238 ACE_ENV_ARG_DECL)
00239 {
00240 if (acquisition_method == 0 || factory == 0)
00241 ACE_THROW (CORBA::BAD_PARAM ());
00242
00243 CORBA::String_var method = CORBA::string_dup (acquisition_method);
00244
00245 ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
00246
00247 const int result =
00248 this->acquirer_factories_.bind (method.in (), factory);
00249
00250 if (result == 1)
00251 ACE_THROW (CORBA::BAD_INV_ORDER ());
00252 else if (result == -1)
00253 ACE_THROW (CORBA::INTERNAL ());
00254
00255
00256
00257 (void) method._retn ();
00258
00259
00260 }
00261
00262 void
00263 TAO::SL3::CredentialsCurator::_tao_add_own_credentials (
00264 SecurityLevel3::OwnCredentials_ptr credentials
00265 ACE_ENV_ARG_DECL)
00266 {
00267 CORBA::String_var credentials_id =
00268 credentials->creds_id (ACE_ENV_SINGLE_ARG_PARAMETER);
00269 ACE_CHECK;
00270
00271 SecurityLevel3::OwnCredentials_var creds =
00272 SecurityLevel3::OwnCredentials::_duplicate (credentials);
00273
00274 if (this->credentials_table_.bind (credentials_id.in (),
00275 creds) != 0)
00276 {
00277 ACE_THROW (CORBA::NO_RESOURCES ());
00278 }
00279
00280
00281 (void) credentials_id._retn ();
00282 }
00283
00284 TAO_END_VERSIONED_NAMESPACE_DECL