summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Security/SL3_PolicyFactory.cpp
blob: 7262bb8ce04aab2461f6bfa8b071185d05eff33d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// $Id$

#include "SL3_PolicyFactory.h"
#include "SL3_ContextEstablishmentPolicy.h"
#include "SL3_ObjectCredentialsPolicy.h"


ACE_RCSID (Security,
           SL3_PolicyFactory,
           "$Id$")


CORBA::Policy_ptr
TAO::SL3::PolicyFactory::create_policy (CORBA::PolicyType type,
                                        const CORBA::Any & value
                                        ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CORBA::PolicyError))
{
  CORBA::Policy_ptr policy = CORBA::Policy::_nil ();

  if (type == SecurityLevel3::ContextEstablishmentPolicyType)
    {
      SecurityLevel3::ContextEstablishmentPolicyArgument * arg = 0;
      if (!(value >>= arg))
        ACE_THROW_RETURN (CORBA::INTERNAL (),
                          policy);

      ACE_NEW_THROW_EX (policy,
                        TAO::SL3::ContextEstablishmentPolicy (
                          arg->creds_directive,
                          arg->creds_list,
                          arg->use_client_auth,
                          arg->use_target_auth,
                          arg->use_confidentiality,
                          arg->use_integrity),
                        CORBA::NO_MEMORY ());
      ACE_CHECK_RETURN (policy);
    }
  else if (type == SecurityLevel3::ObjectCredentialsPolicyType)
    {
      SecurityLevel3::ObjectCredentialsPolicyArgument * creds = 0;
      if (!(value >>= creds))
        ACE_THROW_RETURN (CORBA::INTERNAL (),
                          policy);

      ACE_NEW_THROW_EX (policy,
                        TAO::SL3::ObjectCredentialsPolicy (*creds),
                        CORBA::NO_MEMORY ());
      ACE_CHECK_RETURN (policy);
    }
  else
    {
      ACE_THROW_RETURN (CORBA::PolicyError (CORBA::BAD_POLICY_TYPE),
                        policy);
    }

  return policy;
}