Class: Nexpose::UserConfig
- Inherits:
-
Object
- Object
- Nexpose::UserConfig
- Includes:
- Sanitize
- Defined in:
- lib/nexpose/user.rb
Instance Attribute Summary collapse
-
#all_groups ⇒ Object
Boolean values.
-
#all_sites ⇒ Object
Boolean values.
-
#authsrcid ⇒ Object
Will default to XML (1) for global-admin, Data Source (2) otherwise, but caller can override (e.g., using LDAP authenticator).
-
#email ⇒ Object
Optional fields.
-
#enabled ⇒ Object
1 to enable this user, 0 to disable.
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#groups ⇒ Object
Optional fields.
-
#id ⇒ Object
readonly
user id, set to -1 to create a new user.
-
#name ⇒ Object
readonly
Required fields.
-
#password ⇒ Object
Optional fields.
-
#role_name ⇒ Object
valid roles: global-admin|security-manager|site-admin|system-admin|user|custom.
-
#sites ⇒ Object
Optional fields.
Class Method Summary collapse
-
.delete(connection, user_id) ⇒ Object
Delete a user account.
-
.load(connection, user_id) ⇒ Object
Issue a UserConfigRequest to load an existing UserConfig from Nexpose.
Instance Method Summary collapse
-
#delete(connection) ⇒ Object
Delete the user account associated with this object.
-
#initialize(name, full_name, password, role_name = 'user', id = -1,, enabled = 1, email = nil, all_sites = false, all_groups = false) ⇒ UserConfig
constructor
A new instance of UserConfig.
-
#save(connection) ⇒ Object
Save a user configuration.
- #to_s ⇒ Object
- #to_xml ⇒ Object
Methods included from Sanitize
Constructor Details
#initialize(name, full_name, password, role_name = 'user', id = -1,, enabled = 1, email = nil, all_sites = false, all_groups = false) ⇒ UserConfig
Returns a new instance of UserConfig.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nexpose/user.rb', line 91 def initialize(name, full_name, password, role_name = 'user', id = -1, enabled = 1, email = nil, all_sites = false, all_groups = false) @name = name @password = password @role_name = role_name @authsrcid = ('global-admin'.eql? @role_name) ? '1' : '2' @id = id @enabled = enabled @full_name = full_name @email = email @all_sites = all_sites || role_name == 'global-admin' @all_groups = all_groups || role_name == 'global-admin' @sites = [] @groups = [] end |
Instance Attribute Details
#all_groups ⇒ Object
Boolean values
89 90 91 |
# File 'lib/nexpose/user.rb', line 89 def all_groups @all_groups end |
#all_sites ⇒ Object
Boolean values
89 90 91 |
# File 'lib/nexpose/user.rb', line 89 def all_sites @all_sites end |
#authsrcid ⇒ Object
Will default to XML (1) for global-admin, Data Source (2) otherwise, but caller can override (e.g., using LDAP authenticator).
83 84 85 |
# File 'lib/nexpose/user.rb', line 83 def authsrcid @authsrcid end |
#email ⇒ Object
Optional fields
85 86 87 |
# File 'lib/nexpose/user.rb', line 85 def email @email end |
#enabled ⇒ Object
1 to enable this user, 0 to disable
87 88 89 |
# File 'lib/nexpose/user.rb', line 87 def enabled @enabled end |
#full_name ⇒ Object
Returns the value of attribute full_name.
80 81 82 |
# File 'lib/nexpose/user.rb', line 80 def full_name @full_name end |
#groups ⇒ Object
Optional fields
85 86 87 |
# File 'lib/nexpose/user.rb', line 85 def groups @groups end |
#id ⇒ Object (readonly)
user id, set to -1 to create a new user
75 76 77 |
# File 'lib/nexpose/user.rb', line 75 def id @id end |
#name ⇒ Object (readonly)
Required fields
79 80 81 |
# File 'lib/nexpose/user.rb', line 79 def name @name end |
#password ⇒ Object
Optional fields
85 86 87 |
# File 'lib/nexpose/user.rb', line 85 def password @password end |
#role_name ⇒ Object
valid roles: global-admin|security-manager|site-admin|system-admin|user|custom
77 78 79 |
# File 'lib/nexpose/user.rb', line 77 def role_name @role_name end |
#sites ⇒ Object
Optional fields
85 86 87 |
# File 'lib/nexpose/user.rb', line 85 def sites @sites end |
Class Method Details
.delete(connection, user_id) ⇒ Object
Delete a user account.
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/nexpose/user.rb', line 182 def self.delete(connection, user_id) xml = '<UserDeleteRequest session-id="' + connection.session_id + '"' xml << %Q{ id="#{user_id}"} xml << ' />' r = connection.execute(xml, '1.1') if r.success r.res.elements.each('UserConfigResponse/UserConfig') do |config| '1'.eql? config.attributes['id'] end end end |
.load(connection, user_id) ⇒ Object
Issue a UserConfigRequest to load an existing UserConfig from Nexpose.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/nexpose/user.rb', line 156 def self.load(connection, user_id) xml = '<UserConfigRequest session-id="' + connection.session_id + '"' xml << %Q{ id="#{user_id}"} xml << ' />' r = connection.execute(xml, '1.1') if r.success r.res.elements.each('UserConfigResponse/UserConfig') do |config| id = config.attributes['id'] role_name = config.attributes['role-name'] authsrcid = config.attributes['authsrcid'] name = config.attributes['name'] fullname = config.attributes['fullname'] email = config.attributes['email'] password = config.attributes['password'] enabled = config.attributes['enabled'].to_i all_sites = config.attributes['allSites'] == 'true' ? true : false all_groups = config.attributes['allGroups'] == 'true' ? true : false # Not trying to load sites and groups. # Looks like API currently doesn't return that info to load. return UserConfig.new(name, fullname, password, role_name, id, enabled, email, all_sites, all_groups) end end end |
Instance Method Details
#delete(connection) ⇒ Object
Delete the user account associated with this object.
195 196 197 |
# File 'lib/nexpose/user.rb', line 195 def delete(connection) UserConfig.delete(connection, @id) end |
#save(connection) ⇒ Object
Save a user configuration. Returns the (new) user ID if successful.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/nexpose/user.rb', line 139 def save(connection) xml = '<UserSaveRequest session-id="' + connection.session_id + '">' xml << to_xml xml << '</UserSaveRequest>' r = connection.execute(xml, '1.1') if r.success res = [] r.res.elements.each('UserSaveResponse') do |attr| @id = attr.attributes['id'].to_i end @id else -1 end end |
#to_s ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/nexpose/user.rb', line 106 def to_s out = "#{@user_name} (#{@full_name}) [ID: #{@id}, Role: #{@role_name}]" out << " Disabled" unless @enabled out << " All-Sites" if @all_sites out << " All-Groups" if @all_groups out << " e-mail: #{@email}" unless @email.nil? || @email.empty? out end |
#to_xml ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/nexpose/user.rb', line 115 def to_xml xml = "<UserConfig" xml << %Q{ id="#{@id}"} xml << %Q{ authsrcid="#{@authsrcid}"} xml << %Q{ name="#{@name}"} xml << %Q{ fullname="#{@full_name}"} xml << %Q{ role-name="#{@role_name}"} xml << %Q{ password="#{replace_entities(@password)}"} if @password xml << %Q{ email="#{@email}"} if @email xml << %Q{ enabled="#{@enabled}"} # These two fields are keying off role_name to work around a defect. xml << %Q{ allGroups="#{@all_groups || @role_name == 'global-admin'}"} xml << %Q{ allSites="#{@all_sites || @role_name == 'global-admin'}"} xml << ">" @sites.each do |site| xml << %Q{<site id="#{site}" />} end @groups.each do |group| xml << %Q{<group id="#{group}" />} end xml << '</UserConfig>' end |