Search in sources :

Example 6 with SecurityRoleEntity

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

the class SecurityRoleDaoTestHelper method getTestSecurityRoleEntities.

/**
 * Returns a list of test security role entities
 *
 * @return list of security role entities
 */
private List<SecurityRoleEntity> getTestSecurityRoleEntities() {
    SecurityRoleEntity securityRoleEntityOne = new SecurityRoleEntity();
    securityRoleEntityOne.setCode(SECURITY_ROLE_1);
    SecurityRoleEntity securityRoleEntityTwo = new SecurityRoleEntity();
    securityRoleEntityTwo.setCode(SECURITY_ROLE_2);
    return Arrays.asList(securityRoleEntityOne, securityRoleEntityTwo);
}
Also used : SecurityRoleEntity(org.finra.herd.model.jpa.SecurityRoleEntity)

Example 7 with SecurityRoleEntity

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

the class SecurityFunctionDaoTest method testGetUnrestrictedSecurityFunctions.

@Test
public void testGetUnrestrictedSecurityFunctions() throws Exception {
    // Create a role and two functions.
    SecurityRoleEntity securityRoleEntity = createSecurityRoleEntity(SECURITY_ROLE_1);
    List<SecurityFunctionEntity> securityFunctionEntities = Arrays.asList(createSecurityFunctionEntity(SECURITY_FUNCTION_3), createSecurityFunctionEntity(SECURITY_FUNCTION_2), createSecurityFunctionEntity(SECURITY_FUNCTION));
    // Retrieve a list of unrestricted functions.
    List<String> resultSecurityFunctions = securityFunctionDao.getUnrestrictedSecurityFunctions();
    // Since none of the security functions is mapped to a security role, the list will contain all three security functions.
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION));
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION_2));
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION_3));
    // Validate the order of retrieved security functions.
    assertTrue(resultSecurityFunctions.indexOf(SECURITY_FUNCTION) < resultSecurityFunctions.indexOf(SECURITY_FUNCTION_2));
    assertTrue(resultSecurityFunctions.indexOf(SECURITY_FUNCTION_2) < resultSecurityFunctions.indexOf(SECURITY_FUNCTION_3));
    // Map the role to the first security function.
    SecurityRoleFunctionEntity securityRoleFunctionEntity = new SecurityRoleFunctionEntity();
    securityRoleFunctionEntity.setSecurityRole(securityRoleEntity);
    securityRoleFunctionEntity.setSecurityFunction(securityFunctionEntities.get(0));
    herdDao.saveAndRefresh(securityRoleFunctionEntity);
    // Retrieve a list of unrestricted functions.
    resultSecurityFunctions = securityFunctionDao.getUnrestrictedSecurityFunctions();
    // Since the method is cached, all three security functions will be retrieved.
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION));
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION_2));
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION_3));
    // Clear the cache.
    cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
    // Retrieve a list of unrestricted functions.
    resultSecurityFunctions = securityFunctionDao.getUnrestrictedSecurityFunctions();
    // Since the first security function is mapped to a role, only two security functions will be retrieved.
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION));
    assertTrue(resultSecurityFunctions.contains(SECURITY_FUNCTION_2));
    assertFalse(resultSecurityFunctions.contains(SECURITY_FUNCTION_3));
}
Also used : SecurityRoleFunctionEntity(org.finra.herd.model.jpa.SecurityRoleFunctionEntity) SecurityFunctionEntity(org.finra.herd.model.jpa.SecurityFunctionEntity) SecurityRoleEntity(org.finra.herd.model.jpa.SecurityRoleEntity) Test(org.junit.Test)

Example 8 with SecurityRoleEntity

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

the class SecurityFunctionDaoTest method testGetSecurityFunctionsByRole.

@Test
public void testGetSecurityFunctionsByRole() throws Exception {
    // Create role and function.
    SecurityRoleEntity securityRoleEntity = createSecurityRoleEntity(SECURITY_ROLE_1);
    SecurityFunctionEntity securityFunctionEntity = createSecurityFunctionEntity(SECURITY_FUNCTION);
    // Validate that no security functions are returned for the role.
    assertTrue(securityFunctionDao.getSecurityFunctionsForRole(SECURITY_ROLE_1).isEmpty());
    // Add new role to functions mapping.
    SecurityRoleFunctionEntity securityRoleFunctionEntity = new SecurityRoleFunctionEntity();
    securityRoleFunctionEntity.setSecurityRole(securityRoleEntity);
    securityRoleFunctionEntity.setSecurityFunction(securityFunctionEntity);
    herdDao.saveAndRefresh(securityRoleFunctionEntity);
    // Since the functions method is cached, the test function still will not be retrieved.
    assertTrue(securityFunctionDao.getSecurityFunctionsForRole(SECURITY_ROLE_1).isEmpty());
    // Clear the cache and retrieve the functions again.
    cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
    // Validate that test security function mapped to the role is now retrieved.
    assertEquals(Arrays.asList(SECURITY_FUNCTION), securityFunctionDao.getSecurityFunctionsForRole(SECURITY_ROLE_1));
}
Also used : SecurityRoleFunctionEntity(org.finra.herd.model.jpa.SecurityRoleFunctionEntity) SecurityFunctionEntity(org.finra.herd.model.jpa.SecurityFunctionEntity) SecurityRoleEntity(org.finra.herd.model.jpa.SecurityRoleEntity) Test(org.junit.Test)

Example 9 with SecurityRoleEntity

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

the class HttpHeaderAuthenticationFilterTest method setupTestFunctions.

private void setupTestFunctions(String roleId) {
    SecurityRoleEntity securityRoleEntity = new SecurityRoleEntity();
    securityRoleEntity.setCode(roleId);
    herdDao.saveAndRefresh(securityRoleEntity);
    for (String function : TEST_FUNCTIONS) {
        SecurityFunctionEntity securityFunctionEntity = new SecurityFunctionEntity();
        securityFunctionEntity.setCode(function);
        herdDao.saveAndRefresh(securityFunctionEntity);
        SecurityRoleFunctionEntity securityRoleFunctionEntity = new SecurityRoleFunctionEntity();
        securityRoleFunctionEntity.setSecurityRole(securityRoleEntity);
        securityRoleFunctionEntity.setSecurityFunction(securityFunctionEntity);
        herdDao.saveAndRefresh(securityRoleFunctionEntity);
    }
}
Also used : SecurityRoleFunctionEntity(org.finra.herd.model.jpa.SecurityRoleFunctionEntity) SecurityFunctionEntity(org.finra.herd.model.jpa.SecurityFunctionEntity) SecurityRoleEntity(org.finra.herd.model.jpa.SecurityRoleEntity)

Aggregations

SecurityRoleEntity (org.finra.herd.model.jpa.SecurityRoleEntity)9 SecurityFunctionEntity (org.finra.herd.model.jpa.SecurityFunctionEntity)4 SecurityRoleFunctionEntity (org.finra.herd.model.jpa.SecurityRoleFunctionEntity)4 Test (org.junit.Test)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)1 UserAuthorizations (org.finra.herd.model.api.xml.UserAuthorizations)1 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)1 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)1 Authentication (org.springframework.security.core.Authentication)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1