Class: Crowd

Inherits:
Object
  • Object
show all
Defined in:
lib/crowd.rb,
lib/crowd/version.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Version Classes: AuthenticationConnectionException, AuthenticationException, AuthenticationInvalidCredentialException, AuthenticationInvalidException, AuthenticationInvalidObject, AuthenticationObjectNotFoundException

Constant Summary collapse

@@crowd_url =
nil
@@crowd_app_name =
nil
@@crowd_app_pword =
nil

Class Method Summary collapse

Class Method Details

.add_attribute_principal(username, attributes) ⇒ Object

Add attribute to principal



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/crowd.rb', line 211

def self.add_attribute_principal(username, attributes)
  attributes.each do |key, val|
    response = authenticated_connection do
      if(val.class == Array)
        valArray = ArrayOfString.new(val)
      else
        valArray = ArrayOfString.new
        valArray << val
      end

      tuple = SOAPAttribute.new(key, valArray)
      arg = AddAttributeToPrincipal.new(@@application_token, username, tuple)
      
      server.addAttributeToPrincipal(arg)
    end

    case response
      when AddAttributeToPrincipalResponse
        # Burying it because this means it was successful
      when ObjectNotFoundException
        raise AuthenticationObjectNotFoundException
      else
        raise AuthenticationException, response
    end
  end
  
  true
end

.add_principal(username, password, description, is_active, attributes) ⇒ Object

Add Principal



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
143
144
145
146
147
# File 'lib/crowd.rb', line 116

def self.add_principal(username, password, description, is_active, attributes)
  response = authenticated_connection do
    attrs = ArrayOfSOAPAttribute.new()

    attributes.each do |key, val|
      if (val.class == Array)
        attrVal = ArrayOfString.new(val)
      else
        attrVal = ArrayOfString.new
        attrVal << val
      end
      attrs << SOAPAttribute.new(key, attrVal)
    end

    principal = SOAPPrincipal.new(nil, is_active, attrs, nil, description, nil, nil, username)
    pword = PasswordCredential.new(password, false)
    arg = AddPrincipal.new(@@application_token, principal, pword)

    server.addPrincipal(arg)
  end

  case response
    when AddPrincipalResponse
      return true
    when InvalidCredentialException
      raise AuthenticationInvalidCredentalException
    when InvalidPrincipalException
      raise AuthenticationInvalidException, response
    else
      raise AuthenticationException, response
  end
end

.add_principal_to_role(username, role) ⇒ Object

Add Principal to Role



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/crowd.rb', line 346

def self.add_principal_to_role(username, role)    
  response = authenticated_connection do         
    arg = AddPrincipalToRole.new(@@application_token, username, role)
    #raise arg.to_yaml
    server.addPrincipalToRole(arg)
  end
  
  case response
    when AddPrincipalToRoleResponse
      return true
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.add_role(name, description, is_active) ⇒ Object

Add Role



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/crowd.rb', line 327

def self.add_role(name, description, is_active)
  response = authenticated_connection do 
    role = SOAPRole.new(nil, is_active, nil, nil, description, nil, nil, nil, name)
    arg = AddRole.new(@@application_token, role)
    server.addRole(arg)
  end
  
  case response
    when AddRoleResponse
      return true
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.authenticate_applicationObject

Authenticate application



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
# File 'lib/crowd.rb', line 57

def self.authenticate_application()
  @@application_token = nil
  
  if @@crowd_app_name.nil?
    @@crowd_app_name = CROWD_APPLICATION_NAME
  end
  if @@crowd_app_pword.nil?
    @@crowd_app_pword = CROWD_APPLICATION_PASSWORD
  end
  
  pword = PasswordCredential.new(@@crowd_app_pword, false)
  ctx = ApplicationAuthenticationContext.new(pword, @@crowd_app_name, nil)
  arg = AuthenticateApplication.new(ctx)

  begin      
    response = server.authenticateApplication(arg)  
  rescue Errno::ECONNREFUSED
    raise AuthenticationConnectionException
  rescue Exception
    raise AuthenticationException, response
  end

  if !response.is_a?(AuthenticateApplicationResponse)
    raise AuthenticationException, response
  end
  
  @@application_token = AuthenticatedToken.new(@@crowd_app_name, response.out.token)
  
  response.out.token
end

.authenticate_principal(username, password) ⇒ Object

Authenticate principal



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/crowd.rb', line 90

def self.authenticate_principal(username, password)
  response = authenticated_connection do      
    pword = PasswordCredential.new(password, false)
    ctx = PrincipalAuthenticationContext.new(@@application_token.name, pword, username, nil)
    arg = AuthenticatePrincipal.new(@@application_token, ctx)

    server.authenticatePrincipal(arg)      
  end    
  
  #evaluate the response.  ideally, the authenticatePrincipal call should
  #return an AuthenticationInvalidCredentialException and we can handle it more
  #nicely below.
  case response
    when AuthenticatePrincipalResponse        
      return response.out
    when InvalidAuthenticationException
      return nil      
    when nil #no reponse      
      raise AuthenticationInvalidCredentialException, response
    else
      raise AuthenticationException, response
  end
end

.crowd_app_name=(value) ⇒ Object



36
# File 'lib/crowd.rb', line 36

def self.crowd_app_name=(value); @@crowd_app_name = value; end

.crowd_app_pword=(value) ⇒ Object



37
# File 'lib/crowd.rb', line 37

def self.crowd_app_pword=(value); @@crowd_app_pword = value; end

.crowd_url=(value) ⇒ Object



35
# File 'lib/crowd.rb', line 35

def self.crowd_url=(value); @@crowd_url = value; end

.find_all_principal_namesObject

Find all principal names



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/crowd.rb', line 291

def self.find_all_principal_names    
  response = authenticated_connection do
    arg = FindAllPrincipalNames.new(@@application_token)
    server.findAllPrincipalNames(arg)
  end
  
  case response
    when FindAllPrincipalNamesResponse
      return response.out
    when ObjectNotFoundException
      return {}
    else
      raise AuthenticationException, response
  end
end

.find_all_role_namesObject

Find all role names



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/crowd.rb', line 309

def self.find_all_role_names
  response = authenticated_connection do 
    arg = FindAllRoleNames.new(@@application_token)
    server.findAllRoleNames(arg)
  end
  
  case response
    when FindAllRoleNamesResponse
      return response.out
    when ObjectNotFoundException
      return {}
    else
      raise AuthenticationException, response
  end
end

.find_principal_by_token(token) ⇒ Object

Find Principal via token



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/crowd.rb', line 169

def self.find_principal_by_token(token)
  response = authenticated_connection do
    arg = FindPrincipalByToken.new(@@application_token, token)
    server.findPrincipalByToken(arg)      
  end
  
  case response
    when FindPrincipalByTokenResponse
      return parse_principal(response.out)
    when ObjectNotFoundException
      return {}
    else
      raise AuthenticationException, response
  end
end

.find_principal_by_username(username) ⇒ Object

Find Principal via username



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/crowd.rb', line 151

def self.find_principal_by_username(username)
  response = authenticated_connection do
    arg = FindPrincipalByName.new(@@application_token, username)
    server.findPrincipalByName(arg)      
  end

  case response
    when FindPrincipalByNameResponse
      return parse_principal(response.out)
    when ObjectNotFoundException
      return {}
    else
      raise AuthenticationException, response
  end
end

.is_group_member(username, group) ⇒ Object

Is Group Member



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/crowd.rb', line 421

def self.is_group_member(username, group)
  response = authenticated_connection do 
    arg = IsGroupMember.new(@@application_token, group, username )
    server.isGroupMember(arg)
  end
  
  case response
    when IsGroupMemberResponse
      return response.out
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.is_role_member(username, role) ⇒ Object

Is Role Member



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/crowd.rb', line 383

def self.is_role_member(username, role)
  response = authenticated_connection do 
    arg = IsRoleMember.new(@@application_token, username, role )
    server.isRoleMember(arg)
  end
  
  case response
    when IsRoleMemberResponse
      return response.out
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.remove_attribute_principal(username, attributes) ⇒ Object

Remove principal attribute



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/crowd.rb', line 187

def self.remove_attribute_principal(username, attributes)    
  if(attributes.class != Array)
    attributes = [attributes]
  end
  
  attributes.each do |attr|
    response = authenticated_connection do
      arg = RemoveAttributeFromPrincipal.new(@@application_token, username, attr)
      server.removeAttributeFromPrincipal(arg)
    end

    case response
      when RemoveAttributeFromPrincipalResponse
        # Burying as this means it succeeded
      when ObjectNotFoundException
        raise AuthenticationObjectNotFoundException
      else
        raise AuthenticationException, response
    end
  end
end

.remove_principal(username) ⇒ Object

Remove principal



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/crowd.rb', line 273

def self.remove_principal(username)
  response = authenticated_connection do
    arg = RemovePrincipal.new(@@application_token, username)        
    server.removePrincipal(arg)
  end
  
  case response
    when RemovePrincipalResponse
      return true
    when ObjectNotFoundException
      raise AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end    
end

.remove_principal_from_role(username, role) ⇒ Object

Remove Principal form Role



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/crowd.rb', line 365

def self.remove_principal_from_role(username, role)
  response = authenticated_connection do 
    arg = RemovePrincipalFromRole.new(@@application_token, username, role)
    server.removePrincipalFromRole(arg)
  end
  
  case response
    when RemovePrincipalFromRoleResponse
      return true
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.remove_role(role) ⇒ Object

Remove Role



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/crowd.rb', line 403

def self.remove_role(role)
  response = authenticated_connection do 
    arg = RemoveRole.new(@@application_token, role)
    server.removeRole(arg)
  end
  
  case response
    when RemoveRoleResponse
      return true        
    when ObjectNotFoundException
      return AuthenticationObjectNotFoundException
    else
      raise AuthenticationException, response
  end
end

.update_attribute_principal(username, attributes) ⇒ Object

Update attribute on principal



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/crowd.rb', line 242

def self.update_attribute_principal(username, attributes)    
  attributes.each do |key, val|
    response = authenticated_connection do
      if val.is_a?(Array)
        valArray = ArrayOfString.new(val)
      else
        valArray = ArrayOfString.new
        valArray << val
      end

      tuple = SOAPAttribute.new(key, valArray)
      arg = UpdatePrincipalAttribute.new(@@application_token, username, tuple)
      
      server.updatePrincipalAttribute(arg)
    end

    case response
      when UpdatePrincipalAttributeResponse
        # Burying as it worked
      when ObjectNotFoundException
        raise AuthenticationObjectNotFoundException
      else
        raise AuthenticationException, response
    end
  end
  
  true
end