class Ucert::CitidirectSecuritiesTracker

Class to handle CitiDirect for Securities user account IDs

Attributes

cds_2_ad_user[R]
cds_user_entitlement[R]
cds_user_status_report[RW]

Class constant variables

file_cds_user_map[RW]

Class constant variables

verbose[RW]

Class constant variables

Public Class Methods

new(params ={}) click to toggle source

Instance default variables

# File lib/ucert/citidirect_securities_tracker.rb, line 20
def initialize (params ={})
  @verbose=params.fetch(:verbose, false)
  # CitiDirect for Securities user entitlement report generation: Logon to CitiDirect for Securities sites https://securities.citidirect.com
  # under "ISSUER" -> "AGENCY AND TRUST", Choose "Issuer And Paying Agent - NAM";
  # Select "Reports" -> "Report List" -> "Client" Report Categories -> "User Entitlements Report - CLNT", press "Get Parameters" button
  # Under "Sort Order - View", choose "Export" then press "Get Xml" button to generating the report
  # Press "Get File Directly" to download and unzip the xml report into a local file System
              #
  # Note: There is limitation in the entitlement report where 'Data Group' and 'Functional Group' details are not provided by the application
  #   You may need to logon to the application manually to review the entitlement details when necessary; the limitation also includes
              #   insufficient admin user data in the entitlement report.
  #@cds_user_entitlement_report = File.dirname(__FILE__)+"/../../data/citidirect_securities/User_Entitlements_Report___CLNT.xml"
              @cds_user_entitlement_report_dat = File.dirname(__FILE__)+"/../../data/citidirect_securities/User_Entitlements_Report___CLNT.dat"
              # CitiDirect for Securities to AD user map file
  @file_cds_user_map =  File.dirname(__FILE__)+"/../../data/citidirect_securities/citidirect_securities_user_map.txt"
              # the local cacsh file
              @cds_2_ad_user=load_known_user_map_from_file(@file_cds_user_map)
              # Load the user entitlement instance variable from the report
              @cds_user_entitlement=parse_cds_user_entitlement_report_dat(@cds_user_entitlement_report_dat)
              #@cds_user_entitlement=parse_cds_user_entitlement_report(@cds_user_entitlement_report)
              # Procedure to add DN foreign key to the @cds_user_entitlement, by using key1 key2 to perform the AD search
              insert_dn
              save!
      end

Public Instance Methods

cds_search_by_dn(dn) click to toggle source

Search user entitlement record by AD DN

# File lib/ucert/citidirect_securities_tracker.rb, line 215
    def cds_search_by_dn (dn)
            begin
  puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose
  @cds_user_entitlement.each do |key, val|
      return val if @cds_user_entitlement[key]['DN'].eql? dn
  end
                    return nil
rescue => ee
  puts "Exception on method #{__method__}: #{ee}"
end
    end
Also aliased as: search_by_dn
dn_2_index(dn) click to toggle source

Retrieve the user index from the @cds_user_entitlement data structure

# File lib/ucert/citidirect_securities_tracker.rb, line 129
def dn_2_index (dn)
                begin
(1..@cds_user_entitlement.count).map do |index|
  return index if @cds_user_entitlement[index]["DN"]==dn
end
                rescue => ee
                        puts "Exception on method #{__method__}: #{ee}"
                end
end
parse_cds_user_entitlement_report_dat(file) click to toggle source

Parsing the CitiDirect for Securities user entitlement report in DAT format

# File lib/ucert/citidirect_securities_tracker.rb, line 87
  def parse_cds_user_entitlement_report_dat (file)
          #begin
puts "Parse the user entitlement report: #{file}" if @verbose
cds_user_entitlement=Hash.new
user_index=0
                  line_cnt=0
                  cur_user=String.new
dat_doc = File.open(file, 'r')
dat_doc.each do |record|
                          line_cnt+=1
                          next if line_cnt == 1
                          rec=record.chomp!.split(/\t/)
                          ent=Hash.new
                          ent['Application'] = rec[8]
                          ent['Data Group'] = rec[9]
                          ent['Functional Group'] = rec[10]
                          if cur_user != rec[0]
                                  user_index+=1
                                  cur_user = rec[0]
                                  cds_user_entitlement[user_index]=Hash.new unless cds_user_entitlement.key?(user_index)
                                  cds_user_entitlement[user_index]['User Name'] = rec[0]
                                  cds_user_entitlement[user_index]['First Name'] = rec[1]
                                  cds_user_entitlement[user_index]['Last Name'] = rec[2]
                                  cds_user_entitlement[user_index]['Created'] = rec[3]
                                  cds_user_entitlement[user_index]['Last Login'] = rec[4]
                                  cds_user_entitlement[user_index]['Pwd Expired'] = rec[5]
                                  cds_user_entitlement[user_index]['Acct Disabled'] = rec[6]
                                  cds_user_entitlement[user_index]['Organization'] = rec[7]
                                  cds_user_entitlement[user_index]['Entitlements'] = Array.new
                                  cds_user_entitlement[user_index]['Entitlements'].push(ent)
                          else
                                  cds_user_entitlement[user_index]['Entitlements'].push(ent)
                          end
end
dat_doc=nil
return cds_user_entitlement
#rescue => ee
                  #    puts "Exception on method #{__method__}: #{ee}"
                  #end
  end
print_user_entitlement() click to toggle source

Print out the user entitlement table in plain text, to be imported into database

save!(file=@file_cds_user_map)
Alias for: save_cds_user_map!
search_by_dn(dn)
Alias for: cds_search_by_dn

Private Instance Methods

insert_dn() click to toggle source

Procedures to add additonal field 'dn' into the @cds_user_entitlement data structure, by person the AD search

# File lib/ucert/citidirect_securities_tracker.rb, line 140
  def insert_dn
          #begin
puts "Procedures to insert DN value into the User Entitlement data structure" if @verbose
tracker = Ucert::AdTracker.new
# Insert the foreign key pointing back to the AD user table
                  @cds_user_entitlement.each do |id, record|
                          key1 = record['First Name'].upcase + ' ' + record['Last Name']
                          key2 = record['First Name']
                          my_key=record['User Name'].upcase
                          puts "Perform search from the local cache first: #{my_key}" if @verbose
                          if @cds_2_ad_user.key?(my_key)
                                  dn=@cds_2_ad_user[my_key]
                                  # additional logic to update the existing DN record
                                  unless tracker.ad_person_records.key?(dn)
                                          dn = update_dn(tracker,dn)
                                  end
                                  puts "Found in the local cache file: #{dn}" if @verbose
                          else
                                  puts "Perform 2nd order search only if the 1st one fail, by using: #{my_key}" if @verbose
                                  dn=tracker.ad_search_by_text(my_key,"person")
                          end
                          if dn.nil? and !key1.nil?
                                  puts "Perform 3rd order search only if the last fail, by using: #{key1}" if @verbose
                                  dn = tracker.ad_search_by_text(key1, "person")
                          end
                          if dn.nil? and !key2.nil?
                                  puts "Perform 4th order search only if the last fail, by using: #{key2}" if @verbose
                                  dn = tracker.ad_search_by_text(key2, "person")
                          end
                          @cds_user_entitlement[id]['DN']=dn
                  end
tracker=nil
puts "DN insertion operation done." if @verbose
          #rescue => ee
                  #puts "Exception on method #{__method__}: #{ee}"
          #end
  end
parse_cds_user_entitlement_report(file) click to toggle source

Parsing the CitiDirect for Securities user entitlement report in XML format

# File lib/ucert/citidirect_securities_tracker.rb, line 46
  def parse_cds_user_entitlement_report (file)
puts "Parse the user entitlement report: #{file}" if @verbose
cds_user_entitlement=Hash.new
user_index=0
begin
  xml_doc = Nokogiri::XML(File.open(file))
  xml_doc.css("QueryDisplay1_Data").map do |record|
    user_index+=1
    puts "Processing user record number: #{user_index}" if @verbose
    cds_user_entitlement[user_index]=Hash.new unless cds_user_entitlement.key?(user_index)
    record.elements.each do |ele|
      puts ele.inspect if @verbose
      case ele.name.to_s
      when "UserName"
        puts "Username: #{ele.text}" if @verbose
        cds_user_entitlement[user_index]['UserName']=ele.text
      when "Created"
        cds_user_entitlement[user_index]['Created']=ele.text
      when "LastLogin"
        cds_user_entitlement[user_index]['LastLogin']=ele.text
      when "DataGroup"
        cds_user_entitlement[user_index]['DataGroup']=ele.text
      when "FunctionalGroup"
        cds_user_entitlement[user_index]['FunctionalGroup']=ele.text
      when "PwdExpired"
        cds_user_entitlement[user_index]['PwdExpired']=ele.text
      when "AcctDisabled"
        cds_user_entitlement[user_index]['AcctDisabled']=ele.text
      else
        # do nothing
      end
    end
  end
  xml_doc=nil
  return cds_user_entitlement
rescue => ee
                          puts "Exception on method #{__method__}: #{ee}"
                  end
  end
save_cds_user_map!(file=@file_cds_user_map) click to toggle source

Save the Prime to AD user mapping relation into the cache file

# File lib/ucert/citidirect_securities_tracker.rb, line 195
def save_cds_user_map!(file=@file_cds_user_map)
        puts "Saving the known Prime to AD user mapping relationship to file: #{file} ..." if @verbose
        begin
                timestamp=Time.now
                f=File.open(file, 'w')
                f.write "# local CitiDirect for Securitites to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
                @cds_user_entitlement.values.map do |record|
                        key = record['User Name'].upcase
                        value = record['DN']
                        f.write "\n#{key}|#{value}"
                end
                f.close
                puts "CitiDirect Securitites to AD user map file is successfully saved to: #{file}" if @verbose
        rescue => ee
                puts "Exception on method #{__method__}: #{ee}" if @verbose
        end
end
Also aliased as: save!