summaryrefslogtreecommitdiff
path: root/orbsvcs/orbsvcs/Security/Security_PolicyFactory.cpp
blob: 9462e58aa60532a759196a7b2fd2cf16e42a6823 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// -*- C++ -*-
// $Id$

#include "orbsvcs/Security/Security_PolicyFactory.h"
#include "orbsvcs/Security/SL2_QOPPolicy.h"
#include "orbsvcs/Security/SL2_EstablishTrustPolicy.h"

#include "orbsvcs/Security/SL3_ContextEstablishmentPolicy.h"
#include "orbsvcs/Security/SL3_ObjectCredentialsPolicy.h"

#include "orbsvcs/SecurityLevel2C.h"
#include "orbsvcs/SecurityLevel3C.h"

#include "tao/ORB_Constants.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

CORBA::Policy_ptr
TAO::Security::PolicyFactory::create_policy (
    CORBA::PolicyType type,
    const CORBA::Any &value)
{
  // Not all security policies can be created using the
  // ORB::create_policy() mechanism.  Only those that can be created
  // using that mechanism are supported by this factory.

  if (type == ::Security::SecQOPPolicy)
    {
      ::Security::QOP qop;

      // Extract the desired Quality-of-Protection value from the
      // given Any.
      if (!(value >>= qop))
        throw CORBA::BAD_PARAM (
          CORBA::SystemException::_tao_minor_code (
            TAO::VMCID,
            EINVAL),
          CORBA::COMPLETED_NO);

      TAO::Security::QOPPolicy * qop_policy = 0;
      ACE_NEW_THROW_EX (qop_policy,
                        TAO::Security::QOPPolicy (qop),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      return qop_policy;
    }

  else if (type == ::Security::SecEstablishTrustPolicy)
    {
      ::Security::EstablishTrust *trust = 0;

      // Extract the desired establishing of trust value from the
      // given Any.
      if (!(value >>= trust))
        throw CORBA::BAD_PARAM (
          CORBA::SystemException::_tao_minor_code (
            TAO::VMCID,
            EINVAL),
          CORBA::COMPLETED_NO);

      TAO::Security::EstablishTrustPolicy * trust_policy = 0;
      ACE_NEW_THROW_EX (trust_policy,
                        TAO::Security::EstablishTrustPolicy (*trust),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      return trust_policy;
    }

  else if (type == SecurityLevel3::ContextEstablishmentPolicyType)
    {
      SecurityLevel3::ContextEstablishmentPolicyArgument * args = 0;

      // Extract the desired establishing of trust value from the
      // given Any.
      if (!(value >>= args))
        throw CORBA::BAD_PARAM (
          CORBA::SystemException::_tao_minor_code (
            TAO::VMCID,
            EINVAL),
          CORBA::COMPLETED_NO);

      TAO::SL3::ContextEstablishmentPolicy * policy = 0;
      ACE_NEW_THROW_EX (policy,
                        TAO::SL3::ContextEstablishmentPolicy (
                          args->creds_directive,
                          args->creds_list,
                          args->use_client_auth,
                          args->use_target_auth,
                          args->use_confidentiality,
                          args->use_integrity),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      return policy;
    }

  else if (type == SecurityLevel3::ObjectCredentialsPolicyType)
    {
      SecurityLevel3::OwnCredentialsList * creds = 0;

      // Extract the desired establishing of trust value from the
      // given Any.
      if (!(value >>= creds))
        throw CORBA::BAD_PARAM (
          CORBA::SystemException::_tao_minor_code (
            TAO::VMCID,
            EINVAL),
          CORBA::COMPLETED_NO);

      TAO::SL3::ObjectCredentialsPolicy * policy = 0;
      ACE_NEW_THROW_EX (policy,
                        TAO::SL3::ObjectCredentialsPolicy (*creds),
                        CORBA::NO_MEMORY (
                          CORBA::SystemException::_tao_minor_code (
                            TAO::VMCID,
                            ENOMEM),
                          CORBA::COMPLETED_NO));

      return policy;
    }

  else if (type == ::Security::SecInvocationCredentialsPolicy
           || type == ::Security::SecMechanismsPolicy
           || type == ::Security::SecFeaturePolicy             // Deprecated.
           || type == ::Security::SecDelegationDirectivePolicy)
    throw CORBA::PolicyError (CORBA::UNSUPPORTED_POLICY);
  else
    throw CORBA::PolicyError (CORBA::BAD_POLICY_TYPE);
}

TAO_END_VERSIONED_NAMESPACE_DECL