class Openam::User

Constants

URI_ATTRIBUTE
URI_LOGIN
URI_LOGOUT
VERSION

Attributes

firstname[R]
lastname[R]
mail[R]
password[RW]
status[R]
token_id[RW]
username[RW]

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

call_attributes_uri() click to toggle source
# 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_uri() click to toggle source
# File lib/openam/user.rb, line 22
def call_login_uri
  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
connect() click to toggle source
# File lib/openam/user.rb, line 17
def connect
  response  = JSON.parse(call_login_uri)
  @token_id = response['tokenId']
end
retrieve_attributes() click to toggle source
# 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_hash() click to toggle source
# 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