Search in sources :

Example 6 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class UmsAuthenticationServiceTest method testMachineUserCrn.

@Test
public void testMachineUserCrn() {
    String crn = "crn:cdp:iam:us-west-1:9d74eee4-1cad-45d7-b645-7ccf9edbb73d:machineUser:qaas/b8a64902-7765-4ddd-a4f3-df81ae585e10";
    UserManagementProto.MachineUser machineUser = UserManagementProto.MachineUser.newBuilder().setMachineUserId("machineUserId").setCrn(crn).build();
    when(grpcUmsClient.getMachineUserDetails(anyString(), anyString(), any(), any())).thenReturn(machineUser);
    CloudbreakUser cloudbreakUser = underTest.getCloudbreakUser(crn, "principal");
    assertEquals("machineUserId", cloudbreakUser.getUserId());
    assertEquals("principal", cloudbreakUser.getUsername());
    assertEquals(crn, cloudbreakUser.getUserCrn());
}
Also used : UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class UmsAuthenticationServiceTest method testUserCrn.

@Test
public void testUserCrn() {
    String crn = "crn:cdp:iam:us-west-1:9d74eee4-1cad-45d7-b645-7ccf9edbb73d:user:qaas/b8a64902-7765-4ddd-a4f3-df81ae585e10";
    UserManagementProto.User user = UserManagementProto.User.newBuilder().setUserId("userId").setEmail("e@mail.com").setCrn(crn).build();
    when(grpcUmsClient.getUserDetails(anyString(), any(), any())).thenReturn(user);
    CloudbreakUser cloudbreakUser = underTest.getCloudbreakUser(crn, null);
    assertEquals("userId", cloudbreakUser.getUserId());
    assertEquals("e@mail.com", cloudbreakUser.getUsername());
    assertEquals(crn, cloudbreakUser.getUserCrn());
}
Also used : UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class NotificationController method notify.

protected final void notify(ResourceEvent resourceEvent, boolean workspaceMessage, Collection<?> messageArgs) {
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    CloudbreakEventV4Response notification = new CloudbreakEventV4Response();
    notification.setEventTimestamp(new Date().getTime());
    notification.setUserId(userService.getOrCreate(cloudbreakUser).getUserId());
    notification.setEventType(resourceEvent.name());
    notification.setEventMessage(messagesService.getMessage(resourceEvent.getMessage(), messageArgs));
    notification.setTenantName(cloudbreakUser.getTenant());
    if (workspaceMessage) {
        Long workspaceId = restRequestThreadLocalService.getRequestedWorkspaceId();
        notification.setWorkspaceId(workspaceId);
    }
    notificationSender.send(new Notification<>(notification));
}
Also used : CloudbreakEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Date(java.util.Date)

Example 9 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class StackCreatorService method determineImageCatalog.

private Future<StatedImage> determineImageCatalog(String stackName, String platformString, StackV4Request stackRequest, Blueprint blueprint, User user, Workspace workspace) {
    ClusterV4Request clusterRequest = stackRequest.getCluster();
    if (clusterRequest == null) {
        return null;
    }
    boolean shouldUseBaseCMImage = shouldUseBaseCMImage(clusterRequest, platformString);
    boolean baseImageEnabled = imageCatalogService.baseImageEnabled();
    Map<String, String> mdcContext = MDCBuilder.getMdcContextMap();
    CloudbreakUser cbUser = restRequestThreadLocalService.getCloudbreakUser();
    return executorService.submit(() -> {
        MDCBuilder.buildMdcContextFromMap(mdcContext);
        LOGGER.info("The stack with name {} has base images enabled: {} and should use base images: {}", stackName, baseImageEnabled, shouldUseBaseCMImage);
        StatedImage statedImage = ThreadBasedUserCrnProvider.doAs(user.getUserCrn(), () -> {
            try {
                restRequestThreadLocalService.setCloudbreakUser(cbUser);
                return imageService.determineImageFromCatalog(workspace.getId(), stackRequest.getImage(), platformString, stackRequest.getVariant(), blueprint, shouldUseBaseCMImage, baseImageEnabled, user, image -> true);
            } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) {
                throw new RuntimeException(e);
            }
        });
        MDCBuilder.cleanupMdc();
        return statedImage;
    });
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 10 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class WorkspaceConfiguratorFilterTest method filterWhenWorkspaceExists.

@Test
public void filterWhenWorkspaceExists() throws ServletException, IOException {
    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()));
    underTest.doFilterInternal(request, response, filterChain);
    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)

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