class Nexpose::User
Attributes
all_groups[RW]
Boolean values
all_sites[RW]
Boolean values
authsrcid[RW]
Will default to XML
(1) for global-admin, Data Source (2) otherwise, but caller can override (e.g., using LDAP authenticator).
email[RW]
Optional fields
enabled[RW]
1 to enable this user, 0 to disable
full_name[RW]
groups[RW]
Optional fields
id[R]
user id, set to -1 to create a new user
name[R]
Required fields
password[RW]
Optional fields
role_name[RW]
valid roles: global-admin|security-manager|site-admin|system-admin|user|custom|controls-insight-only
sites[RW]
Optional fields
token[RW]
Optional fields
Public Class Methods
load(connection, user_id)
click to toggle source
Issue a UserConfigRequest to load an existing UserConfig from Nexpose
.
# File lib/nexpose/user.rb, line 156 def self.load(connection, user_id) xml = '<UserConfigRequest session-id="' + connection.session_id + '"' xml << %( 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'] token = config.attributes['token'] 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 User.new(name, fullname, password, role_name, id, enabled, email, all_sites, all_groups, token) end end end
new(name, full_name, password, role_name = 'user', id = -1, enabled = 1, email = nil, all_sites = false, all_groups = false, token = nil)
click to toggle source
# File lib/nexpose/user.rb, line 99 def initialize(name, full_name, password, role_name = 'user', id = -1, enabled = 1, email = nil, all_sites = false, all_groups = false, token = nil) @name = name @password = password @token = token @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
Public Instance Methods
delete(connection)
click to toggle source
Delete the user account associated with this object.
# File lib/nexpose/user.rb, line 183 def delete(connection) connection.delete_user(@id) end
save(connection)
click to toggle source
Save a user configuration. Returns the (new) user ID if successful.
# File lib/nexpose/user.rb, line 140 def save(connection) xml = '<UserSaveRequest session-id="' + connection.session_id + '">' xml << to_xml xml << '</UserSaveRequest>' r = connection.execute(xml, '1.1') if r.success r.res.elements.each('UserSaveResponse') do |attr| @id = attr.attributes['id'].to_i end @id else -1 end end
to_xml()
click to toggle source
# File lib/nexpose/user.rb, line 115 def to_xml xml = '<UserConfig' xml << %( id="#{@id}" ) xml << %( authsrcid="#{@authsrcid}" ) xml << %( name="#{replace_entities(@name)}" ) xml << %( fullname="#{replace_entities(@full_name)}" ) xml << %( role-name="#{replace_entities(@role_name)}" ) xml << %( password="#{replace_entities(@password)}" ) if @password xml << %( token="#{replace_entities(@token)}" ) if @token xml << %( email="#{replace_entities(@email)}" ) if @email xml << %( enabled="#{@enabled}" ) # These two fields are keying off role_name to work around a defect. xml << %( allGroups="#{@all_groups || @role_name == 'global-admin'}" ) xml << %( allSites="#{@all_sites || @role_name == 'global-admin'}" ) xml << '>' @sites.each do |site| xml << %( <site id="#{site}" /> ) end @groups.each do |group| xml << %( <group id="#{group}" /> ) end xml << '</UserConfig>' end