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());
}
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());
}
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));
}
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;
});
}
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());
}
Aggregations