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



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
270
271
272
# File 'lib/crowd.rb', line 245

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



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/crowd.rb', line 130

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



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

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



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/crowd.rb', line 361

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



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

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



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

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



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

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

.crowd_app_pword=(value) ⇒ Object



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

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

.crowd_url=(value) ⇒ Object



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

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

.find_all_principal_namesObject

Find all principal names



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

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



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/crowd.rb', line 343

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



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/crowd.rb', line 183

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 nil
    else
      raise AuthenticationException, response
  end 
rescue AuthenticationObjectNotFoundException
  return nil
rescue SOAP::FaultError => e
  raise AuthenticationException, e.message
end

.find_principal_by_username(username) ⇒ Object

Find Principal via username



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/crowd.rb', line 165

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 nil
    else
      raise AuthenticationException, response
  end
end

.invalidate_principal_token(token) ⇒ Object

Invalidate Principal Token



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/crowd.rb', line 205

def self.invalidate_principal_token(token)
  response = authenticated_connection do 
    arg = InvalidatePrincipalToken.new(@@application_token, token)
    server.invalidatePrincipalToken(arg)
  end
  
  case response
    when InvalidatePrincipalTokenResponse
      return true
    else
      raise AuthenticationException, response
  end
end

.is_group_member(username, group) ⇒ Object

Is Group Member



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/crowd.rb', line 455

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



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/crowd.rb', line 417

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

.is_valid_principal_token?(principal_token, validation_factors = []) ⇒ Boolean

Is valid principal token?

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/crowd.rb', line 114

def self.is_valid_principal_token?(principal_token, validation_factors = [])
  response = authenticated_connection do      
    arg = IsValidPrincipalToken.new(@@application_token, principal_token, validation_factors)
    server.isValidPrincipalToken(arg)      
  end    
  
  case response
    when IsValidPrincipalTokenResponse        
      return response.out
    else
      raise AuthenticationException, response
  end
end

.remove_attribute_principal(username, attributes) ⇒ Object

Remove principal attribute



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/crowd.rb', line 221

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



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

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



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/crowd.rb', line 399

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



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/crowd.rb', line 437

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



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/crowd.rb', line 276

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