use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class WorkspaceConfiguratorFilterTest method testGettingHeaders.
@Test
public void testGettingHeaders() {
CloudbreakUser cbUser = createCbUserWithCrn();
when(authenticatedUserService.getCbUser(any(HttpServletRequest.class))).thenReturn(cbUser);
when(userService.getOrCreate(any())).thenReturn(new User());
when(workspaceService.getByName(anyString(), any())).thenReturn(Optional.of(createWorkspace()));
when(request.getHeaderNames()).thenReturn(Collections.enumeration(Set.of("header1", "header2")));
when(request.getHeaders("header1")).thenReturn(Collections.enumeration(Set.of("value1")));
when(request.getHeaders("header2")).thenReturn(Collections.enumeration(Set.of("value2", "value3")));
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
try {
underTest.doFilterInternal(request, response, filterChain);
} catch (Exception e) {
}
});
verify(workspaceService, times(1)).getByName(eq(Crn.fromString(cbUser.getUserCrn()).getAccountId()), any());
verify(workspaceService, times(0)).getByName(eq(cbUser.getTenant()), any());
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class WorkspaceConfiguratorFilterTest method filterWhenWorkspaceDoesNotExist.
@Test
public void filterWhenWorkspaceDoesNotExist() {
CloudbreakUser cbUser = createCbUserWithCrn();
when(authenticatedUserService.getCbUser(any(HttpServletRequest.class))).thenReturn(cbUser);
when(userService.getOrCreate(any())).thenReturn(new User());
when(workspaceService.getByName(anyString(), any())).thenReturn(Optional.empty());
assertThrows(IllegalStateException.class, () -> underTest.doFilterInternal(request, response, filterChain), "Tenant default workspace does not exist!");
verify(workspaceService, times(1)).getByName(eq(Crn.fromString(cbUser.getUserCrn()).getAccountId()), any());
verify(workspaceService, times(0)).getByName(eq(cbUser.getTenant()), any());
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method testCheckForOsUpgradeShouldThrowExceptionWhenTheClusterNameIsNotAvailable.
@Test
void testCheckForOsUpgradeShouldThrowExceptionWhenTheClusterNameIsNotAvailable() {
when(userService.getOrCreate(cloudbreakUser)).thenReturn(new User());
assertThrows(BadRequestException.class, () -> underTest.checkForOsUpgrade(NameOrCrn.ofCrn("crn"), cloudbreakUser, WORKSPACE_ID));
verify(userService).getOrCreate(cloudbreakUser);
verifyNoInteractions(upgradeService);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class StackOperations method post.
public StackV4Response post(Long workspaceId, CloudbreakUser cloudbreakUser, @Valid StackV4Request request, boolean distroxRequest) {
LOGGER.info("Post for Stack in workspace {}.", workspaceId);
User user = userService.getOrCreate(cloudbreakUser);
LOGGER.info("Cloudbreak user for the requested stack is {}.", cloudbreakUser);
Workspace workspace = workspaceService.get(workspaceId, user);
StackV4Response stackV4Response = stackCommonService.createInWorkspace(request, user, workspace, distroxRequest);
LOGGER.info("Adding environment name and credential to the response.");
environmentServiceDecorator.prepareEnvironmentAndCredentialName(stackV4Response);
LOGGER.info("Adding SDX CRN and name to the response.");
sdxServiceDecorator.prepareSdxAttributes(stackV4Response);
return stackV4Response;
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class LegacyStructuredEventFilter method sendStructuredEvent.
private void sendStructuredEvent(RestRequestDetails restRequest, RestResponseDetails restResponse, Map<String, String> restParams, Long requestTime, String responseBody) {
restResponse.setBody(responseBody);
RestCallDetails restCall = new RestCallDetails();
restCall.setRestRequest(restRequest);
restCall.setRestResponse(restResponse);
restCall.setDuration(System.currentTimeMillis() - requestTime);
CloudbreakUser cloudbreakUser = cloudbreakRestRequestThreadLocalService.getCloudbreakUser();
if (cloudbreakUser == null) {
String serviceId = authenticatedUserService.getServiceAccountId();
cloudbreakUser = new CloudbreakUser(serviceId, serviceId, serviceId, serviceId, serviceId);
}
Long workspaceId = cloudbreakRestRequestThreadLocalService.getRequestedWorkspaceId();
legacyStructuredEventClient.sendStructuredEvent(new StructuredRestCallEvent(createOperationDetails(restParams, requestTime, workspaceId, cloudbreakUser), restCall));
}
Aggregations