com.github.cafaudit.AuditLog Maven / Gradle / Ivy
/*
* Copyright 2015-2018 Micro Focus or one of its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.cafaudit;
import com.hpe.caf.auditing.AuditChannel;
import com.hpe.caf.auditing.AuditEventBuilder;
import com.hpe.caf.auditing.exception.AuditingException;
import com.hpe.caf.auditing.AuditIndexingHint;
import java.io.IOException;
import java.util.Date;
/**
* Auto-generated class for writing AuditMonkey events to the audit log
*/
public final class AuditLog
{
private static final String APPLICATION_IDENTIFIER = "AuditMonkey";
private AuditLog() {
}
/**
* Checks that the AuditLog queue exists and creates it if it doesn't.
* This function should be called before any of the audit... functions are called.
*/
public static void declareApplication(final AuditChannel channel)
throws IOException
{
channel.declareApplication(APPLICATION_IDENTIFIER);
}
/**
* Audit the viewDocument event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param docId Identifies the document that was viewed
*/
public static void auditViewDocument
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final long docId
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("exampleEvents", "viewDocument");
auditEventBuilder.addEventParameter("docId", null, docId);
auditEventBuilder.send();
}
/**
* Audit the policyApplied event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param policyId Policy Identifier
* @param policyName Policy Name
* @param policyDef Policy Definition
*/
public static void auditPolicyApplied
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final int policyId,
final String policyName,
final String policyDef
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("policyEvents", "policyApplied");
auditEventBuilder.addEventParameter("policyId", null, policyId);
auditEventBuilder.addEventParameter("policyName", null, policyName, AuditIndexingHint.FULLTEXT);
auditEventBuilder.addEventParameter("policyDef", null, policyDef, AuditIndexingHint.KEYWORD);
auditEventBuilder.send();
}
/**
* Audit the createDocument event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param docId Unique Identifier of the document
* @param title Title of the Document
* @param fileType File type of the document
* @param date Date of when the document was created
* @param username Unique username of the user
*/
public static void auditCreateDocument
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final long docId,
final String title,
final String fileType,
final Date date,
final String username
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("documentEvents", "createDocument");
auditEventBuilder.addEventParameter("docId", null, docId);
auditEventBuilder.addEventParameter("title", null, title, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("fileType", null, fileType, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.send();
}
/**
* Audit the readDocument event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param docId Unique Identifier of the document
* @param title Title of the Document
* @param fileType File type of the document
* @param date Date of when the document was read
* @param username Unique username of the user
*/
public static void auditReadDocument
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final long docId,
final String title,
final String fileType,
final Date date,
final String username
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("documentEvents", "readDocument");
auditEventBuilder.addEventParameter("docId", null, docId);
auditEventBuilder.addEventParameter("title", null, title, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("fileType", null, fileType, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.send();
}
/**
* Audit the deleteDocument event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param docId Unique Identifier of the document
* @param title Title of the Document
* @param fileType File type of the document
* @param date Date of when the document was deleted
* @param username Unique username of the user
*/
public static void auditDeleteDocument
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final long docId,
final String title,
final String fileType,
final Date date,
final String username
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("documentEvents", "deleteDocument");
auditEventBuilder.addEventParameter("docId", null, docId);
auditEventBuilder.addEventParameter("title", null, title, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("fileType", null, fileType, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.send();
}
/**
* Audit the moveDocument event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param docId Unique Identifier of the document
* @param title Title of the Document
* @param fileType File type of the document
* @param date Date of when the document was created
* @param username Unique username of the user
* @param initialPath Starting location of the document as a path
* @param destinationPath Final location of the document as a path
*/
public static void auditMoveDocument
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final long docId,
final String title,
final String fileType,
final Date date,
final String username,
final String initialPath,
final String destinationPath
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("documentEvents", "moveDocument");
auditEventBuilder.addEventParameter("docId", null, docId);
auditEventBuilder.addEventParameter("title", null, title, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("fileType", null, fileType, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("initialPath", null, initialPath, AuditIndexingHint.FULLTEXT);
auditEventBuilder.addEventParameter("destinationPath", null, destinationPath, AuditIndexingHint.FULLTEXT);
auditEventBuilder.send();
}
/**
* Audit the createUser event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param username Unique username of the user
* @param emailAddress User's email address
* @param date Date user created
*/
public static void auditCreateUser
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final String username,
final String emailAddress,
final Date date
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("userEvents", "createUser");
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("emailAddress", null, emailAddress, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.send();
}
/**
* Audit the deleteUser event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param username Unique username of the user
* @param date Date user deleted
*/
public static void auditDeleteUser
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final String username,
final Date date
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("userEvents", "deleteUser");
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.send();
}
/**
* Audit the login event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param username Unique username of the user
* @param workstation The DNS address of the workstation the user has logged into
* @param date Date of login
*/
public static void auditLogin
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final String username,
final String workstation,
final Date date
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("userEvents", "login");
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("workstation", null, workstation, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.send();
}
/**
* Audit the logout event
* @param channel Identifies the channel to be used for message queuing
* @param tenantId Identifies the tenant that the user belongs to
* @param userId Identifies the user who triggered the event
* @param correlationId Identifies the same user action
* @param username Unique username of the user
* @param workstation The DNS address of the workstation from which the user logged out
* @param date Date of logout
*/
public static void auditLogout
(
final AuditChannel channel,
final String tenantId,
final String userId,
final String correlationId,
final String username,
final String workstation,
final Date date
)
throws IOException, AuditingException
{
final AuditEventBuilder auditEventBuilder = channel.createEventBuilder();
auditEventBuilder.setApplication(APPLICATION_IDENTIFIER);
auditEventBuilder.setTenant(tenantId);
auditEventBuilder.setUser(userId);
auditEventBuilder.setCorrelationId(correlationId);
auditEventBuilder.setEventType("userEvents", "logout");
auditEventBuilder.addEventParameter("username", null, username, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("workstation", null, workstation, AuditIndexingHint.KEYWORD);
auditEventBuilder.addEventParameter("date", null, date);
auditEventBuilder.send();
}
}