Search in sources :

Example 1 with CrnParseException

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

Example 2 with CrnParseException

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

Example 3 with CrnParseException

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;
}
Also used : CrnParseException(com.sequenceiq.cloudbreak.auth.crn.CrnParseException) UmsAuthenticationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException) User(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 4 with CrnParseException

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

Example 5 with CrnParseException

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

Aggregations

Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)6 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)6 MachineUser (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser)1 User (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.User)1 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)1 UmsAuthenticationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException)1 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)1