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;
}
}
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;
}
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;
}
}
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;
}
}
Aggregations