use of org.finra.herd.model.jpa.SecurityFunctionEntity in project herd by FINRAOS.
the class SecurityFunctionDaoImpl method getSecurityFunctions.
@Override
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public List<String> getSecurityFunctions() {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the security role function.
Root<SecurityFunctionEntity> securityFunctionEntity = criteria.from(SecurityFunctionEntity.class);
// Get the columns.
Path<String> functionCodeColumn = securityFunctionEntity.get(SecurityFunctionEntity_.code);
// Add the clauses for the query.
criteria.select(functionCodeColumn).orderBy(builder.asc(functionCodeColumn));
// Run the query to get a list of functions.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.SecurityFunctionEntity in project herd by FINRAOS.
the class SecurityFunctionDaoImpl method getUnrestrictedSecurityFunctions.
@Override
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public List<String> getUnrestrictedSecurityFunctions() {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the security function.
Root<SecurityFunctionEntity> securityFunctionEntityRoot = criteria.from(SecurityFunctionEntity.class);
// Build a subquery to eliminate security functions that are mapped to security roles.
Subquery<SecurityFunctionEntity> subquery = criteria.subquery(SecurityFunctionEntity.class);
Root<SecurityRoleFunctionEntity> subSecurityRoleFunctionEntityRoot = subquery.from(SecurityRoleFunctionEntity.class);
subquery.select(subSecurityRoleFunctionEntityRoot.get(SecurityRoleFunctionEntity_.securityFunction)).where(builder.equal(subSecurityRoleFunctionEntityRoot.get(SecurityRoleFunctionEntity_.securityFunction), securityFunctionEntityRoot));
// Get the security function code column.
Path<String> functionCodeColumn = securityFunctionEntityRoot.get(SecurityFunctionEntity_.code);
// Add the clauses for the query.
criteria.select(functionCodeColumn).where(builder.not(builder.exists(subquery))).orderBy(builder.asc(functionCodeColumn));
// Run the query to get a list of unrestricted security functions.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.SecurityFunctionEntity in project herd by FINRAOS.
the class SecurityFunctionDaoImpl method getSecurityFunctionsForRole.
@Override
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public List<String> getSecurityFunctionsForRole(String roleCd) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the security role function mapping.
Root<SecurityRoleFunctionEntity> securityRoleFunctionEntity = criteria.from(SecurityRoleFunctionEntity.class);
// Join to the other tables we can filter on.
Join<SecurityRoleFunctionEntity, SecurityRoleEntity> securityRoleEntity = securityRoleFunctionEntity.join(SecurityRoleFunctionEntity_.securityRole);
Join<SecurityRoleFunctionEntity, SecurityFunctionEntity> securityFunctionEntity = securityRoleFunctionEntity.join(SecurityRoleFunctionEntity_.securityFunction);
// Get the columns.
Path<String> functionCodeColumn = securityFunctionEntity.get(SecurityFunctionEntity_.code);
// Add the select clause.
criteria.select(functionCodeColumn);
// Add the where clause.
criteria.where(builder.equal(builder.upper(securityRoleEntity.get(SecurityRoleEntity_.code)), roleCd.toUpperCase()));
// Add the order by clause.
criteria.orderBy(builder.asc(functionCodeColumn));
// Run the query to get a list of functions.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.SecurityFunctionEntity 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.SecurityFunctionEntity 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));
}
Aggregations