class Ucert::CitidirectBETracker
Class to handle Citidirect BE user entitlement report
Attributes
Class constant variables
Class constant variables
Class constant variables
Public Class Methods
Instance default variables
# File lib/ucert/citidirect_be_tracker.rb, line 20 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # Citidirect BE user entitlement report generation: # Navigate to the portal site https://portal.citidirect.com/; click 'Service' menu to lauch the java applet application; # In the applet windows, under 'User Administrtion' -> 'Access Management' -> 'User Entitlements', select and run # 'User Profile and Entitlements Report'; open the file then save as xlsx workbook format # @be_user_entitlement_report = File.dirname(__FILE__)+"/../../data/citidirect_be/UserProfileEntitlementsReport.xlsx" # Citidirect BE to AD user map file @file_be_user_map = File.dirname(__FILE__)+"/../../data/citidirect_be/be_user_map.txt" # Load user map from the local cacsh file @be_2_ad_user=load_known_user_map_from_file(@file_be_user_map) # Load the user entitlement instance variable from the user report @be_user_entitlement=parse_be_user_entitlement_report_new(@be_user_entitlement_report) # Procedure to add DN foreign key to the @be_user_entitlement, by performing the AD search insert_dn # Save the user map to local cache file save! end
Public Instance Methods
Search user entitlement record by AD DN
# File lib/ucert/citidirect_be_tracker.rb, line 403 def be_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @be_user_entitlement.each do |key, val| return val if @be_user_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Retrieve the user index from the @be_user_entitlement data structure
# File lib/ucert/citidirect_be_tracker.rb, line 316 def dn_2_index (dn) begin (1..@be_user_entitlement.count).map do |index| return index if @be_user_entitlement[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Parsing the Citidirect BE user entitlement report in the native Excel format
# File lib/ucert/citidirect_be_tracker.rb, line 166 def parse_be_user_entitlement_report_new (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose be_user_entitlement=Hash.new workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] user_number = 0 # Total Number of Users in the report report_date = String.new # Report generation date record=0 # user record index ent_profiles = Hash.new user_profile_recording = true entitlement_recording = false cur_ent = String.new cur_serv = String.new worksheet.count.times do |row| puts "Processing worksheet row: #{row}" if @verbose # Step 0 - Pre-proccessing # Skip empty row next if worksheet[row].nil? # if not recording entitlement, skip row with column A null or empty unless entitlement_recording next if worksheet[row][0].nil? next if worksheet[row][0].value.nil? next if worksheet[row][0].value.to_s.empty? puts "First cell of the row: #{worksheet[row][0].value.to_s}" if @verbose end # Step 1 - logic to extract report date if report_date.empty? && worksheet[row][0].value.to_s.include?("Report Date") puts "Recording report date:" if @verbose report_date = worksheet[row][0].value.to_s.split("Report Date ")[1] puts report_date if @verbose end # Step 2 - logic to determine starting of new user unless worksheet[row][0].nil? if worksheet[row][0].value.to_s.downcase.include?("first name") user_profile_recording = true if record > 0 entitlement_recording = false be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record) be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles end record += 1 puts "\nRecording user record number: #{record}" if @verbose be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record) ent_profiles = Hash.new end end # Step 3 - logic to collect user basic profile #unless worksheet[row][1].nil? if user_profile_recording case worksheet[row][0].value.to_s when /First Name/ be_user_entitlement[record]['First_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip entitlement_recording = false next when /Middle Name/ be_user_entitlement[record]['Middle_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Last Name/ be_user_entitlement[record]['Last_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Initials/ be_user_entitlement[record]['Initials'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Status/ be_user_entitlement[record]['Status'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Alias/ be_user_entitlement[record]['Alias'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /E-Mail Address/ be_user_entitlement[record]['E-Mail'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Credential/ be_user_entitlement[record]['Credential'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next when /Entitlement Name/ entitlement_recording = true user_profile_recording = false next else # doing nothing at this time end end # Step 4 - logic to collect user entitlement details: name -> product -> service -> entitlement attributes # Recording user product details if entitlement_recording # check column B, C not empty to determin the product name if !worksheet[row][0].nil? and !worksheet[row][1].nil? and !worksheet[row][2].nil? cur_ent = worksheet[row][0].value.to_s.strip cur_serv = worksheet[row][2].value.to_s.strip ent_profiles[cur_ent] = Hash.new ent_profiles[cur_ent]['Product Name']=worksheet[row][1].value.to_s.strip ent_profiles[cur_ent][cur_serv]=Hash.new ent_profiles[cur_ent][cur_serv]['Service Name']=cur_serv ent_profiles[cur_ent][cur_serv]['Entitlements']=Array.new next end # check column c to determine current service name if !worksheet[row][2].nil? cur_serv = worksheet[row][2].value.to_s.strip ent_profiles[cur_ent][cur_serv]=Hash.new ent_profiles[cur_ent][cur_serv]['Service Name']=cur_serv ent_profiles[cur_ent][cur_serv]['Entitlements']=Array.new next end # catch the entitlement key value pairs if !worksheet[row][3].nil? and !worksheet[row][4].nil? ent = {worksheet[row][3].value.to_s => worksheet[row][4].value.to_s} puts "Entilement pair found: #{ent}" if @verbose ent_profiles[cur_ent][cur_serv]['Entitlements'].push(ent) next end # catch the footer of the report if !worksheet[row][0].nil? case worksheet[row][0].value.to_s when /Filters have been applied to this data/ user_profile_recording = false entitlement_recording = false next else end end end puts "Finish processing worksheet row: #{row}" if @verbose end puts "Finish parsing the workbook: #{file} " if @verbose workbook=nil be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles return be_user_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
Procedures to add additonal field 'dn' into the @be_user_entitlement data structure, by person the AD search
# File lib/ucert/citidirect_be_tracker.rb, line 327 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @be_user_entitlement.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record['E-Mail'] if record['E-Mail'] key2 = record['First_Name'] + " " + record['Last_Name'] if record['First_Name'] and record['Last_Name'] key3 = record['First_Name'] if record['First_Name'] my_key = record['E-Mail'].upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @be_2_ad_user.key?(my_key) dn=@be_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 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 4th order search only if the last fail, by using: #{key3}" if @verbose dn = tracker.ad_search_by_text(key3, "person") end end @be_user_entitlement[index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Parsing the Citidirect BE user entitlement report in text format
# File lib/ucert/citidirect_be_tracker.rb, line 41 def parse_be_user_entitlement_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose be_user_entitlement=Hash.new workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] user_number = 0 # Total Number of Users in the report report_date = String.new # Report generation date record=0 # user record index access_profile_recording = false ent_profiles = Hash.new skip_next = 0 worksheet.count.times do |row| if skip_next > 0 skip_next -= 1 next end puts "Processing worksheet row: #{row}" if @verbose next if worksheet[row].nil? next if worksheet[row][0].nil? next if worksheet[row][0].value.nil? next if worksheet[row][0].value.to_s.empty? puts "First cell of the row: #{worksheet[row][0].value.to_s}" if @verbose # logic to determine starting of new user if worksheet[row][0].value.to_s.downcase.include?("first name") if record > 0 access_profile_recording = false be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record) be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles end record += 1 puts "\nRecording user record number: #{record}" if @verbose be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record) ent_profiles = Hash.new end # logic to extract report date if report_date.empty? && worksheet[row][0].value.to_s.include?("Report Date") puts "Recording report date:" if @verbose report_date = worksheet[row][0].value.to_s.split("Report Date ")[1] puts report_date if @verbose end # logic to determine total number of users if user_number == 0 && worksheet[row][0].value.to_s.include?("Total Number of Users") puts "Recording number of users:" if @verbose user_number=worksheet[row][1].value.to_i puts user_number if @verbose access_profile_recording = false end puts "Recording user inforamtion in column B: " if @verbose #unless worksheet[row][1].nil? case worksheet[row][0].value.to_s when /First Name/ be_user_entitlement[record]['First_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Last Name/ be_user_entitlement[record]['Last_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Enabled/ be_user_entitlement[record]['Enabled'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Building\/Floor\/Room/ be_user_entitlement[record]['Building_Floor_Room'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /State\/Province\/Territory/ be_user_entitlement[record]['State_Province_Territory'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Telephone/ be_user_entitlement[record]['Telephone'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Time Zone/ be_user_entitlement[record]['Time_Zone'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /User Account Type/ be_user_entitlement[record]['User_Account_Type'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Access To Days/ be_user_entitlement[record]['Allow_User_Access_To_Days'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Allow User Access To Time/ be_user_entitlement[record]['Allow_User_Access_To_Time'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip when /Credential Type/ be_user_entitlement[record]['Credential_Type'] = worksheet[row+1][0].nil? ? nil : worksheet[row+1][0].value.to_s.strip be_user_entitlement[record]['Credential_ID'] = worksheet[row+1][1].nil? ? nil : worksheet[row+1][1].value.to_s.strip skip_next = 1 # skip the next row next when /Assigned Access Profiles/ access_profile_recording = true next when /Billing Account Number/ #be_user_entitlement[record]['SYSTEM_ADMINISTRATOR'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.include?("SYSTEM ADMINISTRATOR") access_profile_recording = false be_user_entitlement[record]['Billing_Account_Number'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip next else if access_profile_recording my_key = worksheet[row][0].value.to_s.strip my_val = worksheet[row][1].value.to_s.strip puts "Found profile: #{{my_key => my_val}}" if @verbose ent_profiles.merge!({my_key => my_val}) unless my_key.empty? end end puts "Done recording on column B" if @verbose # recording user information in Column D unless worksheet[row][2].nil? or worksheet[row][3].nil? puts "Recording user inforamtion in column D: " if @verbose be_user_entitlement[record]['Middle_Name'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Middle Name") be_user_entitlement[record]['Initials'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Initials") be_user_entitlement[record]['Street_Address'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Street Address") be_user_entitlement[record]['City'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("City") be_user_entitlement[record]['Zip_Code'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Zip Code") be_user_entitlement[record]['Country_Code'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Country Code") be_user_entitlement[record]['Employee_ID'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Employee ID") be_user_entitlement[record]['E-Mail_Address'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("E-Mail Address") be_user_entitlement[record]['Days_of_the_Week'] = worksheet[row][3].value.to_s.strip if worksheet[row][2].value.to_s.include?("Days of the Week") puts "Done recording on column D" if @verbose 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 be_user_entitlement.count == user_number puts "Past sanity check past!" if @verbose else raise "Parsing error: inconsistancy number of users: #{user_number}" end be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles return be_user_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Parsing the Citidirect BE user group entitlement report in text format TBD as currently this feature is Unknown
# File lib/ucert/citidirect_be_tracker.rb, line 307 def parse_be_user_group_entitlement_report (file) begin rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/citidirect_be_tracker.rb, line 367 def print_user_entitlement begin puts "user Entitlement Report in Plain-text Format" if @verbose @be_user_entitlement[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @be_user_entitlement.values.map do |rec| rec.each {|k,v| print v,"|"} puts end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Save the Prime to AD user mapping relation into the cache file
# File lib/ucert/citidirect_be_tracker.rb, line 383 def save_be_user_map!(file=@file_be_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 BE to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @be_user_entitlement.values.map do |record| key = record['E-Mail'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "Citidirect BE to AD user map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end