Class: Legion::Extensions::Identity::Entra::Helpers::ScopeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/identity/entra/helpers/scope_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern:) ⇒ ScopeRegistry

Returns a new instance of ScopeRegistry.



13
14
15
16
17
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 13

def initialize(pattern:)
  @pattern = pattern.to_sym
  @requested = Concurrent::AtomicReference.new([])
  @granted = Concurrent::AtomicReference.new([])
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



11
12
13
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 11

def pattern
  @pattern
end

Instance Method Details

#deniedObject



49
50
51
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 49

def denied
  @requested.get - @granted.get
end

#grantedObject



23
24
25
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 23

def granted
  @granted.get.dup
end

#permitted?(scope) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 35

def permitted?(scope)
  @granted.get.include?(scope.to_s)
end

#permitted_all?(*scopes) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 39

def permitted_all?(*scopes)
  granted_set = @granted.get
  scopes.flatten.all? { |s| granted_set.include?(s.to_s) }
end

#permitted_any?(*scopes) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 44

def permitted_any?(*scopes)
  granted_set = @granted.get
  scopes.flatten.any? { |s| granted_set.include?(s.to_s) }
end

#record_granted(scopes) ⇒ Object



31
32
33
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 31

def record_granted(scopes)
  @granted.set(normalize(scopes).uniq.freeze)
end

#record_requested(scopes) ⇒ Object



27
28
29
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 27

def record_requested(scopes)
  @requested.set(normalize(scopes).uniq.freeze)
end

#requestedObject



19
20
21
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 19

def requested
  @requested.get.dup
end

#reset!Object



53
54
55
56
# File 'lib/legion/extensions/identity/entra/helpers/scope_registry.rb', line 53

def reset!
  @requested.set([])
  @granted.set([])
end