class Ucert::AllianceSwiftTracker
Class to handle Alliance Swift operator entitlement reprot
Attributes
Class constant variables
Class constant variables
Class constant variables
Class constant variables
Public Class Methods
Instance default variables
# File lib/ucert/alliance_swift_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # swift operator entitlement details report in xlxl format, generated by accessing "Configuration # -> Alliance Access: Access -> User Management -> Operators -> Search -> Report, select "Details" as 'Report type' # 'XLS' as 'Output Format', then click on 'OK' to save the report -> re-open it in Excel and save as 'XLXS' format. @swift_operator_details_report = File.dirname(__FILE__)+"/../../data/alliance_swift/Swift_Operator_Details.xlsx" # swift operator entitlement details report in 'XLXS' format, generated by accessing "Configuration -> Alliance Access: Access # -> User Management -> Operator Profiles -> Search, Report, Details"; 'XLS' as 'Output Format', then click on 'OK' to save the report # -> re-open it in Excel and save as 'XLXS' format. @swift_operator_profile_details_report = File.dirname(__FILE__)+"/../../data/alliance_swift/Swift_Operator_Profiles_Details.xlsx" # swift to AD operator map file @file_operator_map = File.dirname(__FILE__)+"/../../data/alliance_swift/swift_operator_map.txt" # Load the operator map file to an instance variable (for performance gain) @swift_2_ad_operator=load_known_user_map_from_file(@file_operator_map) # Load the operator entitlement instance variable from the most complete 'User Accout Function' Swift report @swift_operator_entitlement=Hash.new parse_swift_operator_details_report(@swift_operator_details_report) @swift_operator_profiles=Hash.new parse_swift_operator_profile_details_report(@swift_operator_profile_details_report) # Procedure to perform Swift to AD operator matching, insert AD DN into @swift_operator_entitlement data structure insert_dn save! end
Public Instance Methods
Perform search on the AD database, insert AD DN as a foreign key to the @swift_operator_entitlement instance variable
# File lib/ucert/alliance_swift_tracker.rb, line 180 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @swift_operator_entitlement.each do |record, value| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = @swift_operator_entitlement[record]['Name'].gsub("NY_","") if @swift_operator_entitlement[record]['Name'] key2 = @swift_operator_entitlement[record]['Name'] if @swift_operator_entitlement[record]['Name'] key3 = @swift_operator_entitlement[record]['Description'] if @swift_operator_entitlement[record]['Description'] my_key=key2.upcase + ':' + key3.upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @swift_2_ad_operator.key?(my_key) dn=@swift_2_ad_operator[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 if dn.nil? and !key1.nil? puts "Perform 2nd order search only if the 1st one fail, by using: #{key1}" if @verbose dn = tracker.ad_search_by_text(key1, "person") end if dn.nil? and !key2.nil? puts "Perform 3rd order search only if the last fail, by using: #{key2}" if @verbose dn = tracker.ad_search_by_text(key2, "person") end if dn.nil? and !key3.nil? puts "Perform 45d order search only if the last fail, by using: #{key3}" if @verbose dn = tracker.ad_search_by_text(key3, "person") end end @swift_operator_entitlement[record]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
swift_operator_entitlement
table lookup, input is “User Name”, output is the corresponding operator record number
# File lib/ucert/alliance_swift_tracker.rb, line 220 def operator_name_2_index (name) begin raise "Invalid operator name: #{name}" if name.nil? or name.empty? puts "Perform record number lookup for operator name: #{name}" if @verbose @swift_operator_entitlement.each do |key,val| next if val['Name'].nil? or val['Name'].empty? if val['Name'].upcase == name.upcase puts "Record number found: #{key}" if @verbose return key end end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Parsing the Alliance Access “Operator Profile Details” report in Excel xlsx format (exported from Swifts as .xls; open it in Excel, then save as .xlsx)
# File lib/ucert/alliance_swift_tracker.rb, line 105 def parse_swift_operator_profile_details_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] operator_count = 0 # Total Number of Operator in the report report_type = String.new record=0 # opeartor record index worksheet.count.times do |row| puts "Processing worksheet row: #{row}" if @verbose unless worksheet[row][0].nil? next if worksheet[row][0].value.to_s.empty? # Used for unique record identification if worksheet[row][0].value.to_s.downcase.include?("operator profile details") record += 1 puts "Recording operator record number: #{record}" if @verbose @swift_operator_profiles[record] = Hash.new unless @swift_operator_profiles.key?(record) end # Used for record recording self check purpose if worksheet[row][0].value.to_s.downcase.include?("number of entities:") puts "Record Operator Count " if @verbose operator_count=worksheet[row][2].value.to_i break end # Recording report header and criteria section if record == 0 puts "Recording Report Header, Criteria" if @verbose report_type=worksheet[row][2].value.to_s.strip unless worksheet[row][2].nil? if worksheet[row][0].value.to_s.strip.downcase.eql?("report type:") end if record > 0 puts "Record Operator Profile Details " if @verbose @swift_operator_profiles[record]['Name'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("name") if worksheet[row][0].value.to_s.downcase.strip.eql?("entities") @swift_operator_profiles[record]['Entities'] = Hash.new unless @swift_operator_profiles[record]['Entities'] worksheet[row][1].value.to_s.strip.split(/\n/).map do |entity| @swift_operator_profiles[record]['Entities'][entity]=Hash.new unless @swift_operator_profiles[record]['Entities'].key?(entity) end end if worksheet[row][0].value.to_s.downcase.strip.eql?("actions") cur_entity = String.new cur_act = String.new worksheet[row][1].value.to_s.strip.split(/\n/).map do |line| # split and process the 'Actions' field in the spreadsheet if line.include?('-') and line !~ /^\s+/ entry = line.split('-').map {|x| x.strip} cur_entity = entry[0] cur_act = entry[1] @swift_operator_profiles[record]['Entities'][cur_entity] = Hash.new unless @swift_operator_profiles[record]['Entities'].key?(cur_entity) @swift_operator_profiles[record]['Entities'][cur_entity][cur_act] = Array.new unless @swift_operator_profiles[record]['Entities'][cur_entity][cur_act] else #if action =~ /^\s+/ @swift_operator_profiles[record]['Entities'][cur_entity][cur_act].push(line.strip) end end end end end puts "Finish processing worksheet row: #{row}" if @verbose end puts "Finish parsing the workbook: #{file} " if @verbose workbook=nil #self sanity quick check if @swift_operator_profiles.count == operator_count and report_type.eql?("Operator Profiles - Detailed Report") puts "Past the sanity check!" if @verbose else abort "Parsing error: inconsistancy of Report Type #{report_type} or Operator Count #{operator_count} " end return @swift_operator_profiles rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Print out the operator entitlement table in plain text, to be imported into database
# File lib/ucert/alliance_swift_tracker.rb, line 238 def print_operator_entitlement begin puts "Operator Entitlement Report in Plain-text Format" if @verbose puts "Name Description Status Last Login Type Authentication Type Authoriser DN for FileAct Profiles Units DN" if @verbose @swift_operator_entitlement.values.map do |record| puts "#{record['Name']}|#{record['Description']}|#{record['Status']}|#{record['Last_Login']}|#{record['Type']}|#{record['Authentication_Type']}|#{record['Authoriser_DN_for_FileAct']}|#{record['Profile']}|#{record['Units']}|#{record['DN']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Print out the operator entitlement table in plain text, to be imported into database
# File lib/ucert/alliance_swift_tracker.rb, line 252 def print_operator_profiles begin puts "Operator Profiles Report in Plain-text Format" if @verbose puts "Name Entities" if @verbose @swift_operator_profiles.values.map do |record| puts "#{record['Name']}|#{record['Entities']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Search operator entitlement record by AD DN
# File lib/ucert/alliance_swift_tracker.rb, line 286 def swift_search_by_dn (dn) begin puts "Perform search on the operator entitlement record by AD DN: #{dn}" if @verbose @swift_operator_entitlement.each do |key, val| return val if @swift_operator_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
Parsing the Alliance Access “Operator Details” report in Excel xlsx format (exported from Swifts as .xls; open it in Excel, then save as .xlsx)
# File lib/ucert/alliance_swift_tracker.rb, line 45 def parse_swift_operator_details_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] operator_count = 0 # Total Number of Operator in the report report_type = String.new record=0 # opeartor record index worksheet.count.times do |row| puts "Processing worksheet row: #{row}" if @verbose unless worksheet[row][0].nil? next if worksheet[row][0].value.to_s.empty? # Used for unique record identification if worksheet[row][0].value.to_s.downcase.include?("operator details") record += 1 puts "Recording operator record number: #{record}" if @verbose @swift_operator_entitlement[record] = Hash.new unless @swift_operator_entitlement.key?(record) end # Used for record recording self check purpose if worksheet[row][0].value.to_s.downcase.include?("number of entities:") puts "Record Operator Count " if @verbose operator_count=worksheet[row][2].value.to_i break end # Recording report header and criteria section if record == 0 puts "Recording Report Header, Criteria" if @verbose report_type=worksheet[row][2].value.to_s.strip unless worksheet[row][2].nil? if worksheet[row][0].value.to_s.strip.downcase.eql?("report type:") end if record > 0 puts "Record Operator Details " if @verbose @swift_operator_entitlement[record]['Name'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("name") @swift_operator_entitlement[record]['Description'] = worksheet[row][1].value.to_s.strip.gsub(/\n/,' ') if worksheet[row][0].value.to_s.downcase.strip.eql?("description") @swift_operator_entitlement[record]['Status'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("status") @swift_operator_entitlement[record]['Last_Login'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("last login") @swift_operator_entitlement[record]['Type'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("type") @swift_operator_entitlement[record]['Authentication_Type'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("authentication type") @swift_operator_entitlement[record]['Authoriser_DN_for_FileAct'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("authoriser dn for fileact") @swift_operator_entitlement[record]['Profile'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("profiles") @swift_operator_entitlement[record]['Units'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("units") end end puts "Finish processing worksheet row: #{row}" if @verbose end puts "Finish parsing the workbook: #{file} " if @verbose workbook=nil #self sanity quick check if @swift_operator_entitlement.count == operator_count and report_type.eql?("Operators - Detailed Report") puts "Past the sanity check!" if @verbose else abort "Parsing error: inconsistancy of Report Type #{report_type} or Operator Count #{operator_count} " end return @swift_operator_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Save the swift to AD operator mapping relation into the cache file
# File lib/ucert/alliance_swift_tracker.rb, line 266 def save_swift_operator_map!(file=@file_operator_map) puts "Saving the known Swift to AD operator mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local Swift to AD operator map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @swift_operator_entitlement.values.map do |record| key = record['Name'].upcase + ':' + record['Description'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "Swift to AD operator map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end