Search in sources :

Example 1 with IdentityUser

use of com.sequenceiq.cloudbreak.common.model.user.IdentityUser in project cloudbreak by hortonworks.

the class CachedUserDetailsService method createIdentityUser.

private IdentityUser createIdentityUser(List<IdentityUserRole> roles, String account, JsonNode userNode) {
    String userId = userNode.get("id").asText();
    String email = userNode.get("userName").asText();
    String givenName = getGivenName(userNode);
    String familyName = getFamilyName(userNode);
    String dateOfCreation = userNode.get("meta").get("created").asText();
    Date created = parseUserCreated(dateOfCreation);
    account = StringUtils.isEmpty(account) ? userId : account;
    return new IdentityUser(userId, email, account, roles, givenName, familyName, created);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Date(java.util.Date)

Example 2 with IdentityUser

use of com.sequenceiq.cloudbreak.common.model.user.IdentityUser in project cloudbreak by hortonworks.

the class AccountPreferencesValidatorTest method testValidateShouldThrowExceptionWhenTheUserDemoTimeExpired.

@Test
public void testValidateShouldThrowExceptionWhenTheUserDemoTimeExpired() throws AccountPreferencesValidationException {
    Calendar calendar = Calendar.getInstance();
    calendar.roll(Calendar.HOUR_OF_DAY, -1);
    when(preferences.getUserTimeToLive()).thenReturn(40000L);
    IdentityUser identityUser = Mockito.mock(IdentityUser.class);
    when(userDetailsService.getDetails(anyString(), any(UserFilterField.class))).thenReturn(identityUser);
    when(identityUser.getCreated()).thenReturn(calendar.getTime());
    thrown.expect(AccountPreferencesValidationException.class);
    thrown.expectMessage("The user demo time is expired!");
    underTest.validate(stack, EMPTY_STRING, EMPTY_STRING);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserFilterField(com.sequenceiq.cloudbreak.common.service.user.UserFilterField) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 3 with IdentityUser

use of com.sequenceiq.cloudbreak.common.model.user.IdentityUser in project cloudbreak by hortonworks.

the class CredentialServiceTest method testRetrieveAccountCredentialsWhenUserIsNotAdmin.

@Test
public void testRetrieveAccountCredentialsWhenUserIsNotAdmin() {
    IdentityUser user = mock(IdentityUser.class);
    Set<String> platforms = Sets.newHashSet("AWS");
    Credential credential = new Credential();
    credential.setCloudPlatform("AWS");
    when(user.getRoles()).thenReturn(Collections.singletonList(IdentityUserRole.fromString("USER")));
    when(user.getAccount()).thenReturn("account");
    when(user.getUserId()).thenReturn("userId");
    when(accountPreferencesService.enabledPlatforms()).thenReturn(platforms);
    when(credentialRepository.findPublicInAccountForUserFilterByPlatforms("userId", "account", platforms)).thenReturn(Sets.newHashSet(credential));
    Set<Credential> actual = credentialService.retrieveAccountCredentials(user);
    assertEquals("AWS", actual.stream().findFirst().get().cloudPlatform());
    verify(credentialRepository, times(1)).findPublicInAccountForUserFilterByPlatforms("userId", "account", platforms);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Credential(com.sequenceiq.cloudbreak.domain.Credential) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with IdentityUser

use of com.sequenceiq.cloudbreak.common.model.user.IdentityUser in project cloudbreak by hortonworks.

the class ClusterProxyDecoratorTest method setUp.

@Before
public void setUp() {
    when(mapper.mapRequestToEntity(any(ProxyConfigRequest.class), anyBoolean())).thenReturn(new ProxyConfig());
    when(service.create(any(IdentityUser.class), any(ProxyConfig.class))).thenReturn(new ProxyConfig());
    when(service.getPublicProxyConfig(anyString(), eq(identityUser))).thenReturn(new ProxyConfig());
    cluster = new Cluster();
    stack.setPublicInAccount(true);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ProxyConfigRequest(com.sequenceiq.cloudbreak.api.model.proxy.ProxyConfigRequest) ProxyConfig(com.sequenceiq.cloudbreak.domain.ProxyConfig) Before(org.junit.Before)

Example 5 with IdentityUser

use of com.sequenceiq.cloudbreak.common.model.user.IdentityUser in project cloudbreak by hortonworks.

the class ClusterProxyDecoratorTest method testNothingProvided.

@Test
public void testNothingProvided() {
    Cluster result = clusterProxyDecorator.prepareProxyConfig(cluster, identityUser, null, stack);
    assertNull(result.getProxyConfig());
    Mockito.verify(service, Mockito.times(0)).create(any(IdentityUser.class), any(ProxyConfig.class));
    Mockito.verify(service, Mockito.times(0)).getPublicProxyConfig(anyString(), eq(identityUser));
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ProxyConfig(com.sequenceiq.cloudbreak.domain.ProxyConfig) Test(org.junit.Test)

Aggregations

IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)133 Test (org.junit.Test)14 Stack (com.sequenceiq.cloudbreak.domain.Stack)13 UserFilterField (com.sequenceiq.cloudbreak.common.service.user.UserFilterField)9 Async (org.springframework.scheduling.annotation.Async)9 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)8 Credential (com.sequenceiq.cloudbreak.domain.Credential)8 FlexSubscription (com.sequenceiq.cloudbreak.domain.FlexSubscription)8 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)7 LdapConfig (com.sequenceiq.cloudbreak.domain.LdapConfig)7 ProxyConfig (com.sequenceiq.cloudbreak.domain.ProxyConfig)7 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)6 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)6 Before (org.junit.Before)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)6 UpdateStackJson (com.sequenceiq.cloudbreak.api.model.UpdateStackJson)5 Template (com.sequenceiq.cloudbreak.domain.Template)5 ConstraintTemplate (com.sequenceiq.cloudbreak.domain.ConstraintTemplate)4 Network (com.sequenceiq.cloudbreak.domain.Network)4 Recipe (com.sequenceiq.cloudbreak.domain.Recipe)4