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);
}
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));
}
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));
}
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);
}
}
Aggregations