Class: BarkestCore::AuthConfig

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Validations
Defined in:
app/models/barkest_core/auth_config.rb

Overview

Defines the authentication configuration for the system.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AuthConfig

Creates the configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/barkest_core/auth_config.rb', line 27

def initialize(*args)
  args.each do |arg|
    if arg.is_a?(Hash)
      arg.each do |k,v|
        if respond_to?(:"#{k}?")
          send :"#{k}=", ((v === true || v === '1') ? '1' : '0')
        elsif respond_to?(k)
          send :"#{k}=", v.to_s
        end
      end
    end
  end
end

Instance Attribute Details

#enable_db_authObject

Returns the value of attribute enable_db_auth.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def enable_db_auth
  @enable_db_auth
end

#enable_ldap_authObject

Returns the value of attribute enable_ldap_auth.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def enable_ldap_auth
  @enable_ldap_auth
end

#ldap_auto_activateObject

Returns the value of attribute ldap_auto_activate.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_auto_activate
  @ldap_auto_activate
end

#ldap_base_dnObject

Returns the value of attribute ldap_base_dn.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_base_dn
  @ldap_base_dn
end

#ldap_browse_passwordObject

Returns the value of attribute ldap_browse_password.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_browse_password
  @ldap_browse_password
end

#ldap_browse_userObject

Returns the value of attribute ldap_browse_user.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_browse_user
  @ldap_browse_user
end

#ldap_hostObject

Returns the value of attribute ldap_host.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_host
  @ldap_host
end

#ldap_portObject

Returns the value of attribute ldap_port.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_port
  @ldap_port
end

#ldap_sslObject

Returns the value of attribute ldap_ssl.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_ssl
  @ldap_ssl
end

#ldap_system_admin_groupsObject

Returns the value of attribute ldap_system_admin_groups.



9
10
11
# File 'app/models/barkest_core/auth_config.rb', line 9

def ldap_system_admin_groups
  @ldap_system_admin_groups
end

Class Method Details

.loadObject

Loads the configuration from the SystemConfig.



90
91
92
# File 'app/models/barkest_core/auth_config.rb', line 90

def AuthConfig.load
  AuthConfig.new(SystemConfig.get(:auth) || {})
end

Instance Method Details

#enable_db_auth?Boolean

Is DB authentication enabled?

Returns:

  • (Boolean)


43
44
45
# File 'app/models/barkest_core/auth_config.rb', line 43

def enable_db_auth?
  enable_db_auth.to_s.to_i != 0
end

#enable_ldap_auth?Boolean

Is LDAP authentication enabled?

Returns:

  • (Boolean)


49
50
51
# File 'app/models/barkest_core/auth_config.rb', line 49

def enable_ldap_auth?
  enable_ldap_auth.to_s.to_i != 0
end

#ldap_auto_activate?Boolean

Is automatic activation enabled for LDAP authenticated users?

Returns:

  • (Boolean)


61
62
63
# File 'app/models/barkest_core/auth_config.rb', line 61

def ldap_auto_activate?
  ldap_auto_activate.to_s.to_i != 0
end

#ldap_ssl?Boolean

Is SSL enabled for LDAP authentication?

Returns:

  • (Boolean)


55
56
57
# File 'app/models/barkest_core/auth_config.rb', line 55

def ldap_ssl?
  ldap_ssl.to_s.to_i != 0
end

#saveObject

Saves the configuration (encrypted) to the SystemConfig.



84
85
86
# File 'app/models/barkest_core/auth_config.rb', line 84

def save
  SystemConfig.set :auth, to_h, true
end

#to_hObject

Converts the configuration to a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/barkest_core/auth_config.rb', line 67

def to_h
  {
      enable_db_auth: enable_db_auth?,
      enable_ldap_auth: enable_ldap_auth?,
      ldap_host: ldap_host.to_s,
      ldap_port: ldap_port.to_s.to_i,
      ldap_ssl: ldap_ssl?,
      ldap_base_dn: ldap_base_dn.to_s,
      ldap_browse_user: ldap_browse_user.to_s,
      ldap_browse_password: ldap_browse_password.to_s,
      ldap_auto_activate: ldap_auto_activate?,
      ldap_system_admin_groups: ldap_system_admin_groups.to_s,
  }
end