use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class WorkspaceConfiguratorFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
CloudbreakUser cloudbreakUser = authenticatedUserService.getCbUser(request);
try {
if (cloudbreakUser != null) {
if (ThreadBasedUserCrnProvider.getUserCrn() != null && !ThreadBasedUserCrnProvider.getUserCrn().equals(cloudbreakUser.getUserCrn())) {
LOGGER.debug("Before:There is a difference between:: Spring security context: {} and header-based-actor: '{}'", cloudbreakUser.getUserCrn(), ThreadBasedUserCrnProvider.getUserCrn());
logHeadersSafely(request);
}
User user = userService.getOrCreate(cloudbreakUser);
String accountId = Crn.fromString(cloudbreakUser.getUserCrn()).getAccountId();
// default workspaceName is always the accountId
Optional<Workspace> tenantDefaultWorkspace = workspaceService.getByName(accountId, user);
if (!tenantDefaultWorkspace.isPresent()) {
throw new IllegalStateException("Tenant default workspace does not exist!");
}
if (ThreadBasedUserCrnProvider.getUserCrn() != null && !ThreadBasedUserCrnProvider.getUserCrn().equals(user.getUserCrn())) {
LOGGER.debug("Before:There is a difference between:: CB user context: {} and header-based-actor: '{}'", user.getUserCrn(), ThreadBasedUserCrnProvider.getUserCrn());
}
Long workspaceId = tenantDefaultWorkspace.get().getId();
restRequestThreadLocalService.setRequestedWorkspaceId(workspaceId);
WorkspaceIdModifiedRequest modifiedRequest = new WorkspaceIdModifiedRequest(request, workspaceId);
LOGGER.debug("Before:CloudbreakRestRequestThreadLocalContext: {}", restRequestThreadLocalService.getRestThreadLocalContextAsString());
filterChain.doFilter(modifiedRequest, response);
LOGGER.debug("After:CloudbreakRestRequestThreadLocalContext: {}", restRequestThreadLocalService.getRestThreadLocalContextAsString());
} else {
filterChain.doFilter(request, response);
}
} finally {
restRequestThreadLocalService.removeRequestedWorkspaceId();
}
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class DefaultClusterTemplateCache method defaultClusterTemplatesByNames.
public List<ClusterTemplate> defaultClusterTemplatesByNames(Collection<String> templateNamesMissingFromDb, Set<Blueprint> blueprints) {
List<ClusterTemplate> defaultTemplates = new ArrayList<>();
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
boolean internalTenant = entitlementService.internalTenant(workspace.getTenant().getName());
defaultClusterTemplateRequests().forEach((key, value) -> {
if (templateNamesMissingFromDb.contains(key)) {
String defaultTemplateJson = new String(Base64.getDecoder().decode(value));
DefaultClusterTemplateV4Request defaultClusterTemplate = getDefaultClusterTemplate(defaultTemplateJson);
if (internalClusterTemplateValidator.shouldPopulate(defaultClusterTemplate, internalTenant)) {
ClusterTemplate clusterTemplate = defaultClusterTemplateV4RequestToClusterTemplateConverter.convert(defaultClusterTemplate);
clusterTemplate.setWorkspace(workspace);
Optional<Blueprint> blueprint = blueprints.stream().filter(e -> e.getName().equals(defaultClusterTemplate.getDistroXTemplate().getCluster().getBlueprintName())).findFirst();
if (blueprint.isPresent()) {
clusterTemplate.setClouderaRuntimeVersion(blueprint.get().getStackVersion());
}
defaultTemplates.add(clusterTemplate);
}
}
});
return defaultTemplates;
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class NotificationController method executeAndNotify.
protected final void executeAndNotify(Consumer<CloudbreakUser> consumer, ResourceEvent resourceEvent) {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
consumer.accept(cloudbreakUser);
notify(resourceEvent);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class UtilV4Controller method postNotificationTest.
@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public ResourceEventResponse postNotificationTest() {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
notificationSender.sendTestNotification(cloudbreakUser.getUserId());
ResourceEventResponse response = new ResourceEventResponse();
response.setEvent(ResourceEvent.CREDENTIAL_CREATED);
return response;
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class DistroXServiceTest method testWhenEnvExistsAndItIsAvailable.
@Test
@DisplayName("When the environment that has the given name is exist and also in the state AVAILABLE then no exception should come")
void testWhenEnvExistsAndItIsAvailable() throws IllegalAccessException {
String envName = "someAwesomeEnvironment";
DistroXV1Request r = new DistroXV1Request();
r.setEnvironmentName(envName);
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setEnvironmentStatus(AVAILABLE);
envResponse.setCrn("crn");
DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
freeipa.setStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status.AVAILABLE);
when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
when(environmentClientService.getByName(envName)).thenReturn(envResponse);
StackV4Request converted = new StackV4Request();
CloudbreakUser cloudbreakUser = mock(CloudbreakUser.class);
when(stackRequestConverter.convert(r)).thenReturn(converted);
when(platformAwareSdxConnector.listSdxCrns(any(), any())).thenReturn(Set.of(DATALAKE_CRN));
when(restRequestThreadLocalService.getCloudbreakUser()).thenReturn(cloudbreakUser);
underTest.post(r);
verify(environmentClientService, calledOnce()).getByName(any());
verify(environmentClientService, calledOnce()).getByName(envName);
verify(stackOperations, calledOnce()).post(any(), any(), any(), anyBoolean());
verify(stackOperations, calledOnce()).post(eq(USER_ID), eq(cloudbreakUser), eq(converted), eq(true));
verify(workspaceService, calledOnce()).getForCurrentUser();
verify(stackRequestConverter, calledOnce()).convert(any(DistroXV1Request.class));
verify(stackRequestConverter, calledOnce()).convert(r);
}
Aggregations