@Transient public String getScannerTypeName(){ return this.channelType.getName(); } }
public static void main(String[] args) { RssType rss = new RssType(); rss.setVersion("1.0"); ChannelType channel = new ChannelType(); channel.setTitle("Test title"); // Set the rest of the variables rss.setChannel(channel); //do the same for you other types then //convert it to xml Serializer serializer = new Persister(); File result = new File("rss.xml"); serializer.write(rss, result); }
@Override @SuppressWarnings("unchecked") public List<ChannelSeverity> retrieveByChannel(ChannelType channelType) { return sessionFactory .getCurrentSession() .createQuery( "from ChannelSeverity cs where cs.channelType = :channelTypeId order by cs.numericValue desc") .setInteger("channelTypeId", channelType.getId()).list(); }
@Override public String toString() { String type = applicationChannel == null ? "no type" : applicationChannel.getChannelType().getName(); return type + " (" + (findings == null ? 0 : findings.size()) + " results)"; } }
@Override public ChannelSeverity retrieveByCode(ChannelType channelType, String code) { // To avoid case insensitive query in MySQL List<ChannelSeverity> channelSeverities = (List<ChannelSeverity>) sessionFactory .getCurrentSession() .createQuery( "from ChannelSeverity cs where cs.code = :code " + "and cs.channelType = :channelTypeId") .setString("code", code) .setInteger("channelTypeId", channelType.getId()) .list(); if (channelSeverities == null || channelSeverities.size() == 0) return null; for (ChannelSeverity channelSeverity: channelSeverities) { if (code.equals(channelSeverity.getCode())) return channelSeverity; } return null; }
@Override public String toString() { if (channelType == null && application == null) { return "Channel with no type or application"; } else if (channelType == null) { return "Channel with no type for application " + application.getName(); } else if (application == null) { return "Channel with type " + channelType.getName() + " and no application."; } else { return channelType.getName() + "--" + application.getName(); } } }
@Override public void hideForScanResultFilter(ScanResultFilter scanResultFilter, Application application) { String subquery = getVulnsToHideSubquery(scanResultFilter, null, application, 0); Query query = sessionFactory.getCurrentSession().createQuery( "update Vulnerability vulnerability set hidden = true where vulnerability.id in " + subquery) .setParameter("genericSeverityIntValue0", scanResultFilter.getGenericSeverity().getIntValue()) .setParameter("channelTypeId0", scanResultFilter.getChannelType().getId()); if (application != null) { query.setParameter("applicationId0", application.getId()); } query.executeUpdate(); }
@JsonView({AllViews.TableRow.class}) @Transient private String getType() { String type = getApplicationChannel().getChannelType().getName(); if (ChannelType.DYNAMIC_TYPES.contains(type)) { return ChannelType.DYNAMIC; } else if (ChannelType.STATIC_TYPES.contains(type)) { return ChannelType.STATIC; } else { return ChannelType.MIXED; } }
private void addChannelTypeRestrictions() { // Limit scanner if present if (parameters.getChannelTypes() != null && !parameters.getChannelTypes().isEmpty()) { List<Integer> channelTypeIds = list(); for (ChannelType channelType : parameters.getChannelTypes()) { if (channelType.getId() != null) { channelTypeIds.add(channelType.getId()); } } if (!channelTypeIds.isEmpty()) { Criteria subCriteria = session.createCriteria(Finding.class); subCriteria.createAlias("scan", "myScan"); subCriteria.createAlias("myScan.applicationChannel", "myApplicationChannel"); subCriteria.createAlias("myApplicationChannel.channelType", "myChannelType"); subCriteria.add(Restrictions.in("myChannelType.id", channelTypeIds)); subCriteria.setProjection(Projections.property("vulnerability.id")); List<Integer> ids = (List<Integer>) subCriteria.list(); if (ids.isEmpty()) { LOG.debug("Got no valid Scanner type IDs."); ids.add(0); // should yield no results // throw an exception here? } else { LOG.debug("Adding scanner restriction: " + channelTypeIds); } criteria.add(Restrictions.in("id", ids)); } } }
@Override public ChannelVulnerability retrieveByName(ChannelType channelType, String name) { @SuppressWarnings("unchecked") List<ChannelVulnerability> vulns = sessionFactory.getCurrentSession() .createCriteria(ChannelVulnerability.class) .add( Restrictions.eq("name", name).ignoreCase() ) .add( Restrictions.eq("channelType", channelType) ) .list(); if (vulns == null || vulns.isEmpty()) { LOG.error("Error: you should add a mapping for " + name + " for channel " + channelType.getName()); return null; } else { return vulns.get(0); } }
@Override public Map<String, List<ChannelVulnerability>> getChannelVulnsEachChannelType(List<ChannelType> channelTypes) { Map<String, List<ChannelVulnerability>> map = CollectionUtils.map(); for (ChannelType channelType: channelTypes) { map.put(channelType.getName(), (List<ChannelVulnerability>) sessionFactory.getCurrentSession() .createCriteria(ChannelVulnerability.class) .add(Restrictions.eq("channelType", channelType)) .addOrder(Order.asc("name")) .list()); } return map; }
@JsonView({AllViews.TableRow.class, AllViews.FormInfo.class, AllViews.RestView2_1.class, AllViews.RestViewScanStatistic.class, AllViews.RestViewScanList.class }) @Transient private String getScannerName() { return getApplicationChannel().getChannelType().getName(); }
@Transient public String getScannerType() { if (getApplicationChannel() != null && getApplicationChannel().getChannelType() != null && getApplicationChannel().getChannelType().getName() != null) { String scannerName = getApplicationChannel().getChannelType().getName(); if (DYNAMIC_TYPES.contains(scannerName)) { return DYNAMIC; } else if (STATIC_TYPES.contains(scannerName)) { return STATIC; } else if (MIXED_TYPES.contains(scannerName)) { return MIXED; } } return null; }
@Transient @JsonIgnore public List<ApplicationChannel> getUploadableChannels() { if (uploadableChannels != null) return uploadableChannels; List<ApplicationChannel> normalList = getChannelList(); if (normalList == null || normalList.size() == 0) return new ArrayList<ApplicationChannel>(); Set<String> doNotIncludeSet = new HashSet<String>(); doNotIncludeSet.add(ScannerType.MANUAL.getDisplayName()); doNotIncludeSet.add(ScannerType.SENTINEL.getDisplayName()); doNotIncludeSet.add(ScannerType.VERACODE.getDisplayName()); doNotIncludeSet.add(ScannerType.QUALYSGUARD_WAS.getDisplayName()); List<ApplicationChannel> returnList = new ArrayList<ApplicationChannel>(); for (ApplicationChannel channel : normalList) { if (channel != null && channel.getChannelType() != null && channel.getChannelType().getName() != null && !doNotIncludeSet.contains(channel.getChannelType().getName())) { returnList.add(channel); } } uploadableChannels = returnList; return returnList; }
@Transient @JsonView({ AllViews.TableRow.class, AllViews.VulnerabilityDetail.class, AllViews.UIVulnSearch.class, AllViews.RestVulnSearch.class }) private String getScannerName() { return getScan().getApplicationChannel().getChannelType().getName(); }
@Transient @JsonIgnore @Nullable public String getChannelNameOrNull() { return getScan() != null && getScan().getApplicationChannel() != null && getScan().getApplicationChannel().getChannelType() != null && getScan().getApplicationChannel().getChannelType().getName() != null ? getScan().getApplicationChannel().getChannelType().getName() : null; }
@Transient @JsonView({ AllViews.UIVulnSearch.class, AllViews.VulnSearchApplications.class, AllViews.RestVulnSearch.class }) public List<String> getChannelNames() { if (getFindings() == null || getFindings().isEmpty()) { return new ArrayList<String>(); } List<String> returnList = new ArrayList<String>(); for (Finding finding : getFindings()) { if (finding.getScan() != null && finding.getScan().getApplicationChannel() != null && finding.getScan().getApplicationChannel().getChannelType() != null) { returnList.add(finding.getScan().getApplicationChannel().getChannelType().getName()); } } return returnList; }