Search in sources :

Example 6 with NamespaceIamRoleAuthorizationEntity

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

the class NamespaceIamRoleAuthorizationHelperTest method checkPermissionsAssertRoleNameIsCaseInsensitive.

@Test
public void checkPermissionsAssertRoleNameIsCaseInsensitive() {
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    String iamRoleName1 = "iamRoleName1";
    String iamRoleName2 = "iamRoleName2";
    Collection<String> requestedIamRoleNames = Arrays.asList(StringUtils.capitalize(iamRoleName1), StringUtils.capitalize(iamRoleName2));
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames);
    verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 7 with NamespaceIamRoleAuthorizationEntity

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

the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertOrderByRoleName.

@Test
public void getNamespaceIamRoleAuthorizationsAssertOrderByRoleName() {
    NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("Z");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("A");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
    {
        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(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.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)

Example 8 with NamespaceIamRoleAuthorizationEntity

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

the class NamespaceIamRoleAuthorizationDaoImpl method getNamespaceIamRoleAuthorizations.

@Override
public List<NamespaceIamRoleAuthorizationEntity> getNamespaceIamRoleAuthorizations(NamespaceEntity namespaceEntity) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<NamespaceIamRoleAuthorizationEntity> query = criteriaBuilder.createQuery(NamespaceIamRoleAuthorizationEntity.class);
    Root<NamespaceIamRoleAuthorizationEntity> root = query.from(NamespaceIamRoleAuthorizationEntity.class);
    Join<NamespaceIamRoleAuthorizationEntity, NamespaceEntity> namespaceJoin = root.join(NamespaceIamRoleAuthorizationEntity_.namespace);
    if (namespaceEntity != null) {
        query.where(criteriaBuilder.equal(root.get(NamespaceIamRoleAuthorizationEntity_.namespace), namespaceEntity));
    }
    query.orderBy(criteriaBuilder.asc(namespaceJoin.get(NamespaceEntity_.code)), criteriaBuilder.asc(root.get(NamespaceIamRoleAuthorizationEntity_.iamRoleName)));
    return entityManager.createQuery(query).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)

Example 9 with NamespaceIamRoleAuthorizationEntity

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

the class NamespaceIamRoleAuthorizationServiceTest method createNamespaceIamRoleAuthorizationAssertErrorWhenAuthorizationAlreadyExist.

@Test
public void createNamespaceIamRoleAuthorizationAssertErrorWhenAuthorizationAlreadyExist() {
    IamRole expectedIamRole1 = new IamRole("iamRoleName1", "iamRoleDescription1");
    IamRole expectedIamRole2 = new IamRole("iamRoleName2", "iamRoleDescription2");
    List<IamRole> expectedIamRoles = Arrays.asList(expectedIamRole1, expectedIamRole2);
    NamespaceIamRoleAuthorizationCreateRequest expectedRequest = new NamespaceIamRoleAuthorizationCreateRequest("namespace", expectedIamRoles);
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(Arrays.asList(new NamespaceIamRoleAuthorizationEntity()));
    try {
        namespaceIamRoleAuthorizationServiceImpl.createNamespaceIamRoleAuthorization(expectedRequest);
        fail();
    } catch (Exception e) {
        assertEquals(AlreadyExistsException.class, e.getClass());
        assertEquals(String.format("Namespace IAM role authorizations with namespace \"%s\" already exist", expectedNamespaceEntity.getCode()), e.getMessage());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedRequest.getNamespace());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceIamRoleAuthorizationCreateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 10 with NamespaceIamRoleAuthorizationEntity

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

the class NamespaceIamRoleAuthorizationServiceTest method getNamespaceIamRoleAuthorizationAssertInputsTrimmed.

@Test
public void getNamespaceIamRoleAuthorizationAssertInputsTrimmed() {
    String expectedNamespace = " namespace ";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization namespaceIamRoleAuthorization = namespaceIamRoleAuthorizationServiceImpl.getNamespaceIamRoleAuthorization(expectedNamespace);
    assertNotNull(namespaceIamRoleAuthorization);
    assertEquals(expectedNamespaceEntity.getCode(), namespaceIamRoleAuthorization.getNamespace());
    assertNotNull(namespaceIamRoleAuthorization.getIamRoles());
    assertEquals(2, namespaceIamRoleAuthorization.getIamRoles().size());
    {
        IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = namespaceIamRoleAuthorization.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace.trim());
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) ArrayList(java.util.ArrayList) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) 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