Search in sources :

Example 11 with CloudbreakUser

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 12 with CloudbreakUser

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Test(org.junit.jupiter.api.Test)

Example 13 with CloudbreakUser

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);
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Test(org.junit.jupiter.api.Test)

Example 14 with CloudbreakUser

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;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Example 15 with CloudbreakUser

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));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Aggregations

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)47 User (com.sequenceiq.cloudbreak.workspace.model.User)24 Test (org.junit.jupiter.api.Test)10 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)8 Optional (java.util.Optional)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Collection (java.util.Collection)3 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2