Class: Grnds::Sso::VpnConstraint

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeVpnConstraint

Returns a new instance of VpnConstraint.



15
16
17
18
19
20
# File 'lib/grnds/sso/vpn_constraint.rb', line 15

def initialize
  self. = (Rails.env != 'development')

  # Our deployments use nginx in a way that hides the source IP address
  self.pattern = LOCALHOST
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



12
13
14
# File 'lib/grnds/sso/vpn_constraint.rb', line 12

def pattern
  @pattern
end

#require_loginObject 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
end

Instance Method Details

#authenticated?(request) ⇒ Boolean

Returns:

  • (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

Yields:

  • (_self)

Yield Parameters:



22
23
24
# File 'lib/grnds/sso/vpn_constraint.rb', line 22

def configure
  yield self
end

#matches?(request) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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