use of org.finra.herd.model.api.xml.IamRole in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method deleteNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public NamespaceIamRoleAuthorization deleteNamespaceIamRoleAuthorization(String namespace) {
Assert.hasText(namespace, "Namespace must be specified");
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
namespaceIamRoleAuthorizationDao.delete(namespaceIamRoleAuthorizationEntity);
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.api.xml.IamRole in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method getNamespaceIamRoleAuthorization.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.READ)
@Override
public NamespaceIamRoleAuthorization getNamespaceIamRoleAuthorization(String namespace) {
Assert.hasText(namespace, "Namespace must be specified");
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(namespace.trim());
List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = getNamespaeIamRoleAuthorizationEntities(namespaceEntity);
NamespaceIamRoleAuthorization result = new NamespaceIamRoleAuthorization(namespaceEntity.getCode(), new ArrayList<>());
for (NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity : namespaceIamRoleAuthorizationEntities) {
result.getIamRoles().add(new IamRole(namespaceIamRoleAuthorizationEntity.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getDescription()));
}
return result;
}
use of org.finra.herd.model.api.xml.IamRole in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceImpl method validateIamRoles.
/**
* Asserts that the given IAM roles are valid as a user input. The IAM roles are valid if not null, not empty, and each element's name is not null and not
* blank.
*
* @param iamRoles The list of IAM roles to validate
*/
private void validateIamRoles(List<IamRole> iamRoles) {
Assert.notNull(iamRoles, "At least 1 IAM roles must be specified");
Assert.isTrue(iamRoles.size() > 0, "At least 1 IAM roles must be specified");
for (IamRole iamRole : iamRoles) {
Assert.notNull(iamRole, "IAM role must be specified");
Assert.hasText(iamRole.getIamRoleName(), "IAM role name must be specified");
}
}
use of org.finra.herd.model.api.xml.IamRole in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceTest method updateNamespaceIamRoleAuthorizationAssertErrorWhenNamespaceIsBlank.
@Test
public void updateNamespaceIamRoleAuthorizationAssertErrorWhenNamespaceIsBlank() {
String expectedNamespace = " ";
List<IamRole> iamRoles = new ArrayList<>();
IamRole iamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
iamRoles.add(iamRole1);
IamRole iamRole2 = new IamRole("iamRoleName2", " ");
iamRoles.add(iamRole2);
NamespaceIamRoleAuthorizationUpdateRequest expectedNamespaceIamRoleAuthorizationUpdateRequest = new NamespaceIamRoleAuthorizationUpdateRequest(iamRoles);
try {
namespaceIamRoleAuthorizationServiceImpl.updateNamespaceIamRoleAuthorization(expectedNamespace, expectedNamespaceIamRoleAuthorizationUpdateRequest);
fail();
} catch (Exception e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("Namespace must be specified", e.getMessage());
}
verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
use of org.finra.herd.model.api.xml.IamRole in project herd by FINRAOS.
the class NamespaceIamRoleAuthorizationServiceTest method updateNamespaceIamRoleAuthorizationAssertErrorWhenDaoReturnsEmpty.
@Test
public void updateNamespaceIamRoleAuthorizationAssertErrorWhenDaoReturnsEmpty() {
String expectedNamespace = "namespace";
List<IamRole> iamRoles = new ArrayList<>();
IamRole iamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
iamRoles.add(iamRole1);
IamRole iamRole2 = new IamRole("iamRoleName2", " ");
iamRoles.add(iamRole2);
NamespaceIamRoleAuthorizationUpdateRequest expectedNamespaceIamRoleAuthorizationUpdateRequest = new NamespaceIamRoleAuthorizationUpdateRequest(iamRoles);
NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
expectedNamespaceEntity.setCode("NAMESPACE");
when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(Collections.emptyList());
try {
namespaceIamRoleAuthorizationServiceImpl.updateNamespaceIamRoleAuthorization(expectedNamespace, expectedNamespaceIamRoleAuthorizationUpdateRequest);
fail();
} catch (Exception e) {
assertEquals(ObjectNotFoundException.class, e.getClass());
assertEquals(String.format("Namespace IAM role authorizations for namespace \"%s\" do not exist", expectedNamespaceEntity.getCode()), e.getMessage());
}
verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace);
verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Aggregations