use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class GrpcUmsClient method getUserDetails.
/**
* Retrieves user details from UMS.
*
* @param userCrn the CRN of the user
* @param requestId an optional request Id
* @return the user associated with this user CRN
*/
@Cacheable(cacheNames = "umsUserCache", key = "{ #userCrn }")
public User getUserDetails(String userCrn, Optional<String> requestId) {
UmsClient client = makeClient(channelWrapper.getChannel());
LOGGER.debug("Getting user information for {} using request ID {}", userCrn, requestId);
User user = client.getUser(RequestIdUtil.getOrGenerate(requestId), userCrn);
LOGGER.debug("User information retrieved for userCrn: {}", user.getCrn());
return user;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class CrnUserDetailsServiceTest method loadUserByCrn.
@Test
public void loadUserByCrn() {
User user = User.newBuilder().setCrn("userCrn").setEmail("dummyuser@cloudera.com").setUserId("1").build();
when(mockedUmsClient.getUserDetails(eq(userCrn), any(), any())).thenReturn(user);
UserDetails userDetails = underTest.loadUserByUsername(userCrn);
assertTrue(userDetails.getAuthorities().iterator().next().getAuthority().equals("CRN_USER"));
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class MockUserManagementService method listUsers.
@Override
public void listUsers(ListUsersRequest request, StreamObserver<ListUsersResponse> responseObserver) {
LOGGER.info("List users for account: {}", request.getAccountId());
Builder userBuilder = ListUsersResponse.newBuilder();
if (request.getUserIdOrCrnCount() == 0) {
if (isNotEmpty(request.getAccountId())) {
ofNullable(accountUsers.get(request.getAccountId())).orElse(Set.of()).stream().map(userName -> createUser(request.getAccountId(), userName)).forEach(userBuilder::addUser);
for (int i = 0; i < MOCK_USER_COUNT; i++) {
User user = createUser(request.getAccountId(), "fakeMockUser" + i);
userBuilder.addUser(user);
}
}
responseObserver.onNext(userBuilder.build());
} else {
String userIdOrCrn = request.getUserIdOrCrn(0);
String[] splittedCrn = userIdOrCrn.split(":");
String userName = splittedCrn[6];
String accountId = splittedCrn[4];
responseObserver.onNext(userBuilder.addUser(createUser(accountId, userName)).build());
}
responseObserver.onCompleted();
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class UmsClient method listUsers.
/**
* Wraps calls to ListUsers with an Account ID.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param userIdOrCrnList a list of users to list. If null or empty then all users will be listed
* @return the list of users
*/
public List<User> listUsers(String requestId, String accountId, List<String> userIdOrCrnList) {
checkNotNull(requestId, "requestId should not be null.");
validateAccountIdWithWarning(accountId);
List<User> users = new ArrayList<>();
ListUsersRequest.Builder requestBuilder = ListUsersRequest.newBuilder().setAccountId(accountId).setPageSize(umsClientConfig.getListUsersPageSize());
if (userIdOrCrnList != null && !userIdOrCrnList.isEmpty()) {
requestBuilder.addAllUserIdOrCrn(userIdOrCrnList);
}
ListUsersResponse response;
do {
response = newStub(requestId).listUsers(requestBuilder.build());
users.addAll(response.getUserList());
requestBuilder.setPageToken(response.getNextPageToken());
} while (response.hasNextPageToken());
return users;
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User in project cloudbreak by hortonworks.
the class UmsAuthenticationService method getCloudbreakUser.
@Override
public CloudbreakUser getCloudbreakUser(String userCrn, String principal) {
String requestId = MDCBuilder.getOrGenerateRequestId();
Crn crn;
try {
crn = Crn.safeFromString(userCrn);
} catch (NullPointerException | CrnParseException e) {
throw new UmsAuthenticationException(String.format("Invalid CRN has been provided: %s", userCrn));
}
CloudbreakUser cloudbreakUser;
switch(crn.getResourceType()) {
case USER:
if (RegionAwareInternalCrnGeneratorUtil.isInternalCrn(userCrn)) {
return RegionAwareInternalCrnGeneratorUtil.createInternalCrnUser(Crn.fromString(userCrn));
} else {
User userInfo = umsClient.getUserDetails(userCrn, Optional.ofNullable(requestId), regionAwareInternalCrnGeneratorFactory);
String userName = principal != null ? principal : userInfo.getEmail();
cloudbreakUser = new CloudbreakUser(userInfo.getUserId(), userCrn, userName, userInfo.getEmail(), crn.getAccountId());
}
break;
case MACHINE_USER:
MachineUser machineUserInfo = umsClient.getMachineUserDetails(userCrn, Crn.fromString(userCrn).getAccountId(), Optional.ofNullable(requestId), regionAwareInternalCrnGeneratorFactory);
String machineUserName = principal != null ? principal : machineUserInfo.getMachineUserName();
cloudbreakUser = new CloudbreakUser(machineUserInfo.getMachineUserId(), userCrn, machineUserName, machineUserInfo.getMachineUserName(), crn.getAccountId());
break;
default:
throw new UmsAuthenticationException(String.format("Authentication is supported only with User and MachineUser CRN: %s", userCrn));
}
return cloudbreakUser;
}
Aggregations