Skip to content
Snippets Groups Projects
Commit c87c5a09 authored by Stephen Henderson's avatar Stephen Henderson
Browse files

cont'd moving Audit* to final locations

parent 963565f0
No related branches found
No related tags found
1 merge request!6Trusted ibm
Showing
with 326 additions and 7 deletions
......@@ -15,7 +15,7 @@
package org.opengroup.osdu.indexer.api;
import org.opengroup.osdu.core.common.model.coreis.SearchServiceRole;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest;
import org.opengroup.osdu.indexer.service.ReindexService;
import org.springframework.http.ResponseEntity;
......
// Copyright 2017-2019, Schlumberger
//
// 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 org.opengroup.osdu.indexer.logging;
import com.google.common.base.Strings;
import org.opengroup.osdu.core.common.service.logging.audit.AuditAction;
import org.opengroup.osdu.core.common.service.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.service.logging.audit.AuditStatus;
import java.util.List;
public class AuditEvents {
private static final String INDEX_CREATE_RECORD_ACTION_ID = "IN001";
private static final String INDEX_CREATE_RECORDS_SUCCESS = "Successfully created record in index";
private static final String INDEX_CREATE_RECORDS_FAILURE = "Failed creating record in index";
private static final String INDEX_UPDATE_RECORD_ACTION_ID = "IN002";
private static final String INDEX_UPDATE_RECORDS_SUCCESS = "Successfully updated record in index";
private static final String INDEX_UPDATE_RECORDS_FAILURE = "Failed updating record in index";
private static final String INDEX_DELETE_RECORD_ACTION_ID = "IN003";
private static final String INDEX_DELETE_RECORDS_SUCCESS = "Successfully deleted record in index";
private static final String INDEX_DELETE_RECORDS_FAILURE = "Failed deleting record in index";
private static final String INDEX_PURGE_RECORD_ACTION_ID = "IN004";
private static final String REINDEX_KIND_ACTION_ID = "IN007";
private static final String REINDEX_KIND_OPERATION = "Reindex kind";
private static final String COPY_INDEX_ACTION_ID = "IN008";
private static final String COPY_INDEX_OPERATION = "Copy index";
private static final String GET_TASK_STATUS_ACTION_ID = "IN009";
private static final String GET_TASK_STATUS_OPERATION = "Get task status";
private static final String RUN_JOB_ACTION_ID = "IN010";
private static final String RUN_JOB_MESSAGE_SUCCESS = "Index clean-up status job run success";
private static final String INDEX_MAPPING_UPDATE_ACTION_ID = "IN0011";
private static final String INDEX_MAPPING_UPDATE_SUCCESS = "Successfully updated index mapping";
private static final String INDEX_MAPPING_UPDATE_FAILURE = "Failed updating index mapping";
private final String user;
public AuditEvents(String user) {
if (Strings.isNullOrEmpty(user)) {
throw new IllegalArgumentException("User not provided for audit events.");
}
this.user = user;
}
public AuditPayload getIndexCreateRecordSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_CREATE_RECORD_ACTION_ID)
.message(INDEX_CREATE_RECORDS_SUCCESS)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexCreateRecordFailEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_CREATE_RECORD_ACTION_ID)
.message(INDEX_CREATE_RECORDS_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexUpdateRecordSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.UPDATE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_UPDATE_RECORD_ACTION_ID)
.message(INDEX_UPDATE_RECORDS_SUCCESS)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexUpdateRecordFailEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.UPDATE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_UPDATE_RECORD_ACTION_ID)
.message(INDEX_UPDATE_RECORDS_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexDeleteRecordSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_DELETE_RECORD_ACTION_ID)
.message(INDEX_DELETE_RECORDS_SUCCESS)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexDeleteRecordFailEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_DELETE_RECORD_ACTION_ID)
.message(INDEX_DELETE_RECORDS_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexPurgeRecordSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_PURGE_RECORD_ACTION_ID)
.message(INDEX_DELETE_RECORDS_SUCCESS)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexPurgeRecordFailEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_PURGE_RECORD_ACTION_ID)
.message(INDEX_DELETE_RECORDS_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getReindexEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.SUCCESS)
.actionId(REINDEX_KIND_ACTION_ID)
.message(REINDEX_KIND_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getCopyIndexEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.SUCCESS)
.actionId(COPY_INDEX_ACTION_ID)
.message(COPY_INDEX_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getTaskStatusEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.READ)
.status(AuditStatus.SUCCESS)
.actionId(GET_TASK_STATUS_ACTION_ID)
.message(GET_TASK_STATUS_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexCleanUpJobRunEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.JOB_RUN)
.status(AuditStatus.SUCCESS)
.user(this.user)
.actionId(RUN_JOB_ACTION_ID)
.message(RUN_JOB_MESSAGE_SUCCESS)
.resources(resources)
.build();
}
public AuditPayload getIndexMappingUpdateEvent(List<String> resources, boolean isSuccess) {
if (isSuccess) {
return AuditPayload.builder()
.action(AuditAction.UPDATE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_MAPPING_UPDATE_ACTION_ID)
.message(INDEX_MAPPING_UPDATE_SUCCESS)
.resources(resources)
.user(this.user)
.build();
} else {
return AuditPayload.builder()
.action(AuditAction.UPDATE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_MAPPING_UPDATE_ACTION_ID)
.message(INDEX_MAPPING_UPDATE_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
}
}
\ No newline at end of file
// Copyright 2017-2019, Schlumberger
//
// 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 org.opengroup.osdu.indexer.logging;
import org.opengroup.osdu.core.common.service.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.service.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import javax.inject.Inject;
import java.util.List;
@Component
@RequestScope
public class AuditLogger {
@Inject
private JaxRsDpsLog logger;
@Inject
private IHeadersInfo headers;
private AuditEvents events = null;
private AuditEvents getAuditEvents() {
if (this.events == null) {
this.events = new AuditEvents(this.headers.getUser());
}
return this.events;
}
public void indexCreateRecordSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexCreateRecordSuccessEvent(resources));
}
public void indexCreateRecordFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexCreateRecordFailEvent(resources));
}
public void indexUpdateRecordSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexUpdateRecordSuccessEvent(resources));
}
public void indexUpdateRecordFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexUpdateRecordFailEvent(resources));
}
public void indexDeleteRecordSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexDeleteRecordSuccessEvent(resources));
}
public void indexDeleteRecordFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexDeleteRecordFailEvent(resources));
}
public void indexPurgeRecordSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexPurgeRecordSuccessEvent(resources));
}
public void indexPurgeRecordFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexPurgeRecordFailEvent(resources));
}
public void getReindex(List<String> resources) {
this.writeLog(this.getAuditEvents().getReindexEvent(resources));
}
public void copyIndex(List<String> resources) {
this.writeLog(this.getAuditEvents().getCopyIndexEvent(resources));
}
public void getTaskStatus(List<String> resources) {
this.writeLog(this.getAuditEvents().getTaskStatusEvent(resources));
}
public void getIndexCleanUpJobRun(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexCleanUpJobRunEvent(resources));
}
public void indexMappingUpdateSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexMappingUpdateEvent(resources,true));
}
public void indexMappingUpdateFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexMappingUpdateEvent(resources,false));
}
private void writeLog(AuditPayload log) {
this.logger.audit(log);
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ import org.opengroup.osdu.core.common.model.core.DpsHeaders;
import org.opengroup.osdu.core.common.model.core.TenantInfo;
import org.opengroup.osdu.core.common.model.AppException;
import org.opengroup.osdu.core.common.service.coreis.*;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo;
import org.opengroup.osdu.is.core.service.ElasticSettingService;
import org.opengroup.osdu.is.core.util.ElasticClientHandler;
......
......@@ -37,6 +37,7 @@ import org.opengroup.osdu.core.common.model.indexer.*;
import org.opengroup.osdu.core.common.model.storage.ConversionStatus;
import org.opengroup.osdu.core.common.service.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.spi.indexer.IPublisher;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder;
import org.opengroup.osdu.core.common.model.coreis.RequestStatus;
import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages;
......
......@@ -20,7 +20,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.AppException;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest;
import org.opengroup.osdu.indexer.service.ReindexService;
......
......@@ -18,7 +18,6 @@ import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.service.logging.audit.AuditAction;
import org.opengroup.osdu.core.common.model.indexer.AuditEvents;
import org.opengroup.osdu.core.common.service.logging.audit.AuditStatus;
import org.springframework.test.context.junit4.SpringRunner;
......
......@@ -21,7 +21,6 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.core.common.service.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.service.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo;
......
......@@ -31,7 +31,7 @@ import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.core.DpsHeaders;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexCopyServiceImpl;
import org.opengroup.osdu.indexer.service.IndexerMappingService;
import org.opengroup.osdu.core.common.model.core.ClusterSettings;
......
......@@ -34,7 +34,7 @@ import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.core.ClusterSettings;
import org.opengroup.osdu.core.common.model.core.DpsHeaders;
import org.opengroup.osdu.core.common.model.AppException;
import org.opengroup.osdu.core.common.model.indexer.AuditLogger;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo;
import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo;
import org.opengroup.osdu.is.core.service.ElasticSettingService;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment