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

Merge branch 'integration-master' into 'master'

# Conflicts:
#   provider/partition-gcp/pom.xml
parents adf10f2c de8138b9
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
package org.opengroup.osdu.partition.logging;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
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.entitlements.EntitlementsException;
import org.opengroup.osdu.core.common.model.entitlements.Groups;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -31,11 +22,27 @@ import org.springframework.web.context.annotation.RequestScope;
public class AuditLogger {
private final JaxRsDpsLog logger;
private final IEntitlementsFactory factory;
private final DpsHeaders headers;
private AuditEvents events = null;
private AuditEvents getAuditEvents() {
if ( == null) { = new AuditEvents("partitionAccountUser");
if (Strings.isNullOrEmpty(this.headers.getUserEmail())) {
IEntitlementsService service = this.factory.create(headers);
try {
Groups groups = service.getGroups(); = new AuditEvents(groups.getMemberEmail());
} catch (EntitlementsException e) {
throw new AppException(HttpStatus.UNAUTHORIZED.value(), "Authentication Failure",
e.getMessage(), e);
} else { = new AuditEvents(this.headers.getUserEmail());
......@@ -20,6 +20,7 @@ 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 static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
......@@ -29,7 +30,9 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
public class AuditLoggerTest {
......@@ -37,6 +40,12 @@ public class AuditLoggerTest {
private JaxRsDpsLog log;
private IEntitlementsFactory factory;
private DpsHeaders headers;
private AuditLogger sut;
......@@ -44,6 +53,7 @@ public class AuditLoggerTest {
public void setup() {
resources = Collections.singletonList("resources");
......@@ -45,9 +45,6 @@ public class AuthorizationService implements IAuthorizationService {
try {
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) {
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