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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#email_methodObject

Returns the value of attribute email_method.



5
6
7
# File 'lib/wallaby/configuration/security.rb', line 5

def email_method
  @email_method
end

#logout_methodObject

Returns the value of attribute logout_method.



5
6
7
# File 'lib/wallaby/configuration/security.rb', line 5

def logout_method
  @logout_method
end

#logout_pathObject

Returns the value of attribute logout_path.



5
6
7
# File 'lib/wallaby/configuration/security.rb', line 5

def logout_path
  @logout_path
end

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
```


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

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

#authenticate?Boolean

See if authenticate configuration is set

Returns:

  • (Boolean)


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

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
```


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

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)


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

def current_user?
  current_user != DEFAULT_CURRENT_USER
end