use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class AuthenticationServiceTest method test_that_findIamRoleAssociatedWithSdb_returns_empty_optional_when_roles_not_found.
@Test
public void test_that_findIamRoleAssociatedWithSdb_returns_empty_optional_when_roles_not_found() {
String accountId = "0000000000";
String roleName = "role/path";
String principalArn = String.format("arn:aws:iam::%s:instance-profile/%s", accountId, roleName);
String roleArn = String.format("arn:aws:iam::%s:role/%s", accountId, roleName);
String rootArn = String.format("arn:aws:iam::%s:root", accountId);
when(awsIamRoleDao.getIamRole(principalArn)).thenReturn(Optional.empty());
when(awsIamRoleDao.getIamRole(roleArn)).thenReturn(Optional.empty());
when(awsIamRoleDao.getIamRole(rootArn)).thenReturn(Optional.empty());
when(awsIamRoleArnParser.isRoleArn(principalArn)).thenReturn(false);
when(awsIamRoleArnParser.convertPrincipalArnToRoleArn(principalArn)).thenReturn(roleArn);
when(awsIamRoleArnParser.convertPrincipalArnToRootArn(roleArn)).thenReturn(rootArn);
Optional<AwsIamRoleRecord> result = authenticationService.findIamRoleAssociatedWithSdb(principalArn);
assertFalse(result.isPresent());
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class AwsIamRoleService method createIamRole.
@Transactional
public AwsIamRoleRecord createIamRole(String iamPrincipalArn) {
String iamRoleId = uuidSupplier.get();
OffsetDateTime dateTime = dateTimeSupplier.get();
AwsIamRoleRecord awsIamRoleRecord = new AwsIamRoleRecord();
awsIamRoleRecord.setId(iamRoleId);
awsIamRoleRecord.setAwsIamRoleArn(iamPrincipalArn);
awsIamRoleRecord.setCreatedBy(SYSTEM_USER);
awsIamRoleRecord.setLastUpdatedBy(SYSTEM_USER);
awsIamRoleRecord.setCreatedTs(dateTime);
awsIamRoleRecord.setLastUpdatedTs(dateTime);
awsIamRoleDao.createIamRole(awsIamRoleRecord);
return awsIamRoleRecord;
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class IamPrincipalPermissionService method updateIamPrincipalPermission.
/**
* Updates a IAM role permission.
*
* @param safeDepositBoxId The safe deposit box id
* @param iamPrincipalPermission The IAM principal permission
* @param user The user making the changes
* @param dateTime The time of the changes
*/
@Transactional
public void updateIamPrincipalPermission(final String safeDepositBoxId, final IamPrincipalPermission iamPrincipalPermission, final String user, final OffsetDateTime dateTime) {
final Optional<AwsIamRoleRecord> iamRole = awsIamRoleDao.getIamRole(iamPrincipalPermission.getIamPrincipalArn());
if (iamRole.isEmpty()) {
String msg = "Unable to update permissions for IAM role that doesn't exist.";
throw ApiException.newBuilder().withApiErrors(CustomApiError.createCustomApiError(DefaultApiError.ENTITY_NOT_FOUND, msg)).withExceptionMessage(msg).build();
}
AwsIamRolePermissionRecord record = new AwsIamRolePermissionRecord();
record.setSdboxId(safeDepositBoxId);
record.setAwsIamRoleId(iamRole.get().getId());
record.setRoleId(iamPrincipalPermission.getRoleId());
record.setLastUpdatedBy(user);
record.setLastUpdatedTs(dateTime);
awsIamRoleDao.updateIamRolePermission(record);
}
use of com.nike.cerberus.record.AwsIamRoleRecord in project cerberus by Nike-Inc.
the class IamPrincipalPermissionService method getIamPrincipalPermissions.
public Set<IamPrincipalPermission> getIamPrincipalPermissions(final String safeDepositBoxId) {
final Set<IamPrincipalPermission> iamPrincipalPermissionSet = Sets.newHashSet();
final List<AwsIamRolePermissionRecord> permissionRecords = awsIamRoleDao.getIamRolePermissions(safeDepositBoxId);
permissionRecords.forEach(r -> {
final Optional<AwsIamRoleRecord> iamRoleRecord = awsIamRoleDao.getIamRoleById(r.getAwsIamRoleId());
if (iamRoleRecord.isPresent()) {
final IamPrincipalPermission permission = new IamPrincipalPermission();
permission.setId(r.getId());
permission.setIamPrincipalArn(iamRoleRecord.get().getAwsIamRoleArn());
permission.setRoleId(r.getRoleId());
permission.setCreatedBy(r.getCreatedBy());
permission.setLastUpdatedBy(r.getLastUpdatedBy());
permission.setCreatedTs(r.getCreatedTs());
permission.setLastUpdatedTs(r.getLastUpdatedTs());
iamPrincipalPermissionSet.add(permission);
}
});
return iamPrincipalPermissionSet;
}
Aggregations