Search in sources :

Example 21 with CloudbreakUser

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with CloudbreakUser

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()));
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 23 with CloudbreakUser

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);
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Example 24 with CloudbreakUser

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);
    }
}
Also used : CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 25 with CloudbreakUser

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();
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Aggregations

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)47 User (com.sequenceiq.cloudbreak.workspace.model.User)24 Test (org.junit.jupiter.api.Test)10 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)8 Optional (java.util.Optional)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Collection (java.util.Collection)3 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2