use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class AuditFilterTest method testDoFilterInternalWhenAuditAndMutating.
@Test
public void testDoFilterInternalWhenAuditAndMutating() throws Exception {
when(authenticatedUserService.getCbUser(any(HttpServletRequest.class))).thenReturn(new CloudbreakUser("userid", "usercrn", "username", "useremail", "usertenant"));
when(request.getRequestURI()).thenReturn("/as/api/v1/distrox/crn/testcrn/autoscale_config");
when(request.getMethod()).thenReturn("POST");
when(request.getHeader("x-real-ip")).thenReturn("127.0.0.1");
when(request.getHeader("user-agent")).thenReturn("test-user-agent");
underTest.doFilterInternal(request, response, filterChain);
verify(auditService, times(1)).auditRestApi(eq(Map.of("uri", "/as/api/v1/distrox/crn/testcrn/autoscale_config")), eq(true), eq("test-user-agent"), eq("usercrn"), eq("usertenant"), eq("127.0.0.1"));
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class CredentialToExtendedCloudCredentialConverter method convert.
public ExtendedCloudCredential convert(Credential credential, Optional<User> optionalUser) {
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
User user = null;
if (optionalUser.isPresent()) {
user = optionalUser.orElse(null);
} else {
CloudbreakUser cloudbreakUser = legacyRestRequestThreadLocalService.getCloudbreakUser();
if (cloudbreakUser != null) {
user = userService.getOrCreate(cloudbreakUser);
} else {
Crn crn = Crn.fromString(credential.getCreator());
user = userService.getByUserIdAndTenant(crn.getUserId(), crn.getAccountId()).orElse(null);
}
}
if (user == null) {
throw new IllegalStateException("The user is not available for the credential: " + credential.getCreator());
}
return new ExtendedCloudCredential(cloudCredential, credential.cloudPlatform(), credential.getDescription(), user.getUserCrn(), user.getTenant().getName(), entitlementService.getEntitlements(credential.getAccount()));
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class UserProfileService method getOrCreateForLoggedInUser.
public UserProfile getOrCreateForLoggedInUser() {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
return getOrCreate(user);
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class UserService method createUser.
private User createUser(CloudbreakUser cloudbreakUser) {
try {
return transactionService.requiresNew(() -> {
User user = new User();
user.setUserId(cloudbreakUser.getUserId());
user.setUserName(cloudbreakUser.getUsername());
user.setUserCrn(cloudbreakUser.getUserCrn());
Tenant tenant = tenantService.findByName(cloudbreakUser.getTenant()).orElse(null);
if (tenant == null) {
tenant = new Tenant();
tenant.setName(cloudbreakUser.getTenant());
tenant = tenantService.save(tenant);
createTenantDefaultWorkspace(tenant);
}
user.setTenant(tenant);
return userRepository.save(user);
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.
the class UserService method evictCurrentUserDetailsForLoggedInUser.
public String evictCurrentUserDetailsForLoggedInUser() {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
cachedUserService.evictByIdentityUser(cloudbreakUser);
return cloudbreakUser.getUsername();
}
Aggregations