Search in sources :

Example 1 with CrnUser

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);
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser)

Example 2 with CrnUser

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;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) HashMap(java.util.HashMap) Instant(java.time.Instant) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 3 with CrnUser

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);
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with 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));
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) Test(org.junit.Test)

Example 5 with CrnUser

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) Test(org.junit.jupiter.api.Test)

Aggregations

CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)5 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 AccountTag (com.sequenceiq.environment.tags.domain.AccountTag)1 DetailedDBStackStatus (com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus)1 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1 DBStackStatus (com.sequenceiq.redbeams.domain.stack.DBStackStatus)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1