Commit d79150d7 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge remote-tracking branch 'origin/master' into integration-master

# Conflicts:
#	partition-core/src/main/java/org/opengroup/osdu/partition/api/PartitionApi.java
#	partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditEvents.java
#	partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java
#	provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java
parents cec39278 49d8103a
......@@ -50,7 +50,7 @@ public class PartitionApi {
public ResponseEntity create(@PathVariable("partitionId") String partitionId, @RequestBody @Valid PartitionInfo partitionInfo) {
this.partitionService.createPartition(partitionId, partitionInfo);
URI partitionLocation = ServletUriComponentsBuilder.fromCurrentRequest().buildAndExpand().toUri();
this.auditLogger.createdPartitionSuccess(Collections.singletonList(partitionId));
this.auditLogger.createPartitionSuccess(Collections.singletonList(partitionId));
return ResponseEntity.created(partitionLocation).build();
}
......@@ -59,7 +59,7 @@ public class PartitionApi {
@ResponseStatus(HttpStatus.NO_CONTENT)
public void patch(@PathVariable("partitionId") String partitionId, @RequestBody @Valid PartitionInfo partitionInfo) {
this.partitionService.updatePartition(partitionId, partitionInfo);
this.auditLogger.updatedPartitionSecretSuccess(Collections.singletonList(partitionId));
this.auditLogger.updatePartitionSecretSuccess(Collections.singletonList(partitionId));
}
@GetMapping("/{partitionId}")
......@@ -74,7 +74,7 @@ public class PartitionApi {
@PreAuthorize("@authorizationFilter.hasPermissions()")
public ResponseEntity delete(@PathVariable("partitionId") String partitionId) {
this.partitionService.deletePartition(partitionId);
this.auditLogger.deletedPartitionSuccess(Collections.singletonList(partitionId));
this.auditLogger.deletePartitionSuccess(Collections.singletonList(partitionId));
return ResponseEntity.noContent().build();
}
......
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 EPAM Systems, Inc
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.partition.logging;
import static java.lang.String.format;
......@@ -12,22 +29,22 @@ import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
public class AuditEvents {
private static final String CREATE_PARTITION_ACTION_ID = "PT001";
private static final String CREATE_PARTITION_MESSAGE = "Partition creation";
private static final String CREATE_PARTITION_MESSAGE = "Create partition";
private static final String READ_PARTITION_ACTION_ID = "PT002";
private static final String READ_PARTITION_MESSAGE = "Partition read";
private static final String READ_PARTITION_MESSAGE = "Read partition";
private static final String DELETE_PARTITION_ACTION_ID = "PT003";
private static final String DELETE_PARTITION_MESSAGE = "Partition removal";
private static final String DELETE_PARTITION_MESSAGE = "Delete partition";
private static final String READ_SERVICE_LIVENESS_ACTION_ID = "PT004";
private static final String READ_SERVICE_LIVENESS_MESSAGE = "Service run";
private static final String UPDATE_PARTITION_ACTION_ID = "PT005";
private static final String UPDATE_PARTITION_MESSAGE = "Partition updating";
private static final String UPDATE_PARTITION_MESSAGE = "Update partition";
private static final String READ_LIST_PARTITION_ACTION_ID = "PT006";
private static final String READ_LIST_PARTITION_MESSAGE = "Partition list read";
private static final String READ_LIST_PARTITION_MESSAGE = "Read partition list";
private final String user;
......
/*
Copyright 2002-2021 Google LLC
Copyright 2002-2021 EPAM Systems, Inc
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.partition.logging;
import java.util.List;
......@@ -5,7 +22,6 @@ import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.logging.audit.AuditPayload;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -15,23 +31,20 @@ import org.springframework.web.context.annotation.RequestScope;
public class AuditLogger {
private final JaxRsDpsLog logger;
private final DpsHeaders headers;
private AuditEvents events = null;
private AuditEvents getAuditEvents() {
if (this.events == null) {
this.events = new AuditEvents(this.headers.getUserEmail());
this.events = new AuditEvents("partitionAccountUser");
}
return this.events;
}
public void createdPartitionSuccess(List<String> resources) {
public void createPartitionSuccess(List<String> resources) {
writeLog(getAuditEvents().getCreatePartitionEvent(AuditStatus.SUCCESS, resources));
}
public void createdPartitionFailure(List<String> resources) {
public void createPartitionFailure(List<String> resources) {
writeLog(getAuditEvents().getCreatePartitionEvent(AuditStatus.FAILURE, resources));
}
......@@ -43,11 +56,11 @@ public class AuditLogger {
writeLog(getAuditEvents().getReadPartitionEvent(AuditStatus.FAILURE, resources));
}
public void deletedPartitionSuccess(List<String> resources) {
public void deletePartitionSuccess(List<String> resources) {
writeLog(getAuditEvents().getDeletePartitionEvent(AuditStatus.SUCCESS, resources));
}
public void deletedPartitionFailure(List<String> resources) {
public void deletePartitionFailure(List<String> resources) {
writeLog(getAuditEvents().getDeletePartitionEvent(AuditStatus.FAILURE, resources));
}
......@@ -59,11 +72,11 @@ public class AuditLogger {
writeLog(getAuditEvents().getReadServiceLivenessEvent(AuditStatus.FAILURE, resources));
}
public void updatedPartitionSecretSuccess(List<String> resources) {
public void updatePartitionSecretSuccess(List<String> resources) {
writeLog(getAuditEvents().getUpdatePartitionSecretEvent(AuditStatus.SUCCESS, resources));
}
public void updatedPartitionSecretFailure(List<String> resources) {
public void updatePartitionSecretFailure(List<String> resources) {
writeLog(getAuditEvents().getUpdatePartitionSecretEvent(AuditStatus.FAILURE, resources));
}
......
package org.opengroup.osdu.partition.logging;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
@RunWith(MockitoJUnitRunner.class)
public class AuditLoggerTest {
@Mock
private JaxRsDpsLog log;
@InjectMocks
private AuditLogger sut;
private List<String> resources;
@Before
public void setup() {
resources = Collections.singletonList("resources");
}
@Test
public void should_writeCreatePartitionSuccessEvent() {
this.sut.createPartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeCreatePartitionFailureEvent() {
this.sut.createPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadPartitionSuccessEvent() {
this.sut.readPartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadPartitionFailureEvent() {
this.sut.readPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeDeletePartitionSuccessEvent() {
this.sut.deletePartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeDeletePartitionFailureEvent() {
this.sut.deletePartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadServiceLivenessSuccessEvent() {
this.sut.readServiceLivenessSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadServiceLivenessFailureEvent() {
this.sut.readServiceLivenessFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeUpdatePartitionSecretSuccessEvent() {
this.sut.updatePartitionSecretSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeUpdatePartitionSecretFailureEvent() {
this.sut.updatePartitionSecretFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadListPartitionSuccessEvent() {
this.sut.readListPartitionSuccess(this.resources);
verify(this.log, times(1)).audit(any());
}
@Test
public void should_writeReadListPartitionFailureEvent() {
this.sut.readListPartitionFailure(this.resources);
verify(this.log, times(1)).audit(any());
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>partition</artifactId>
<version>1.0.0</version>
<version>0.6.0-SNAPSHOT</version>
<description>Partition Service</description>
<properties>
......
......@@ -17,8 +17,10 @@
package org.opengroup.osdu.partition.provider.gcp.security;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.core.common.model.entitlements.AuthorizationResponse;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.partition.provider.interfaces.IAuthorizationService;
......@@ -41,7 +43,11 @@ public class AuthorizationService implements IAuthorizationService {
@Override
public boolean isDomainAdminServiceAccount() {
try {
authorizationServiceImpl.authorizeAny(headers, PARTITION_ADMIN_ROLE);
AuthorizationResponse authorizationResponse = authorizationServiceImpl
.authorizeAny(headers, PARTITION_ADMIN_ROLE);
if (Objects.nonNull(authorizationResponse)) {
headers.put("user", authorizationResponse.getUser());
}
} catch (AppException e) {
throw e;
} catch (Exception e) {
......
......@@ -53,7 +53,7 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public PartitionInfo createPartition(String partitionId, PartitionInfo partitionInfo) {
if (this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) {
this.auditLogger.createdPartitionFailure(Collections.singletonList(partitionId));
this.auditLogger.createPartitionFailure(Collections.singletonList(partitionId));
throw new AppException(HttpStatus.SC_CONFLICT, UNKNOWN_ERROR_REASON,
"Partition already exists.");
}
......@@ -86,13 +86,13 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public PartitionInfo updatePartition(String partitionId, PartitionInfo partitionInfo) {
if (partitionInfo.getProperties().containsKey("id")) {
this.auditLogger.updatedPartitionSecretFailure(Collections.singletonList(partitionId));
this.auditLogger.updatePartitionSecretFailure(Collections.singletonList(partitionId));
throw new AppException(HttpStatus.SC_BAD_REQUEST, "can not update id",
"the field id can not be updated");
}
if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) {
this.auditLogger.updatedPartitionSecretFailure(Collections.singletonList(partitionId));
this.auditLogger.updatePartitionSecretFailure(Collections.singletonList(partitionId));
throw new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON,
"An attempt to update not existing partition.");
}
......@@ -161,7 +161,7 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public boolean deletePartition(String partitionId) {
if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) {
this.auditLogger.deletedPartitionFailure(Collections.singletonList(partitionId));
this.auditLogger.deletePartitionFailure(Collections.singletonList(partitionId));
throw new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON,
"An attempt to delete not existing partition.");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment