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

Merge branch 'integration-master' of...

Merge branch 'integration-master' of git.epam.com:go3-nrg/platform/System/partition into integration-master

# Conflicts:
#	partition-core/src/main/java/org/opengroup/osdu/partition/logging/AuditLogger.java
#	partition-core/src/test/java/org/opengroup/osdu/partition/logging/AuditLoggerTest.java
#	provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationService.java
parents d79150d7 7fe66c11
/*
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 com.google.common.base.Strings;
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 (this.events == null) {
this.events = new AuditEvents("partitionAccountUser");
if (Strings.isNullOrEmpty(this.headers.getUserEmail())) {
IEntitlementsService service = this.factory.create(headers);
try {
Groups groups = service.getGroups();
this.events = new AuditEvents(groups.getMemberEmail());
} catch (EntitlementsException e) {
throw new AppException(HttpStatus.UNAUTHORIZED.value(), "Authentication Failure",
e.getMessage(), e);
}
} else {
this.events = new AuditEvents(this.headers.getUserEmail());
}
}
return this.events;
}
......
......@@ -3,6 +3,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;
......@@ -12,7 +13,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;
@RunWith(MockitoJUnitRunner.class)
public class AuditLoggerTest {
......@@ -20,6 +23,12 @@ public class AuditLoggerTest {
@Mock
private JaxRsDpsLog log;
@Mock
private IEntitlementsFactory factory;
@Mock
private DpsHeaders headers;
@InjectMocks
private AuditLogger sut;
......@@ -27,6 +36,7 @@ public class AuditLoggerTest {
@Before
public void setup() {
when(this.headers.getUserEmail()).thenReturn("test_user@email.com");
resources = Collections.singletonList("resources");
}
......
......@@ -27,7 +27,13 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.3.25</version>
<version>0.6.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.qos.logback.contrib</groupId>
<artifactId>logback-json-classic</artifactId>
<version>0.1.5</version>
</dependency>
<!-- Third party Apache 2.0 license packages -->
......
......@@ -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) {
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="!local">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>yyyy-MM-dd HH:mm:ss.SSS</timestampFormat>
<timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
<appendLineSeparator>true</appendLineSeparator>
<jsonFormatter class="org.opengroup.osdu.core.gcp.logging.formatter.GoogleJsonFormatter">
<prettyPrint>false</prettyPrint>
</jsonFormatter>
</layout>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
......@@ -58,7 +58,6 @@ public abstract class TestUtils {
throws Exception {
Map<String, String> headers = getOsduTenantHeaders();
headers.put("user", "test_user@gmail.com");
return send(path, httpMethod, token, requestBody, query, headers, enforceHttp);
}
......
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