Class: Openam::User
- Inherits:
-
Object
- Object
- Openam::User
- 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
-
#firstname ⇒ Object
readonly
Returns the value of attribute firstname.
-
#lastname ⇒ Object
readonly
Returns the value of attribute lastname.
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
-
#password ⇒ Object
Returns the value of attribute password.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#token_id ⇒ Object
Returns the value of attribute token_id.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #call_attributes_uri ⇒ Object
- #call_login_uri ⇒ Object
- #connect ⇒ Object
-
#initialize(args) ⇒ User
constructor
A new instance of User.
- #retrieve_attributes ⇒ Object
- #user_hash ⇒ Object
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
#firstname ⇒ Object (readonly)
Returns the value of attribute firstname.
9 10 11 |
# File 'lib/openam/user.rb', line 9 def firstname @firstname end |
#lastname ⇒ Object (readonly)
Returns the value of attribute lastname.
9 10 11 |
# File 'lib/openam/user.rb', line 9 def lastname @lastname end |
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
9 10 11 |
# File 'lib/openam/user.rb', line 9 def mail @mail end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/openam/user.rb', line 8 def password @password end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/openam/user.rb', line 9 def status @status end |
#token_id ⇒ Object
Returns the value of attribute token_id.
8 9 10 |
# File 'lib/openam/user.rb', line 8 def token_id @token_id end |
#username ⇒ Object
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_uri ⇒ Object
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_uri ⇒ Object
22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
17 18 19 20 |
# File 'lib/openam/user.rb', line 17 def connect response = JSON.parse(call_login_uri) @token_id = response['tokenId'] end |
#retrieve_attributes ⇒ Object
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_hash ⇒ Object
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 |