Class: Wallaby::Configuration::Security

Inherits:
Object
  • Object
show all
Defined in:
lib/wallaby/configuration/security.rb

Overview

Security configuration

Constant Summary collapse

DEFAULT_CURRENT_USER =

by default, current_user returns nil

-> { nil }
DEFAULT_AUTHENTICATE =

by default, not to stop the before_action chain

-> { true }

Instance Method Summary collapse

Instance Method Details

#authenticate(&block) ⇒ Object

Configure how to authenicate a user. All application controller methods will be available.

Examples:

```
  Wallaby.config do |c|
    c.security.authenticate do
      authenticate_or_request_with_http_basic do |username, password|
        username == 'too_simple' && password == 'too_naive'
      end
    end
  end
```


46
47
48
49
50
51
52
# File 'lib/wallaby/configuration/security.rb', line 46

def authenticate(&block)
  if block_given?
    @authenticate = block
  else
    @authenticate ||= DEFAULT_AUTHENTICATE
  end
end

#authenticate?Boolean

See if authenticate configuration is set

Returns:

  • (Boolean)


56
57
58
# File 'lib/wallaby/configuration/security.rb', line 56

def authenticate?
  authenticate != DEFAULT_AUTHENTICATE
end

#current_user(&block) ⇒ Object

Configure how to get the current user. All application controller methods will be available.

Examples:

```
  Wallaby.config do |c|
    c.security.current_user do
      User.find_by_email session[:user_email]
    end
  end
```


20
21
22
23
24
25
26
# File 'lib/wallaby/configuration/security.rb', line 20

def current_user(&block)
  if block_given?
    @current_user = block
  else
    @current_user ||= DEFAULT_CURRENT_USER
  end
end

#current_user?Boolean

See if current_user configuration is set

Returns:

  • (Boolean)


30
31
32
# File 'lib/wallaby/configuration/security.rb', line 30

def current_user?
  current_user != DEFAULT_CURRENT_USER
end