List of usage examples for org.hibernate.criterion Restrictions in
public static Criterion in(String propertyName, Collection values)
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java
License:Mozilla Public License
@Nonnull private Criteria addFiltering(Criteria criteria, Set<Integer> teamIds, Set<Integer> appIds) { boolean useAppIds = appIds != null, useTeamIds = teamIds != null; if (teamIds != null && teamIds.isEmpty()) { teamIds = set(0);/* w w w .j a v a 2s . c om*/ } if (appIds != null && appIds.isEmpty()) { appIds = set(0); } if (!useAppIds && !useTeamIds) { return criteria; } if (useAppIds && useTeamIds) { criteria.createAlias("app.organization", "team").add(eq("team.active", true)) .add(or(Restrictions.in("app.id", appIds), Restrictions.in("team.id", teamIds))); } else if (useAppIds) { criteria.add(Restrictions.in("app.id", appIds)); } else { criteria.createAlias("app.organization", "team").add(Restrictions.in("team.id", teamIds)) .add(eq("team.active", true)); } return criteria; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java
License:Mozilla Public License
public List<ScanRepeatFindingMap> getMapsForIDs(List<Integer> mapIDs) { return sessionFactory.getCurrentSession().createCriteria(ScanRepeatFindingMap.class) .add(Restrictions.in("id", mapIDs)).list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityCommentDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override// w ww . ja va 2 s . com public List<VulnerabilityComment> retrieveRecent(int number, Set<Integer> authenticatedAppIds, Set<Integer> authenticatedTeamIds) { if ((authenticatedAppIds == null || authenticatedAppIds.isEmpty()) && (authenticatedTeamIds == null || authenticatedTeamIds.isEmpty())) { return list(); } Criteria baseCriteria = getVulnCriteria(number).createAlias("vulnerability.application", "app") .createAlias("vulnerability", "vuln").add(Restrictions.eq("app.active", true)) .add(Restrictions.eq("vuln.active", true)); boolean useAppIds = authenticatedAppIds != null && !authenticatedAppIds.isEmpty(), useTeamIds = authenticatedTeamIds != null && !authenticatedTeamIds.isEmpty(); if (useAppIds && useTeamIds) { baseCriteria.createAlias("app.organization", "team") .add(Restrictions.or(Restrictions.in("app.id", authenticatedAppIds), Restrictions.in("team.id", authenticatedTeamIds))); } else if (useAppIds) { baseCriteria.add(Restrictions.in("app.id", authenticatedAppIds)); } else if (useTeamIds) { baseCriteria.createAlias("app.organization", "team") .add(Restrictions.in("team.id", authenticatedTeamIds)); } return baseCriteria.list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override//from www . java 2 s .c o m public List<Vulnerability> retrieveByIdList(List<Integer> vulnerabilityIds) { return sessionFactory.getCurrentSession().createCriteria(Vulnerability.class) .add(Restrictions.in("id", vulnerabilityIds)).list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java
License:Mozilla Public License
@Override public List<Map> getScanComparison(VulnerabilitySearchParameters parameters, boolean isFalsePositive) { assert parameters != null; List<Integer> idList = getVulnIdList(parameters); if (idList.isEmpty()) return list(); Session session = sessionFactory.getCurrentSession(); List<Map> fullList = list(); // TODO refactor this to reduce duplication or remove the need for it int current = 0; while (current < idList.size()) { int start = current, end = current + 500; if (end > idList.size()) { end = idList.size();//from w ww . ja v a 2 s . c o m } List<Integer> thisPage = idList.subList(start, end); Criteria criteria = session.createCriteria(Vulnerability.class); criteria.createAlias("findings", "finding"); criteria.createAlias("finding.scan", "scan"); criteria.createAlias("scan.applicationChannel", "applicationChannel"); criteria.createAlias("applicationChannel.channelType", "channelType"); criteria.add(Restrictions.in("id", thisPage)); ProjectionList projectionList = Projections.projectionList() .add(Projections.groupProperty("channelType.name"), "channelName") .add(Projections.alias(Projections.countDistinct("id"), "foundCount")); if (!isFalsePositive) { projectionList.add(Projections.groupProperty("foundHAMEndpoint"), "foundHAMEndpoint"); } criteria.setProjection(projectionList); criteria.addOrder(Order.desc("foundCount")); criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List results = (List<Map>) criteria.list(); fullList.addAll(results); current += 500; } return fullList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addPermissionRestrictions() { if (parameters.getPermissionsList() != null && !parameters.getPermissionsList().isEmpty()) { criteria.createAlias("endpointPermissions", "permissionAlias"); criteria.add(Restrictions.in("permissionAlias.name", parameters.getPermissionsList())); }// ww w. j a va 2s . co m if (parameters.getShowAuthenticated() || parameters.getShowUnknown() || parameters.getShowUnauthenticated()) { List<AuthenticationRequired> ordinalValues = list(); boolean acceptNull = false; if (parameters.getShowAuthenticated()) { ordinalValues.add(AUTHENTICATED); } if (parameters.getShowUnauthenticated()) { ordinalValues.add(ANONYMOUS); } if (parameters.getShowUnknown()) { ordinalValues.add(UNKNOWN); acceptNull = true; } Criterion restrictions; if (acceptNull) { restrictions = Restrictions.or(Restrictions.in("authenticationRequired", ordinalValues), Restrictions.isNull("authenticationRequired")); } else { restrictions = Restrictions.in("authenticationRequired", ordinalValues); } criteria.add(restrictions); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addTeamsAndApplications() { List<Integer> appIds = list(), teamIds = list(); if (parameters.getTeams() != null && !parameters.getTeams().isEmpty()) { for (Organization organization : parameters.getTeams()) { if (organization.getId() != null) { teamIds.add(organization.getId()); }/* w ww.jav a 2 s . com*/ } } if (parameters.getApplications() != null && !parameters.getApplications().isEmpty()) { for (Application application : parameters.getApplications()) { if (application.getId() != null) { appIds.add(application.getId()); } } } if (appIds.isEmpty() || teamIds.isEmpty()) { if (appIds.isEmpty()) { criteria.add(Restrictions.eq("applicationAlias.active", true)); LOG.debug("No application IDs added to the criteria."); } else { criteria.add(Restrictions.in("application.id", appIds)); LOG.debug("Added applications with IDs " + appIds); } if (teamIds.isEmpty()) { criteria.add(Restrictions.eq("team.active", true)); LOG.debug("No team IDs added to the criteria."); } else { criteria.add(Restrictions.in("team.id", teamIds)); LOG.debug("Added teams with IDs " + teamIds); } } else { // Make sure to OR things together if both application and team IDs are present. This ensures that // if a user has permission to see one team and one application from a different team, all of the // vulnerabilities will show up. criteria.add(Restrictions.or(Restrictions.in("application.id", appIds), Restrictions.in("team.id", teamIds))); LOG.debug("Added applications with IDs " + appIds); LOG.debug("Added teams with IDs " + teamIds); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addAppTags() { List<Integer> appIds; List<Integer> tagIds = list(); if (parameters.getTags() != null) { for (Tag tag : parameters.getTags()) { if (tag.getId() != null) { tagIds.add(tag.getId()); }/*from w w w . j a va2s. c o m*/ } } if (tagIds.isEmpty()) { LOG.debug("No tag IDs found in parameters."); } else { Criteria subCriteria = session.createCriteria(Tag.class); subCriteria.createAlias("applications", "applicationsAlias"); subCriteria.add(Restrictions.in("id", tagIds)); subCriteria.setProjection(Projections.property("applicationsAlias.id")); appIds = (List<Integer>) subCriteria.list(); if (appIds.isEmpty()) appIds.add(0); criteria.add(Restrictions.in("application.id", appIds)); LOG.debug("Added applications with IDs " + appIds); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addVulnTags() { List<Integer> tagIds = list(); if (parameters.getVulnTags() != null) { for (Tag tag : parameters.getVulnTags()) { if (tag.getId() != null) { tagIds.add(tag.getId()); }/*from ww w . j a va2s .c o m*/ } } if (tagIds.isEmpty()) { LOG.debug("No vuln tag IDs found in parameters."); } else { criteria.createAlias("tags", "tagsAlias"); criteria.add(Restrictions.in("tagsAlias.id", tagIds)); LOG.debug("Added tags with IDs " + tagIds); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addTypeRestrictions() { if (parameters.getGenericVulnerabilities() != null && !parameters.getGenericVulnerabilities().isEmpty()) { List<Integer> genericVulnerabilityIds = list(); for (GenericVulnerability genericVulnerability : parameters.getGenericVulnerabilities()) { if (genericVulnerability.getId() != null) { genericVulnerabilityIds.add(genericVulnerability.getId()); }//from www . java 2 s.c o m } if (!genericVulnerabilityIds.isEmpty()) { LOG.debug("Restricting CWE ID to " + genericVulnerabilityIds); criteria.add(Restrictions.in("genericVulnAlias.id", genericVulnerabilityIds)); } } }