00001
00002
00003 #include "orbsvcs/Security/Security_PolicyFactory.h"
00004
00005 ACE_RCSID (Security,
00006 Security_PolicyFactory,
00007 "Security_PolicyFactory.cpp,v 1.13 2006/03/14 06:14:35 jtc Exp")
00008
00009 #include "orbsvcs/Security/SL2_QOPPolicy.h"
00010 #include "orbsvcs/Security/SL2_EstablishTrustPolicy.h"
00011
00012 #include "orbsvcs/Security/SL3_ContextEstablishmentPolicy.h"
00013 #include "orbsvcs/Security/SL3_ObjectCredentialsPolicy.h"
00014
00015 #include "orbsvcs/SecurityLevel2C.h"
00016 #include "orbsvcs/SecurityLevel3C.h"
00017
00018 #include "tao/ORB_Constants.h"
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 CORBA::Policy_ptr
00023 TAO::Security::PolicyFactory::create_policy (
00024 CORBA::PolicyType type,
00025 const CORBA::Any &value
00026 ACE_ENV_ARG_DECL)
00027 ACE_THROW_SPEC ((CORBA::SystemException,
00028 CORBA::PolicyError))
00029 {
00030
00031
00032
00033
00034 if (type == ::Security::SecQOPPolicy)
00035 {
00036 ::Security::QOP qop;
00037
00038
00039
00040 if (!(value >>= qop))
00041 ACE_THROW_RETURN (CORBA::BAD_PARAM (
00042 CORBA::SystemException::_tao_minor_code (
00043 TAO::VMCID,
00044 EINVAL),
00045 CORBA::COMPLETED_NO),
00046 CORBA::Policy::_nil ());
00047
00048 TAO::Security::QOPPolicy * qop_policy = 0;
00049 ACE_NEW_THROW_EX (qop_policy,
00050 TAO::Security::QOPPolicy (qop),
00051 CORBA::NO_MEMORY (
00052 CORBA::SystemException::_tao_minor_code (
00053 TAO::VMCID,
00054 ENOMEM),
00055 CORBA::COMPLETED_NO));
00056 ACE_CHECK_RETURN (CORBA::Policy::_nil ());
00057
00058 return qop_policy;
00059 }
00060
00061 else if (type == ::Security::SecEstablishTrustPolicy)
00062 {
00063 ::Security::EstablishTrust *trust = 0;
00064
00065
00066
00067 if (!(value >>= trust))
00068 ACE_THROW_RETURN (CORBA::BAD_PARAM (
00069 CORBA::SystemException::_tao_minor_code (
00070 TAO::VMCID,
00071 EINVAL),
00072 CORBA::COMPLETED_NO),
00073 CORBA::Policy::_nil ());
00074
00075 TAO::Security::EstablishTrustPolicy * trust_policy = 0;
00076 ACE_NEW_THROW_EX (trust_policy,
00077 TAO::Security::EstablishTrustPolicy (*trust),
00078 CORBA::NO_MEMORY (
00079 CORBA::SystemException::_tao_minor_code (
00080 TAO::VMCID,
00081 ENOMEM),
00082 CORBA::COMPLETED_NO));
00083 ACE_CHECK_RETURN (CORBA::Policy::_nil ());
00084
00085 return trust_policy;
00086 }
00087
00088 else if (type == SecurityLevel3::ContextEstablishmentPolicyType)
00089 {
00090 SecurityLevel3::ContextEstablishmentPolicyArgument * args = 0;
00091
00092
00093
00094 if (!(value >>= args))
00095 ACE_THROW_RETURN (CORBA::BAD_PARAM (
00096 CORBA::SystemException::_tao_minor_code (
00097 TAO::VMCID,
00098 EINVAL),
00099 CORBA::COMPLETED_NO),
00100 CORBA::Policy::_nil ());
00101
00102 TAO::SL3::ContextEstablishmentPolicy * policy = 0;
00103 ACE_NEW_THROW_EX (policy,
00104 TAO::SL3::ContextEstablishmentPolicy (
00105 args->creds_directive,
00106 args->creds_list,
00107 args->use_client_auth,
00108 args->use_target_auth,
00109 args->use_confidentiality,
00110 args->use_integrity),
00111 CORBA::NO_MEMORY (
00112 CORBA::SystemException::_tao_minor_code (
00113 TAO::VMCID,
00114 ENOMEM),
00115 CORBA::COMPLETED_NO));
00116 ACE_CHECK_RETURN (CORBA::Policy::_nil ());
00117
00118 return policy;
00119 }
00120
00121 else if (type == SecurityLevel3::ObjectCredentialsPolicyType)
00122 {
00123 SecurityLevel3::OwnCredentialsList * creds = 0;
00124
00125
00126
00127 if (!(value >>= creds))
00128 ACE_THROW_RETURN (CORBA::BAD_PARAM (
00129 CORBA::SystemException::_tao_minor_code (
00130 TAO::VMCID,
00131 EINVAL),
00132 CORBA::COMPLETED_NO),
00133 CORBA::Policy::_nil ());
00134
00135 TAO::SL3::ObjectCredentialsPolicy * policy = 0;
00136 ACE_NEW_THROW_EX (policy,
00137 TAO::SL3::ObjectCredentialsPolicy (*creds),
00138 CORBA::NO_MEMORY (
00139 CORBA::SystemException::_tao_minor_code (
00140 TAO::VMCID,
00141 ENOMEM),
00142 CORBA::COMPLETED_NO));
00143 ACE_CHECK_RETURN (CORBA::Policy::_nil ());
00144
00145 return policy;
00146 }
00147
00148 else if (type == ::Security::SecInvocationCredentialsPolicy
00149 || type == ::Security::SecMechanismsPolicy
00150 || type == ::Security::SecFeaturePolicy
00151 || type == ::Security::SecDelegationDirectivePolicy)
00152 ACE_THROW_RETURN (CORBA::PolicyError (CORBA::UNSUPPORTED_POLICY),
00153 CORBA::Policy::_nil ());
00154 else
00155 ACE_THROW_RETURN (CORBA::PolicyError (CORBA::BAD_POLICY_TYPE),
00156 CORBA::Policy::_nil ());
00157 }
00158
00159 TAO_END_VERSIONED_NAMESPACE_DECL