Class: Clickwrap::AuthorityRule
- Inherits:
-
Data
- Object
- Data
- Clickwrap::AuthorityRule
- Defined in:
- lib/clickwrap/authority.rb
Overview
The server-owned rule that says which represented parties a policy allows and which adapter has to establish the actor's authority. It is compiled into the policy revision and repeated in the signed presentation, so a browser cannot choose a weaker role or a different authority source.
Instance Attribute Summary collapse
-
#adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
-
#allow_represented_party_creation ⇒ Object
readonly
Returns the value of attribute allow_represented_party_creation.
-
#minimum_role ⇒ Object
readonly
Returns the value of attribute minimum_role.
-
#represented_party_types ⇒ Object
readonly
Returns the value of attribute represented_party_types.
-
#required_permission ⇒ Object
readonly
Returns the value of attribute required_permission.
Instance Method Summary collapse
- #allows_represented_party_creation? ⇒ Boolean
-
#initialize(represented_party_types: [], adapter_name: :host, minimum_role: nil, required_permission: nil, allow_represented_party_creation: false) ⇒ AuthorityRule
constructor
A new instance of AuthorityRule.
- #permits?(represented_party) ⇒ Boolean
- #to_snapshot ⇒ Object
Constructor Details
#initialize(represented_party_types: [], adapter_name: :host, minimum_role: nil, required_permission: nil, allow_represented_party_creation: false) ⇒ AuthorityRule
Returns a new instance of AuthorityRule.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/clickwrap/authority.rb', line 23 def initialize(represented_party_types: [], adapter_name: :host, minimum_role: nil, required_permission: nil, allow_represented_party_creation: false) normalized_types = Array(represented_party_types).filter_map do |type| name = type.is_a?(Class) ? type.name : type.to_s name unless name.strip.empty? end.uniq.freeze if normalized_types.empty? raise DefinitionError, "A represented-party authority rule must name at least one represented-party " \ "class. An empty list would let the rule authorize every kind of record." end super( represented_party_types: normalized_types, adapter_name: adapter_name.to_s, minimum_role: minimum_role&.to_s, required_permission: &.to_s, allow_represented_party_creation: allow_represented_party_creation == true ) end |
Instance Attribute Details
#adapter_name ⇒ Object (readonly)
Returns the value of attribute adapter_name
16 17 18 |
# File 'lib/clickwrap/authority.rb', line 16 def adapter_name @adapter_name end |
#allow_represented_party_creation ⇒ Object (readonly)
Returns the value of attribute allow_represented_party_creation
16 17 18 |
# File 'lib/clickwrap/authority.rb', line 16 def allow_represented_party_creation @allow_represented_party_creation end |
#minimum_role ⇒ Object (readonly)
Returns the value of attribute minimum_role
16 17 18 |
# File 'lib/clickwrap/authority.rb', line 16 def minimum_role @minimum_role end |
#represented_party_types ⇒ Object (readonly)
Returns the value of attribute represented_party_types
16 17 18 |
# File 'lib/clickwrap/authority.rb', line 16 def represented_party_types @represented_party_types end |
#required_permission ⇒ Object (readonly)
Returns the value of attribute required_permission
16 17 18 |
# File 'lib/clickwrap/authority.rb', line 16 def @required_permission end |
Instance Method Details
#allows_represented_party_creation? ⇒ Boolean
46 |
# File 'lib/clickwrap/authority.rb', line 46 def allows_represented_party_creation? = allow_represented_party_creation == true |
#permits?(represented_party) ⇒ Boolean
48 49 50 51 52 53 54 |
# File 'lib/clickwrap/authority.rb', line 48 def permits?(represented_party) return false if represented_party.nil? represented_party.class.ancestors.any? do |ancestor| ancestor.respond_to?(:name) && represented_party_types.include?(ancestor.name) end end |
#to_snapshot ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/clickwrap/authority.rb', line 56 def to_snapshot { "represented_party_types" => represented_party_types, "authority_adapter" => adapter_name, "when_actor_is_at_least" => minimum_role, "when_actor_has_permission" => , "including_when_this_action_creates_the_represented_party" => allows_represented_party_creation? }.compact end |