Search in sources :

Example 1 with IamRole

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

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

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");
    }
}
Also used : IamRole(org.finra.herd.model.api.xml.IamRole)

Example 4 with IamRole

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);
}
Also used : IamRole(org.finra.herd.model.api.xml.IamRole) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationUpdateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 5 with IamRole

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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) IamRole(org.finra.herd.model.api.xml.IamRole) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationUpdateRequest(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Aggregations

IamRole (org.finra.herd.model.api.xml.IamRole)22 Test (org.junit.Test)16 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)15 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)14 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)13 ArrayList (java.util.ArrayList)10 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)7 NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)6 NamespaceIamRoleAuthorizationUpdateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest)5 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 NamespaceIamRoleAuthorizations (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations)2 LinkedHashMap (java.util.LinkedHashMap)1