Class: Grnds::Sso::VpnConstraint
- Inherits:
-
Object
- Object
- Grnds::Sso::VpnConstraint
- Includes:
- Singleton
- Defined in:
- lib/grnds/sso/vpn_constraint.rb
Constant Summary collapse
- LOCALHOST =
'127.0.0.1'.freeze
- VPN =
%r{^10\.}.freeze
Instance Attribute Summary collapse
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#require_login ⇒ Object
(also: #require_login?)
Returns the value of attribute require_login.
Instance Method Summary collapse
- #authenticated?(request) ⇒ Boolean
- #configure {|_self| ... } ⇒ Object
-
#initialize ⇒ VpnConstraint
constructor
A new instance of VpnConstraint.
- #matches?(request) ⇒ Boolean
- #on_the_vpn?(request) ⇒ Boolean
Constructor Details
#initialize ⇒ VpnConstraint
Returns a new instance of VpnConstraint.
15 16 17 18 19 20 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 15 def initialize self.require_login = (Rails.env != 'development') # Our deployments use nginx in a way that hides the source IP address self.pattern = LOCALHOST end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
12 13 14 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 12 def pattern @pattern end |
#require_login ⇒ Object Also known as: require_login?
Returns the value of attribute require_login.
12 13 14 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 12 def require_login @require_login end |
Instance Method Details
#authenticated?(request) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 32 def authenticated?(request) session = request.session session[:init] = true unless session.loaded? return session['uid'].present? end |
#configure {|_self| ... } ⇒ Object
22 23 24 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 22 def configure yield self end |
#matches?(request) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 26 def matches?(request) return false unless !require_login? || authenticated?(request) return on_the_vpn?(request) end |
#on_the_vpn?(request) ⇒ Boolean
39 40 41 42 43 44 45 46 47 |
# File 'lib/grnds/sso/vpn_constraint.rb', line 39 def on_the_vpn?(request) case pattern when String return pattern == request.remote_ip else return pattern.match(request.remote_ip) end raise "VPN not defined" end |