Class: Openam::User

Inherits:
Object
  • Object
show all
Defined in:
lib/openam/user.rb,
lib/openam/user/uri.rb,
lib/openam/user/version.rb

Constant Summary collapse

URI_LOGIN =
'json/authenticate?realm=Realm_DVS'.freeze
URI_LOGOUT =
'/identity/logout'.freeze
URI_ATTRIBUTE =
'identity/attributes?realm=Realm_DVS'.freeze
VERSION =
'0.1.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ User



11
12
13
14
15
# File 'lib/openam/user.rb', line 11

def initialize args
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#firstnameObject (readonly)

Returns the value of attribute firstname.



9
10
11
# File 'lib/openam/user.rb', line 9

def firstname
  @firstname
end

#lastnameObject (readonly)

Returns the value of attribute lastname.



9
10
11
# File 'lib/openam/user.rb', line 9

def lastname
  @lastname
end

#mailObject (readonly)

Returns the value of attribute mail.



9
10
11
# File 'lib/openam/user.rb', line 9

def mail
  @mail
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/openam/user.rb', line 8

def password
  @password
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/openam/user.rb', line 9

def status
  @status
end

#token_idObject

Returns the value of attribute token_id.



8
9
10
# File 'lib/openam/user.rb', line 8

def token_id
  @token_id
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/openam/user.rb', line 8

def username
  @username
end

Instance Method Details

#call_attributes_uriObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/openam/user.rb', line 46

def call_attributes_uri
  HTTP.post(
    "#{ENV['OPENAMURL']}#{URI_ATTRIBUTE}", 
    :form => {
      :subjectid =>@token_id
    }
  )
  .body
  .to_s
end

#call_login_uriObject



22
23
24
25
26
27
28
29
# File 'lib/openam/user.rb', line 22

def 
  http_body = HTTP.headers("Content-Type" => "application/json")
    .headers("X-OpenAM-Username" => @username)
    .headers("X-OpenAM-Password" => @password)
    .post("#{ENV['OPENAMURL']}#{URI_LOGIN}")
    .body
    .to_s
end

#connectObject



17
18
19
20
# File 'lib/openam/user.rb', line 17

def connect
  response  = JSON.parse()
  @token_id = response['tokenId']
end

#retrieve_attributesObject



57
58
59
60
61
62
63
# File 'lib/openam/user.rb', line 57

def retrieve_attributes
  user_attributes = user_hash
  @mail           = user_attributes['mail'][0]
  @lastname       = user_attributes['sn'][0]
  @firstname      = user_attributes['givenName'][0]
  @status         = user_attributes['inetUserStatus'][0]
end

#user_hashObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openam/user.rb', line 31

def user_hash
  opensso_user = Hash.new{ |h,k| h[k] = Array.new }
  attribute_name = ''
  lines = call_attributes_uri.split(/\n/)
  lines.each do |line|
    line = line.strip
    if line.match(/^userdetails.attribute.name=/)
      attribute_name = line.gsub(/^userdetails.attribute.name=/, '').strip
    elsif line.match(/^userdetails.attribute.value=/)
      opensso_user[attribute_name] << line.gsub(/^userdetails.attribute.value=/, '').strip
    end
  end
  opensso_user
end