~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/orbsvcs/Security/SecurityManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
 
3
 
#include "SecurityManager.h"
4
 
 
5
 
ACE_RCSID (Security,
6
 
           SecurityManager,
7
 
           "SecurityManager.cpp,v 1.6 2003/10/28 18:34:24 bala Exp")
8
 
 
9
 
 
10
 
#include "PrincipalAuthenticator.h"
11
 
 
12
 
#include "tao/ORB_Constants.h"
13
 
 
14
 
 
15
 
TAO_SecurityManager::TAO_SecurityManager (void)
16
 
  : lock_ (),
17
 
    principal_authenticator_ ()
18
 
{
19
 
}
20
 
 
21
 
TAO_SecurityManager::~TAO_SecurityManager (void)
22
 
{
23
 
}
24
 
 
25
 
Security::MechandOptionsList *
26
 
TAO_SecurityManager::supported_mechanisms (ACE_ENV_SINGLE_ARG_DECL)
27
 
  ACE_THROW_SPEC ((CORBA::SystemException))
28
 
{
29
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
30
 
                      CORBA::SystemException::_tao_minor_code (
31
 
                        TAO_DEFAULT_MINOR_CODE,
32
 
                        ENOTSUP),
33
 
                      CORBA::COMPLETED_NO),
34
 
                    0);
35
 
}
36
 
 
37
 
SecurityLevel2::CredentialsList *
38
 
TAO_SecurityManager::own_credentials (ACE_ENV_SINGLE_ARG_DECL)
39
 
  ACE_THROW_SPEC ((CORBA::SystemException))
40
 
{
41
 
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
42
 
                    monitor,
43
 
                    this->lock_,
44
 
                    0);
45
 
 
46
 
  SecurityLevel2::CredentialsList *creds_list = 0;
47
 
  ACE_NEW_THROW_EX (creds_list,
48
 
                    SecurityLevel2::CredentialsList (this->own_credentials_),
49
 
                    CORBA::NO_MEMORY (
50
 
                      CORBA::SystemException::_tao_minor_code (
51
 
                        TAO_DEFAULT_MINOR_CODE,
52
 
                        ENOMEM),
53
 
                      CORBA::COMPLETED_NO));
54
 
  ACE_CHECK_RETURN (0);
55
 
 
56
 
  return creds_list;
57
 
}
58
 
 
59
 
SecurityLevel2::RequiredRights_ptr
60
 
TAO_SecurityManager::required_rights_object (ACE_ENV_SINGLE_ARG_DECL)
61
 
  ACE_THROW_SPEC ((CORBA::SystemException))
62
 
{
63
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
64
 
                      CORBA::SystemException::_tao_minor_code (
65
 
                        TAO_DEFAULT_MINOR_CODE,
66
 
                        ENOTSUP),
67
 
                      CORBA::COMPLETED_NO),
68
 
                    SecurityLevel2::RequiredRights::_nil ());
69
 
}
70
 
 
71
 
SecurityLevel2::PrincipalAuthenticator_ptr
72
 
TAO_SecurityManager::principal_authenticator (ACE_ENV_SINGLE_ARG_DECL)
73
 
  ACE_THROW_SPEC ((CORBA::SystemException))
74
 
{
75
 
  {
76
 
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
77
 
                      monitor,
78
 
                      this->lock_,
79
 
                      SecurityLevel2::PrincipalAuthenticator::_nil ());
80
 
 
81
 
    if (CORBA::is_nil (this->principal_authenticator_.in ()))
82
 
      {
83
 
        TAO_PrincipalAuthenticator *pa = 0;
84
 
        ACE_NEW_THROW_EX (pa,
85
 
                          TAO_PrincipalAuthenticator (this),
86
 
                          CORBA::NO_MEMORY (
87
 
                            CORBA::SystemException::_tao_minor_code (
88
 
                              TAO_DEFAULT_MINOR_CODE,
89
 
                              ENOMEM),
90
 
                            CORBA::COMPLETED_NO));
91
 
        ACE_CHECK_RETURN (SecurityLevel2::PrincipalAuthenticator::_nil ());
92
 
 
93
 
        this->principal_authenticator_ = pa;
94
 
      }
95
 
  }
96
 
 
97
 
  return
98
 
    SecurityLevel2::PrincipalAuthenticator::_duplicate (
99
 
      this->principal_authenticator_.in ());
100
 
}
101
 
 
102
 
SecurityLevel2::AccessDecision_ptr
103
 
TAO_SecurityManager::access_decision (ACE_ENV_SINGLE_ARG_DECL)
104
 
  ACE_THROW_SPEC ((CORBA::SystemException))
105
 
{
106
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
107
 
                      CORBA::SystemException::_tao_minor_code (
108
 
                        TAO_DEFAULT_MINOR_CODE,
109
 
                        ENOTSUP),
110
 
                      CORBA::COMPLETED_NO),
111
 
                    SecurityLevel2::AccessDecision::_nil ());
112
 
}
113
 
 
114
 
SecurityLevel2::AuditDecision_ptr
115
 
TAO_SecurityManager::audit_decision (ACE_ENV_SINGLE_ARG_DECL)
116
 
  ACE_THROW_SPEC ((CORBA::SystemException))
117
 
{
118
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
119
 
                      CORBA::SystemException::_tao_minor_code (
120
 
                        TAO_DEFAULT_MINOR_CODE,
121
 
                        ENOTSUP),
122
 
                      CORBA::COMPLETED_NO),
123
 
                    SecurityLevel2::AuditDecision::_nil ());
124
 
}
125
 
 
126
 
SecurityLevel2::TargetCredentials_ptr
127
 
TAO_SecurityManager::get_target_credentials (CORBA::Object_ptr /* obj_ref */
128
 
                                             ACE_ENV_ARG_DECL)
129
 
  ACE_THROW_SPEC ((CORBA::SystemException))
130
 
{
131
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
132
 
                      CORBA::SystemException::_tao_minor_code (
133
 
                        TAO_DEFAULT_MINOR_CODE,
134
 
                        ENOTSUP),
135
 
                      CORBA::COMPLETED_NO),
136
 
                    SecurityLevel2::TargetCredentials::_nil ());
137
 
}
138
 
 
139
 
void
140
 
TAO_SecurityManager::remove_own_credentials (
141
 
    SecurityLevel2::Credentials_ptr creds
142
 
    ACE_ENV_ARG_DECL)
143
 
  ACE_THROW_SPEC ((CORBA::SystemException))
144
 
{
145
 
  ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);
146
 
 
147
 
  // Check if the given Credentials are already in the "own
148
 
  // credentials" list.
149
 
 
150
 
  const CORBA::ULong len = this->own_credentials_.length ();
151
 
 
152
 
  // @@ A linear search.  Yuck!
153
 
  for (CORBA::ULong i = 0; i < len; ++i)
154
 
    if (this->own_credentials_[i].in () == creds)
155
 
      {
156
 
        if (i == len - 1)
157
 
          this->own_credentials_.length (len - 1);
158
 
        else
159
 
          {
160
 
            // Avoid building a new CredentialsList.  Just invalidate
161
 
            // the Credentials in the current position in the
162
 
            // CredentialsList.
163
 
            //
164
 
            // This is has the disadvantage that it will leave "holes"
165
 
            // in the CredentialsList.
166
 
            this->own_credentials_[i] = SecurityLevel2::Credentials::_nil ();
167
 
          }
168
 
 
169
 
        return;
170
 
      }
171
 
 
172
 
  ACE_THROW (CORBA::BAD_PARAM ());
173
 
}
174
 
 
175
 
CORBA::Policy_ptr
176
 
TAO_SecurityManager::get_security_policy (CORBA::PolicyType /* policy_type */
177
 
                                          ACE_ENV_ARG_DECL)
178
 
  ACE_THROW_SPEC ((CORBA::SystemException))
179
 
{
180
 
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (
181
 
                      CORBA::SystemException::_tao_minor_code (
182
 
                        TAO_DEFAULT_MINOR_CODE,
183
 
                        ENOTSUP),
184
 
                      CORBA::COMPLETED_NO),
185
 
                    CORBA::Policy::_nil ());
186
 
}
187
 
 
188
 
void
189
 
TAO_SecurityManager::add_own_credentials (SecurityLevel2::Credentials_ptr creds
190
 
                                          ACE_ENV_ARG_DECL)
191
 
{
192
 
  ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);
193
 
 
194
 
  // Check if the given Credentials are already in the "own
195
 
  // credentials" list.
196
 
 
197
 
  const CORBA::ULong len = this->own_credentials_.length ();
198
 
 
199
 
  CORBA::ULong empty_slot = 0;
200
 
 
201
 
  // @@ A linear search.  Yuck!
202
 
  for (CORBA::ULong i = 0; i < len; ++i)
203
 
    if (this->own_credentials_[i].in () == creds)
204
 
      ACE_THROW (CORBA::BAD_PARAM ());
205
 
    else if (empty_slot == 0
206
 
             && CORBA::is_nil (this->own_credentials_[i]))
207
 
      empty_slot = i;
208
 
 
209
 
  if (empty_slot != 0)
210
 
    {
211
 
      this->own_credentials_[empty_slot] =
212
 
        SecurityLevel2::Credentials::_duplicate (creds);
213
 
    }
214
 
  else
215
 
    {
216
 
      this->own_credentials_.length (len + 1);
217
 
      this->own_credentials_[len] =
218
 
        SecurityLevel2::Credentials::_duplicate (creds);
219
 
    }
220
 
}