Class: Kraut::Principal
- Inherits:
-
Object
- Object
- Kraut::Principal
- Includes:
- Mapper
- Defined in:
- lib/kraut/principal.rb
Overview
Kraut::Principal
Represents a principal registered with Crowd.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns a Hash of attributes for the principal.
- #groups ⇒ Object
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
-
.authenticate(name, password) ⇒ Object
Expects a
name
andpassword
and returns a new authenticatedKraut::Principal
. - .find_by_token(token) ⇒ Object
Instance Method Summary collapse
-
#display_name ⇒ Object
Returns the principal name to display.
-
#email ⇒ Object
Returns the principal’s email address.
-
#member_of?(group) ⇒ Boolean
Returns whether the principal is a member of a given
group
. -
#requires_password_change? ⇒ Boolean
Returns whether the principal’s password is expired.
Methods included from Mapper
Instance Attribute Details
#attributes ⇒ Object
Returns a Hash of attributes for the principal.
49 50 51 |
# File 'lib/kraut/principal.rb', line 49 def attributes @attributes ||= find_attributes end |
#groups ⇒ Object
61 62 63 |
# File 'lib/kraut/principal.rb', line 61 def groups @groups ||= {} end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/kraut/principal.rb', line 30 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
30 31 32 |
# File 'lib/kraut/principal.rb', line 30 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
30 31 32 |
# File 'lib/kraut/principal.rb', line 30 def token @token end |
Class Method Details
.authenticate(name, password) ⇒ Object
Expects a name
and password
and returns a new authenticated Kraut::Principal
.
14 15 16 17 18 19 20 21 |
# File 'lib/kraut/principal.rb', line 14 def self.authenticate(name, password) response = Client.auth_request :authenticate_principal, :in1 => { "aut:application" => Application.name, "aut:credential" => { "aut:credential" => password }, "aut:name" => name } new :name => name.strip, :password => password, :token => response[:out].to_s end |
.find_by_token(token) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/kraut/principal.rb', line 23 def self.find_by_token(token) response = Client.auth_request :find_principal_by_token, :in1 => token.to_s # assumption: this works without failure since the auth_request raises an error if the request was not successful! new :name => response[:out][:name].to_s, :token => token.to_s end |
Instance Method Details
#display_name ⇒ Object
Returns the principal name to display.
33 34 35 |
# File 'lib/kraut/principal.rb', line 33 def display_name attributes[:display_name] end |
#email ⇒ Object
Returns the principal’s email address.
38 39 40 |
# File 'lib/kraut/principal.rb', line 38 def email attributes[:mail] end |
#member_of?(group) ⇒ Boolean
Returns whether the principal is a member of a given group
.
56 57 58 59 |
# File 'lib/kraut/principal.rb', line 56 def member_of?(group) return groups[group] unless groups[group].nil? groups[group] = Client.auth_request(:is_group_member, :in1 => group, :in2 => name)[:out] end |
#requires_password_change? ⇒ Boolean
Returns whether the principal’s password is expired. Principals with an expired password are still able to authenticate and access your application if you do not use this method.
44 45 46 |
# File 'lib/kraut/principal.rb', line 44 def requires_password_change? attributes[:requires_password_change] end |