use of com.sequenceiq.cloudbreak.auth.crn.CrnParseException in project cloudbreak by hortonworks.
the class FlowService method getFlowChainStateByResourceCrn.
public FlowCheckResponse getFlowChainStateByResourceCrn(String chainId, String resourceCrn) {
Crn crn;
List<Long> resourceIds;
try {
crn = Crn.safeFromString(resourceCrn);
if (crn.getService().equals(Crn.Service.DATALAKE)) {
resourceIds = flowLogDBService.getResourceIdsByCrn(resourceCrn);
} else {
Long resourceId = flowLogDBService.getResourceIdByCrnOrName(resourceCrn);
resourceIds = Collections.singletonList(resourceId);
}
} catch (CrnParseException crnParseException) {
resourceIds = Collections.EMPTY_LIST;
}
return getFlowChainStateSafe(resourceIds, chainId);
}
use of com.sequenceiq.cloudbreak.auth.crn.CrnParseException in project cloudbreak by hortonworks.
the class CrnService method getCurrentUserId.
public String getCurrentUserId() {
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
Crn crn = null;
try {
crn = Crn.fromString(userCrn);
} catch (NullPointerException e) {
LOGGER.warn("Crn is not set", e);
throw new CrnParseException("CRN is not set");
}
if (crn != null) {
if (ResourceType.USER.equals(crn.getResourceType())) {
return crn.getResource();
} else {
return null;
}
} else {
throw new CrnParseException("Can not parse account ID from CRN");
}
}
use of com.sequenceiq.cloudbreak.auth.crn.CrnParseException 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;
}
use of com.sequenceiq.cloudbreak.auth.crn.CrnParseException in project cloudbreak by hortonworks.
the class CrnService method getCurrentUserId.
public String getCurrentUserId() {
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
if (userCrn == null) {
throw new CrnParseException("Current user CRN is not set");
}
Crn crn = Crn.safeFromString(userCrn);
return crn.getUserId();
}
use of com.sequenceiq.cloudbreak.auth.crn.CrnParseException in project cloudbreak by hortonworks.
the class CrnService method getCurrentAccountId.
public String getCurrentAccountId() {
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
if (userCrn == null) {
throw new CrnParseException("Current user CRN is not set");
}
Crn crn = Crn.safeFromString(userCrn);
return crn.getAccountId();
}
Aggregations