Commit 4a8facd4 authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Code formatting

Using isDomainAdminServiceAccount instead of isRootUser
parent 96695317
package org.opengroup.osdu.workflow.aws.service;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.springframework.stereotype.Component;
@Component
public class RootAuthorizationServiceImpl implements IRootAuthorizationService {
public class AdminAuthorizationServiceImpl implements IAdminAuthorizationService {
@Override
public boolean isRootUser() {
public boolean isDomainAdminServiceAccount() {
return false;
}
}
......@@ -2,7 +2,7 @@ package org.opengroup.osdu.workflow.provider.azure.service;
import com.microsoft.azure.spring.autoconfigure.aad.UserPrincipal;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
......@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class RootAuthorizationServiceImpl implements IRootAuthorizationService {
public class AdminAuthorizationServiceImpl implements IAdminAuthorizationService {
enum UserType {
REGULAR_USER,
GUEST_USER,
......@@ -18,7 +18,7 @@ public class RootAuthorizationServiceImpl implements IRootAuthorizationService {
}
@Override
public boolean isRootUser() {
public boolean isDomainAdminServiceAccount() {
final Object principal = getUserPrincipal();
if (!(principal instanceof UserPrincipal)) {
......
package org.opengroup.osdu.workflow.provider.gcp.service;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.springframework.stereotype.Service;
@Service
public class RootAuthorizationServiceImpl implements IRootAuthorizationService {
public class AdminAuthorizationServiceImpl implements IAdminAuthorizationService {
@Override
public boolean isRootUser() {
public boolean isDomainAdminServiceAccount() {
return false;
}
}
package org.opengroup.osdu.workflow.provider.ibm.service;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.springframework.stereotype.Component;
@Component
public class RootAuthorizationServiceImpl implements IRootAuthorizationService {
public class AdminAuthorizationServiceImpl implements IAdminAuthorizationService {
@Override
public boolean isRootUser() {
public boolean isDomainAdminServiceAccount() {
return false;
}
}
package org.opengroup.osdu.workflow.provider.interfaces;
public interface IRootAuthorizationService {
boolean isRootUser();
public interface IAdminAuthorizationService {
boolean isDomainAdminServiceAccount();
}
......@@ -24,7 +24,7 @@ import org.opengroup.osdu.core.common.exception.UnauthorizedException;
import org.opengroup.osdu.core.common.model.entitlements.AuthorizationResponse;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
......@@ -38,7 +38,7 @@ public class AuthorizationFilter {
final DpsHeaders headers;
final IRootAuthorizationService rootAuthorizationService;
final IAdminAuthorizationService adminAuthorizationService;
/**
* Check the access permission for provided Authorization header and the required roles.
......@@ -63,7 +63,7 @@ public class AuthorizationFilter {
throw new BadRequestException("data-partition-id header should not be passed");
}
headers.put(DpsHeaders.USER_EMAIL, "RootUser");
return rootAuthorizationService.isRootUser();
return adminAuthorizationService.isDomainAdminServiceAccount();
}
private void validateMandatoryHeaders() {
......
......@@ -14,7 +14,7 @@ import org.opengroup.osdu.workflow.exception.handler.ConflictApiError;
import org.opengroup.osdu.workflow.model.CreateWorkflowRequest;
import org.opengroup.osdu.workflow.model.WorkflowMetadata;
import org.opengroup.osdu.workflow.model.WorkflowRole;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowManagerService;
import org.opengroup.osdu.workflow.security.AuthorizationFilter;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -105,7 +105,7 @@ class WorkflowManagerMvcTest {
private IAuthorizationService authorizationService;
@MockBean
private IRootAuthorizationService rootAuthorizationService;
private IAdminAuthorizationService adminAuthorizationService;
@MockBean
private JaxRsDpsLog log;
......
......@@ -12,7 +12,7 @@ import org.opengroup.osdu.workflow.exception.handler.RestExceptionHandler;
import org.opengroup.osdu.workflow.model.UpdateWorkflowRunRequest;
import org.opengroup.osdu.workflow.model.WorkflowRole;
import org.opengroup.osdu.workflow.model.WorkflowRunResponse;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.opengroup.osdu.workflow.security.AuthorizationFilter;
import org.opengroup.osdu.workflow.model.TriggerWorkflowRequest;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowRunService;
......@@ -107,7 +107,7 @@ class WorkflowRunMvcTest {
@MockBean
private IAuthorizationService authorizationService;
@MockBean
private IRootAuthorizationService rootAuthorizationService;
private IAdminAuthorizationService adminAuthorizationService;
@MockBean
private RestExceptionHandler restExceptionHandler;
@MockBean
......
......@@ -13,7 +13,7 @@ import org.opengroup.osdu.workflow.exception.WorkflowNotFoundException;
import org.opengroup.osdu.workflow.exception.handler.ConflictApiError;
import org.opengroup.osdu.workflow.model.CreateWorkflowRequest;
import org.opengroup.osdu.workflow.model.WorkflowMetadata;
import org.opengroup.osdu.workflow.provider.interfaces.IRootAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IAdminAuthorizationService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowManagerService;
import org.opengroup.osdu.workflow.security.AuthorizationFilter;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -81,7 +81,7 @@ class WorkflowSystemManagerMvcTest {
private IAuthorizationService authorizationService;
@MockBean
private IRootAuthorizationService rootAuthorizationService;
private IAdminAuthorizationService adminAuthorizationService;
@MockBean
private JaxRsDpsLog log;
......@@ -98,7 +98,7 @@ class WorkflowSystemManagerMvcTest {
.readValue(WORKFLOW_REQUEST, CreateWorkflowRequest.class);
final WorkflowMetadata metadata = mapper.readValue(WORKFLOW_RESPONSE, WorkflowMetadata.class);
when(workflowManagerService.createSystemWorkflow(eq(request))).thenReturn(metadata);
when(rootAuthorizationService.isRootUser())
when(adminAuthorizationService.isDomainAdminServiceAccount())
.thenReturn(true);
when(dpsHeaders.getAuthorization()).thenReturn(TEST_AUTH);
when(dpsHeaders.getPartitionId()).thenReturn("");
......@@ -112,7 +112,7 @@ class WorkflowSystemManagerMvcTest {
.andExpect(status().isOk())
.andReturn();
verify(workflowManagerService).createSystemWorkflow(eq(request));
verify(rootAuthorizationService).isRootUser();
verify(adminAuthorizationService).isDomainAdminServiceAccount();
verify(dpsHeaders).getAuthorization();
verify(dpsHeaders).getPartitionId();
final WorkflowMetadata responseMetadata =
......@@ -125,7 +125,7 @@ class WorkflowSystemManagerMvcTest {
final CreateWorkflowRequest request = mapper.readValue(WORKFLOW_REQUEST, CreateWorkflowRequest.class);
when(workflowManagerService.createSystemWorkflow(eq(request)))
.thenThrow(new ResourceConflictException(EXISTING_WORKFLOW_ID, "conflict"));
when(rootAuthorizationService.isRootUser())
when(adminAuthorizationService.isDomainAdminServiceAccount())
.thenReturn(true);
when(dpsHeaders.getAuthorization()).thenReturn(TEST_AUTH);
when(dpsHeaders.getPartitionId()).thenReturn("");
......@@ -139,7 +139,7 @@ class WorkflowSystemManagerMvcTest {
.andExpect(status().isConflict())
.andReturn();
verify(workflowManagerService).createSystemWorkflow(eq(request));
when(rootAuthorizationService.isRootUser())
when(adminAuthorizationService.isDomainAdminServiceAccount())
.thenReturn(true);
verify(dpsHeaders).getAuthorization();
verify(dpsHeaders).getPartitionId();
......@@ -151,7 +151,7 @@ class WorkflowSystemManagerMvcTest {
@Test
void testDeleteSystemApiWithSuccess() throws Exception {
doNothing().when(workflowManagerService).deleteSystemWorkflow(eq(WORKFLOW_NAME));
when(rootAuthorizationService.isRootUser())
when(adminAuthorizationService.isDomainAdminServiceAccount())
.thenReturn(true);
when(dpsHeaders.getAuthorization()).thenReturn(TEST_AUTH);
when(dpsHeaders.getCorrelationId()).thenReturn(CORRELATION_ID);
......@@ -163,7 +163,7 @@ class WorkflowSystemManagerMvcTest {
.andExpect(status().is(204))
.andReturn();
verify(workflowManagerService).deleteSystemWorkflow(eq(WORKFLOW_NAME));
verify(rootAuthorizationService).isRootUser();
verify(adminAuthorizationService).isDomainAdminServiceAccount();
verify(dpsHeaders).getAuthorization();
}
......@@ -171,7 +171,7 @@ class WorkflowSystemManagerMvcTest {
void testDeleteSystemApiWithError() throws Exception {
doThrow(new WorkflowNotFoundException("not found")).when(workflowManagerService)
.deleteSystemWorkflow(eq(WORKFLOW_NAME));
when(rootAuthorizationService.isRootUser())
when(adminAuthorizationService.isDomainAdminServiceAccount())
.thenReturn(true);
when(dpsHeaders.getAuthorization()).thenReturn(TEST_AUTH);
when(dpsHeaders.getPartitionId()).thenReturn("");
......@@ -184,7 +184,7 @@ class WorkflowSystemManagerMvcTest {
.andExpect(status().isNotFound())
.andReturn();
verify(workflowManagerService).deleteSystemWorkflow(eq(WORKFLOW_NAME));
verify(rootAuthorizationService).isRootUser();
verify(adminAuthorizationService).isDomainAdminServiceAccount();
verify(dpsHeaders).getAuthorization();
verify(dpsHeaders).getPartitionId();
}
......
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