use of com.sequenceiq.cloudbreak.auth.CrnUser in project cloudbreak by hortonworks.
the class InternalCrnModifier method createNewUser.
private void createNewUser(Crn newUserCrn) {
CrnUser newUser = RegionAwareInternalCrnGeneratorUtil.createInternalCrnUser(newUserCrn);
internalUserModifier.persistModifiedInternalUser(newUser);
}
use of com.sequenceiq.cloudbreak.auth.CrnUser in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverter method convert.
public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) {
Crn ownerCrn = Crn.safeFromString(ownerCrnString);
CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString);
DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn());
DBStack dbStack = new DBStack();
dbStack.setOwnerCrn(ownerCrn);
dbStack.setUserName(user.getEmail());
CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform());
dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName()));
dbStack.setEnvironmentId(source.getEnvironmentCrn());
setRegion(dbStack, environment);
if (source.getDatabaseServer() != null) {
dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, ownerCrn, environment.getSecurityAccess()));
}
Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
if (asMap != null) {
Map<String, String> parameter = new HashMap<>();
asMap.forEach((key, value) -> parameter.put(key, value.toString()));
dbStack.setParameters(parameter);
}
dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack));
Instant now = clock.getCurrentInstant();
dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli()));
dbStack.setResourceCrn(crnService.createCrn(dbStack).toString());
dbStack.setTags(getTags(dbStack, source, environment));
dbStack.setSslConfig(getSslConfig(source, dbStack));
return dbStack;
}
use of com.sequenceiq.cloudbreak.auth.CrnUser in project cloudbreak by hortonworks.
the class EnvironmentTagProviderTest method setUp.
@BeforeEach
void setUp() {
when(accountTagService.get(ACCOUNT_ID)).thenReturn(Set.of(new AccountTag()));
when(accountTagToAccountTagResponsesConverter.convert(any())).thenReturn(ACCOUNT_TAGS.get(0));
CrnUser crnUser = new CrnUser("userId", USER_CRN, USERNAME, "email", "tenant", "role");
when(crnUserDetailsService.loadUserByUsername(USER_CRN)).thenReturn(crnUser);
}
use of com.sequenceiq.cloudbreak.auth.CrnUser in project cloudbreak by hortonworks.
the class UserServiceTest method testPersistModifiedInternalUser.
@Test
public void testPersistModifiedInternalUser() throws TransactionExecutionException {
doAnswer(invocation -> ((Supplier<?>) invocation.getArgument(0)).get()).when(transactionService).requiresNew(any());
when(userRepository.findByTenantNameAndUserId(anyString(), anyString())).thenReturn(Optional.empty());
when(tenantService.findByName(anyString())).thenReturn(Optional.empty());
when(tenantService.save(any())).thenReturn(createTenant());
when(workspaceService.create(any())).thenReturn(createWorkspace());
when(userRepository.save(any())).thenReturn(createUser());
doNothing().when(restRequestThreadLocalService).setCloudbreakUser(any());
CrnUser cbUser = createCrnUser();
underTest.persistModifiedInternalUser(cbUser);
assertNotNull(cbUser);
verify(cachedUserService, times(1)).getUser(any(), any(), any());
verify(workspaceService, times(1)).create(any());
verify(tenantService, times(1)).save(any());
verify(restRequestThreadLocalService, times(1)).setCloudbreakUser(eq(cbUser));
}
use of com.sequenceiq.cloudbreak.auth.CrnUser in project cloudbreak by hortonworks.
the class InternalCrnModifierTest method testModificationIfUserCrnIsInternal.
@Test
public void testModificationIfUserCrnIsInternal() {
when(reflectionUtil.getParameter(any(), any(), eq(AccountId.class))).thenReturn(Optional.empty());
when(reflectionUtil.getParameter(any(), any(), eq(TenantAwareParam.class))).thenReturn(Optional.of(STACK_CRN));
doNothing().when(internalUserModifier).persistModifiedInternalUser(any());
AtomicBoolean assertationHappened = new AtomicBoolean(false);
when(reflectionUtil.proceed(any())).thenAnswer(invocation -> {
assertEquals(EXPECTED_INTERNAL_CRN, ThreadBasedUserCrnProvider.getUserCrn());
assertationHappened.set(true);
return null;
});
ThreadBasedUserCrnProvider.doAs(INTERNAL_CRN, () -> {
underTest.changeInternalCrn(proceedingJoinPoint);
});
ArgumentCaptor<CrnUser> newUserCaptor = ArgumentCaptor.forClass(CrnUser.class);
verify(internalUserModifier, times(1)).persistModifiedInternalUser(newUserCaptor.capture());
assertEquals("1234", newUserCaptor.getValue().getTenant());
verify(reflectionUtil, times(1)).proceed(any());
assertTrue(assertationHappened.get());
}
Aggregations