| Back | Main view

IMiS/Storage Connector JAVA - Audit log

Product:IMiS/Storage Connector JAVA
Release:10.1.2010
Date:08/13/2021

Case: IMiS/Storage Connector Java - Audit log

Description:

This example demonstrates operations which reads audit log with parameters on the IMiS/ARChive Server.
Below is a description of operations for the reading audit log.


1. Directory entity audit log read

Operation reads the audit log for directory entity "kclay", results are returned in XML.


JAVA

IArchive archive = IMIS_ARCHIVE;

// Create query with list type, usernames scope and kclay username
AuditQuery query = new AuditQuery();
query.setEventIdQueryType(AuditQuery.QueryParamsType.LIST);
query.setSessionScope(AuditQuery.SessionParamsScope.USER_NAMES);
query.getUserNames().add("kclay");

// Read audit log XML and write result to string
String auditLogXML = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
  inputStream = archive.auditLogQuery(query);
  int n;
  byte[] buffer = new byte[4096];
  while (-1 != (n = inputStream.read(buffer)))
    outputStream.write(buffer, 0, n);
  outputStream.flush();

  auditLogXML = outputStream.toString("UTF-8");

  System.out.println(auditLogXML);
}
catch (LoginException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (StorageConnectorException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (IOException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
finally {
  try {
    outputStream.close();
  }
  catch (IOException e) {
    e.printStackTrace();
    System.out.println(e.getMessage());
  }
  if (null != inputStream) {
    try {
      inputStream.close();
    }
    catch (IOException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
  }
}


Result

<?xml version="1.0" encoding="UTF-8"?>
<auditlog.query.resultset xsi:schemaLocation="http://www.imis.si/imisarc http://www.imis.si/imisarc/auditlog.xsd" xmlns="http://www.imis.si/imisarc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sessions>
    <!--Audit query sessions.-->
    <session id="7632" closureReason="1" address="192.168.50.15" internal_address="192.168.100.64" dateTimeOpened="2020-10-23T12:42:07Z" dateTimeClosed="2020-10-23T12:44:22Z" username="kclay" computerName="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 Edg/86.0.622.51"/>
    <session id="7916" closureReason="1" address="192.168.100.63" dateTimeOpened="2020-11-09T09:17:55Z" dateTimeClosed="2020-11-09T09:28:17Z" username="kclay" computerName="DESKTOP-LB1R5U3"/>
  </sessions>
  <events>
    <!--Audit query events.-->
    <!--Sort compare function is QuerySorter::CompareSESS_TS-->
    <event sessionId="7632" type="27" seq="0" dateTime="2020-10-23T12:42:26Z" ver="8" verLabel="4" classificationCode="C=5^D=IS-CODE-923" context="0325d91031839b31fbc9948bc6e48a6c43229bf582894bd44edcea573b1d8658"/>
    <event sessionId="7632" type="28" seq="1" dateTime="2020-10-23T12:42:41Z" ver="9" verLabel="4.0.0.1" classificationCode="C=5^D=IS-CODE-923" context="0325d91031839b31fbc9948bc6e48a6c43229bf582894bd44edcea573b1d8658"/>
    <event sessionId="7632" type="19" seq="2" dateTime="2020-10-23T12:42:41Z" ver="9" verLabel="4.0.0.1" classificationCode="C=5^D=IS-CODE-923" context="0325d91031839b31fbc9948bc6e48a6c43229bf582894bd44edcea573b1d8658" message="Technology License Agreement.docx [5d3c79600a7a8d96492eec532179b43372eff50c4339e4e3c6562648c252a9a2]"/>
    <event sessionId="7632" type="21" seq="3" dateTime="2020-10-23T12:42:41Z" ver="9" verLabel="4.0.0.1" classificationCode="C=5^D=IS-CODE-923" context="0325d91031839b31fbc9948bc6e48a6c43229bf582894bd44edcea573b1d8658" message="Technology License Agreement.docx [5d3c79600a7a8d96492eec532179b43372eff50c4339e4e3c6562648c252a9a2]"/>
    <event sessionId="7632" type="4" seq="4" dateTime="2020-10-23T12:42:41Z" ver="9" verLabel="4.0.0.1" classificationCode="C=5^D=IS-CODE-923" context="0325d91031839b31fbc9948bc6e48a6c43229bf582894bd44edcea573b1d8658"/>
    <event sessionId="7916" type="19" seq="5" dateTime="2020-11-09T09:17:55Z" classificationCode="C=14^F=01/002/03^D=000005" context="f75c7c8cd277724e9b121223fa72472e1762efad607325c56a5055b32972951f" message="Dokument [b40c5b034ab6f4de542b4bd8f52de1c56452ead2e8c3df136ef33869ebfe50b8]"/>
    <event sessionId="7916" type="21" seq="6" dateTime="2020-11-09T09:17:55Z" classificationCode="C=14^F=01/002/03^D=000005" context="f75c7c8cd277724e9b121223fa72472e1762efad607325c56a5055b32972951f" message="Dokument [b40c5b034ab6f4de542b4bd8f52de1c56452ead2e8c3df136ef33869ebfe50b8]"/>
    <event sessionId="7916" type="18" seq="7" dateTime="2020-11-09T09:17:55Z" classificationCode="C=14^F=01/002/03^D=000005" context="f75c7c8cd277724e9b121223fa72472e1762efad607325c56a5055b32972951f" message="Dokument [b40c5b034ab6f4de542b4bd8f52de1c56452ead2e8c3df136ef33869ebfe50b8]"/>
    <event sessionId="7916" type="21" seq="8" dateTime="2020-11-09T09:17:55Z" classificationCode="C=14^F=01/002/03^D=000005" context="f75c7c8cd277724e9b121223fa72472e1762efad607325c56a5055b32972951f" message="Dokument [b40c5b034ab6f4de542b4bd8f52de1c56452ead2e8c3df136ef33869ebfe50b8]"/>
  </events>
</auditlog.query.resultset>


2. Audit log query events read

Operation reads the audit log after 24.08.2021, results are returned in XML.

JAVA

IArchive archive = IMIS_ARCHIVE;

// Create query with date from 24.08.2021
AuditQuery query = new AuditQuery();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, 24);
calendar.set(Calendar.MONTH, 7);
calendar.set(Calendar.YEAR, 2021);
query.setDateFrom(calendar);

// Read audit log XML and write result to string
String auditLogXML = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
  inputStream = archive.auditLogQuery(query);
  int n;
  byte[] buffer = new byte[4096];
  while (-1 != (n = inputStream.read(buffer)))
    outputStream.write(buffer, 0, n);
  outputStream.flush();

  auditLogXML = outputStream.toString("UTF-8");

  System.out.println(auditLogXML);
}
catch (LoginException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (StorageConnectorException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (IOException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
finally {
  try {
    outputStream.close();
  }
  catch (IOException e) {
    e.printStackTrace();
    System.out.println(e.getMessage());
  }
  if (null != inputStream) {
    try {
      inputStream.close();
    }
    catch (IOException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
  }
}

Result

<?xml version="1.0" encoding="UTF-8"?>
<auditlog.query.resultset xsi:schemaLocation="http://www.imis.si/imisarc http://www.imis.si/imisarc/auditlog.xsd" xmlns="http://www.imis.si/imisarc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sessions>
    <!--Audit query sessions.-->
    <session id="11082" isAuditQuery="true" closureReason="0" address="192.168.50.15" internal_address="192.168.100.51" dateTimeOpened="2021-08-24T11:17:09Z" username="anelson" computerName="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"/>
    <session id="11071" isAuditQuery="true" closureReason="0" address="192.168.80.64" internal_address="::1" dateTimeOpened="2021-08-23T13:24:31Z" username="admin" computerName="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"/>
    <session id="11080" isAuditQuery="true" closureReason="0" address="192.168.50.15" internal_address="192.168.80.64" dateTimeOpened="2021-08-24T09:34:47Z" username="admin" computerName="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"/>
  </sessions>
  <events>
    <!--Audit query events.-->
    <!--Sort compare function is QuerySorter::CompareSESS_TS-->
    <event sessionId="11082" type="2" seq="0" dateTime="2021-08-24T11:31:04Z" ver="3" verLabel="1.2" classificationCode="C=30^D=000006" context="070c36a85a4ce00d5303a635dc5f525ec80d83c35bf68be8f9d1fa6407f8ff71"/>
    <event sessionId="11082" type="17" seq="1" dateTime="2021-08-24T11:31:13Z" classificationCode="C=30^D=000006" context="070c36a85a4ce00d5303a635dc5f525ec80d83c35bf68be8f9d1fa6407f8ff71" message="bacode sample.pdf [a15b13daf00ae27ba9b690960839bea2e202777c30bdcf98d567f091a05da18f]"/>
    <event sessionId="11082" type="1" seq="5" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4"/>
    <event sessionId="11082" type="19" seq="6" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="r.pdf [2e80da9f647a9628106cac6558ab0bf19fdbf02c00ba143af92399bb746ff832]"/>
    <event sessionId="11082" type="21" seq="7" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="r.pdf [2e80da9f647a9628106cac6558ab0bf19fdbf02c00ba143af92399bb746ff832]"/>
    <event sessionId="11082" type="19" seq="8" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="AuditLog.csv [2f029c04c53c41a035d236c7cb4b6e9ce5f9ce5011a68b3d15e466b2fe9886b8]"/>
    <event sessionId="11082" type="21" seq="9" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="AuditLog.csv [2f029c04c53c41a035d236c7cb4b6e9ce5f9ce5011a68b3d15e466b2fe9886b8]"/>
    <event sessionId="11082" type="9" seq="10" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="Changed properties: sys:Category, sys:Description, sys:ExternalIds, sys:Keywords, sys:Owner, sys:Significance, sys:Title"/>
    <event sessionId="11082" type="13" seq="11" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="Opened [1]"/>
    <event sessionId="11082" type="12" seq="12" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="Security Class initially set to 'Secret [6684672]'"/>
    <event sessionId="11082" type="4" seq="13" dateTime="2021-08-24T13:14:56Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4"/>
    <event sessionId="11082" type="3" seq="14" dateTime="2021-08-24T13:15:04Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4"/>
    <event sessionId="11082" type="9" seq="15" dateTime="2021-08-24T13:15:13Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="Changed properties: Review Trigger"/>
    <event sessionId="11082" type="4" seq="16" dateTime="2021-08-24T13:15:13Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4"/>
    <event sessionId="11082" type="27" seq="17" dateTime="2021-08-24T13:18:09Z" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4"/>
    <event sessionId="11080" type="7" seq="18" dateTime="2021-08-24T13:36:04Z" message="Requested all audit events for user 'kclay' "/>
    <event sessionId="11080" type="7" seq="19" dateTime="2021-08-24T13:39:41Z" message="Requested all audit events for user 'kclay' "/>
    <event sessionId="11080" type="7" seq="20" dateTime="2021-08-24T13:39:49Z" message="Requested all audit events for user 'kclay' "/>
    <event sessionId="11080" type="7" seq="21" dateTime="2021-08-24T13:39:55Z" message="Requested all audit events for user 'kclay' "/>
    <event sessionId="11082" type="28" seq="22" dateTime="2021-08-24T13:40:41Z" ver="2" verLabel="2" classificationCode="C=30^D=000017" context="6f97d87786864af2061d29ed25c1e672caf0e7f18eb6b18f73e336f64cc8b3d4" message="Cras quis mauris sed ex faucibus venenatis vel quis lectus. "/>
  </events>
</auditlog.query.resultset>


3. Entity audit log read

Operation reads the audit log for entity with id "UI5xIqUKX70ano1FhnLNNnV_G2TJTR71", directory entity "anelson" and after 01.08.2021, results are returned in XML.

JAVA

IArchive archive = IMIS_ARCHIVE;

// Create query with entity id, list type, usernames scope, anelson username and date from 01.08.2021
AuditQuery query = new AuditQuery();
query.setObjectScope(AuditQuery.ObjectParamsScope.OBJECT_IDS);
query.getObjectIds().add("UI5xIqUKX70ano1FhnLNNnV_G2TJTR71");
query.setEventIdQueryType(AuditQuery.QueryParamsType.LIST);
query.setSessionScope(AuditQuery.SessionParamsScope.USER_NAMES);
query.getUserNames().add("anelson");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.MONTH, 7);
calendar.set(Calendar.YEAR, 2021);
query.setDateFrom(calendar);

// Read audit log XML and write result to string
String auditLogXML = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
  inputStream = archive.auditLogQuery(query);
  int n;
  byte[] buffer = new byte[4096];
  while (-1 != (n = inputStream.read(buffer)))
    outputStream.write(buffer, 0, n);
  outputStream.flush();

  auditLogXML = outputStream.toString("UTF-8");

  System.out.println(auditLogXML);
}
catch (LoginException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (StorageConnectorException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (IOException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
finally {
  try {
    outputStream.close();
  }
  catch (IOException e) {
    e.printStackTrace();
    System.out.println(e.getMessage());
  }
  if (null != inputStream) {
    try {
      inputStream.close();
    }
    catch (IOException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
  }
}

Result

<?xml version="1.0" encoding="UTF-8"?>
<auditlog.query.resultset xsi:schemaLocation="http://www.imis.si/imisarc http://www.imis.si/imisarc/auditlog.xsd" xmlns="http://www.imis.si/imisarc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sessions>
    <!--Audit query sessions.-->
    <session id="10906" isAuditQuery="true" closureReason="0" address="192.168.50.15" internal_address="192.168.100.50" dateTimeOpened="2021-08-11T08:43:36Z" username="anelson" computerName="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"/>
  </sessions>
  <events>
    <!--Audit query events.-->
    <!--Sort compare function is QuerySorter::CompareSESS_TS-->
    <event sessionId="10906" type="2" seq="0" dateTime="2021-08-11T09:57:48Z" classificationCode="C=3" context="d7efa3b61efbf9a8f817528675f2bd6cbe35e26ba4dad20dad7054f4fd91e917"/>
  </events>
</auditlog.query.resultset>


4. Entity audit log message

Operation sets the audit log message for entity open and first content part open.

JAVA

IArchive archive = IMIS_ARCHIVE;

IEntity entity = null;
try {
  // Set entity open audit log message
  archive.getAuditLog().setMessage("Entity open reason.");

  // Open entity
  entity = archive.openEntity(EntityIdKind.INTERNAL, "hs3iTw6Fvs4Y5jz67ODhkKY6-S4Uj2DL", null, AccessMode.READ, null);
  System.out.println(entity.getClassificationCode());

  if (entity instanceof IDocument) {
    IDocument document = (IDocument)entity;
    IReadOnlyList<IContentPart> parts = document.getContent().getParts();
    if (0 < parts.size()) {
      IContentPart contentPart = parts.get(0);
      System.out.println(contentPart.getDescription());
      InputStream inputStream = null;

      // Set content part open audit log message
      document.getAuditLog().setMessage("Entity content part open reason.");

      // Open content part and print content
      try {
        inputStream = contentPart.openDataInputStream();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        int n;
        byte[] buffer = new byte[4096];
        while (-1 < (n = inputStream.read(buffer)))
          outputStream.write(buffer, 0, n);
        System.out.println(outputStream.toString());
      }
      finally {
        if (null != inputStream) {
          inputStream.close();
        }
      }
    }
  }
}
catch (LoginException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (StorageConnectorException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
catch (IOException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
}
finally {
  // Close entity
  if (null != entity) {
    try {
      entity.close();
    }
    catch (StorageConnectorException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
    catch (IOException e) {
      e.printStackTrace();
      System.out.println(e.getMessage());
    }
  }
}

Result

C=3^D=000144
text.txt
Nunc ut suscipit sapien, sit amet aliquam est. Nullam ut eros justo. Fusce mollis enim at turpis porttitor mollis.


Entity audit log

<?xml version="1.0" encoding="UTF-8"?>
<auditlog.query.resultset xsi:schemaLocation="http://www.imis.si/imisarc http://www.imis.si/imisarc/auditlog.xsd" xmlns="http://www.imis.si/imisarc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <sessions>
    <!--Audit query sessions.-->
    <session id="12301" isAuditQuery="true" closureReason="1" address="192.168.80.64" internal_address="192.168.1.1" dateTimeOpened="2021-10-15T07:55:41Z" dateTimeClosed="2021-10-15T07:55:42Z" username="admin" computerName="Test Computer"/>
  </sessions>
  <events>
    <!--Audit query events.-->
    <!--Sort compare function is QuerySorter::CompareSESS_TS-->
    <event sessionId="12301" type="2" seq="5" dateTime="2021-10-15T07:55:41Z" classificationCode="C=3^D=000144" context="hs3iTw6Fvs4Y5jz67ODhkKY6-S4Uj2DL" message="Entity open reason."/>
    <event sessionId="12301" type="17" seq="6" dateTime="2021-10-15T07:55:42Z" classificationCode="C=3^D=000144" context="hs3iTw6Fvs4Y5jz67ODhkKY6-S4Uj2DL" message="text.txt [PG9In3Efy_oh3BaAxjPstT54XSIgGnuU];Entity content part open reason."/>
  </events>
</auditlog.query.resultset>


Related Documents:



| Back | Main view