Search in sources :

Example 1 with UmsAuthenticationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException in project cloudbreak by hortonworks.

the class UmsAuthenticationServiceTest method testInvalidCrnDueToParse.

@Test
public void testInvalidCrnDueToParse() {
    thrown.expect(UmsAuthenticationException.class);
    String crn = "crn:cdp:cookie:us-west-1:9d74eee4-1cad-45d7-b645-7ccf9edbb73d:user:qaas/b8a64902-7765-4ddd-a4f3-df81ae585e10";
    try {
        underTest.getCloudbreakUser(crn, "principal");
    } catch (UmsAuthenticationException e) {
        assertEquals("Invalid CRN has been provided: " + crn, e.getMessage());
        throw e;
    }
}
Also used : UmsAuthenticationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with UmsAuthenticationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException 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 3 with UmsAuthenticationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException in project cloudbreak by hortonworks.

the class UmsAuthenticationServiceTest method testInvalidTypeCrn.

@Test
public void testInvalidTypeCrn() {
    thrown.expect(UmsAuthenticationException.class);
    String crn = "crn:cdp:iam:us-west-1:9d74eee4-1cad-45d7-b645-7ccf9edbb73d:cluster:qaas/b8a64902-7765-4ddd-a4f3-df81ae585e10";
    try {
        underTest.getCloudbreakUser(crn, "principal");
    } catch (UmsAuthenticationException e) {
        assertEquals("Authentication is supported only with User and MachineUser CRN: " + crn, e.getMessage());
        throw e;
    }
}
Also used : UmsAuthenticationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with UmsAuthenticationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException in project cloudbreak by hortonworks.

the class UmsAuthenticationServiceTest method testInvalidCrnDueToPattern.

@Test
public void testInvalidCrnDueToPattern() {
    thrown.expect(UmsAuthenticationException.class);
    String crn = "crsdfadsfdsf sadasf3-df81ae585e10";
    try {
        underTest.getCloudbreakUser(crn, "principal");
    } catch (UmsAuthenticationException e) {
        assertEquals("Invalid CRN has been provided: " + crn, e.getMessage());
        throw e;
    }
}
Also used : UmsAuthenticationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

UmsAuthenticationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsAuthenticationException)4 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 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 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)1 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)1