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.
50 51 52 |
# File 'lib/kraut/principal.rb', line 50 def attributes @attributes ||= find_attributes end |
#groups ⇒ Object
62 63 64 |
# File 'lib/kraut/principal.rb', line 62 def groups @groups ||= {} end |
#name ⇒ Object
Returns the value of attribute name.
31 32 33 |
# File 'lib/kraut/principal.rb', line 31 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
31 32 33 |
# File 'lib/kraut/principal.rb', line 31 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
31 32 33 |
# File 'lib/kraut/principal.rb', line 31 def token @token end |
Class Method Details
.authenticate(name, password) ⇒ Object
Expects a name
and password
and returns a new authenticated Kraut::Principal
.
15 16 17 18 19 20 21 22 |
# File 'lib/kraut/principal.rb', line 15 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, :password => password, :token => response[:out].to_s end |
.find_by_token(token) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/kraut/principal.rb', line 24 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.
34 35 36 |
# File 'lib/kraut/principal.rb', line 34 def display_name attributes[:display_name] end |
#email ⇒ Object
Returns the principal’s email address.
39 40 41 |
# File 'lib/kraut/principal.rb', line 39 def email attributes[:mail] end |
#member_of?(group) ⇒ Boolean
Returns whether the principal is a member of a given group
.
57 58 59 60 |
# File 'lib/kraut/principal.rb', line 57 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.
45 46 47 |
# File 'lib/kraut/principal.rb', line 45 def requires_password_change? attributes[:requires_password_change] end |