Search in sources :

Example 1 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity 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;
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 2 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity 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;
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 3 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationServiceImpl method createNamespaceIamRoleAuthorizationEntity.

/**
 * Creates a new NamespaceIamRoleAuthorizationEntity from the given parameters.
 *
 * @param namespaceEntity The namespace entity
 * @param iamRole The IAM role
 *
 * @return The NamespaceIamRoleAuthorizationEntity
 */
private NamespaceIamRoleAuthorizationEntity createNamespaceIamRoleAuthorizationEntity(NamespaceEntity namespaceEntity, IamRole iamRole) {
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity.setNamespace(namespaceEntity);
    namespaceIamRoleAuthorizationEntity.setIamRoleName(iamRole.getIamRoleName().trim());
    if (StringUtils.isNotBlank(iamRole.getIamRoleDescription())) {
        namespaceIamRoleAuthorizationEntity.setDescription(iamRole.getIamRoleDescription().trim());
    }
    return namespaceIamRoleAuthorizationEntity;
}
Also used : NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)

Example 4 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertFilterByNamespaceWhenGiven.

@Test
public void getNamespaceIamRoleAuthorizationsAssertFilterByNamespaceWhenGiven() {
    NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    NamespaceEntity namespaceEntity2 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity1);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(0, namespaceIamRoleAuthorizations.size());
    }
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity3 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity3.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity3.setIamRoleName("iamRoleName3");
    namespaceIamRoleAuthorizationEntity3.setDescription("description3");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity3);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity1);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(2, namespaceIamRoleAuthorizations.size());
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(0);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) List(java.util.List) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test)

Example 5 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertGetAllWhenNamespaceIsNotGiven.

@Test
public void getNamespaceIamRoleAuthorizationsAssertGetAllWhenNamespaceIsNotGiven() {
    NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    NamespaceEntity namespaceEntity2 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity3 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity3.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity3.setIamRoleName("iamRoleName3");
    namespaceIamRoleAuthorizationEntity3.setDescription("description3");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity3);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(null);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(3, namespaceIamRoleAuthorizations.size());
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(0);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(2);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity2.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) List(java.util.List) Test(org.junit.Test)

Aggregations

NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)27 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)24 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)14 IamRole (org.finra.herd.model.api.xml.IamRole)13 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)12 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)7 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 List (java.util.List)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 NamespaceIamRoleAuthorizationUpdateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest)2 NamespaceIamRoleAuthorizations (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeSet (java.util.TreeSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)1