2727import org .slf4j .Logger ;
2828import org .slf4j .LoggerFactory ;
2929import org .springframework .beans .factory .annotation .Autowired ;
30+ import org .springframework .beans .factory .annotation .Value ;
3031import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
3132import org .springframework .stereotype .Component ;
3233
4748public class DefectDojoPersistenceProvider implements PersistenceProvider {
4849 private static final Logger LOG = LoggerFactory .getLogger (DefectDojoPersistenceProvider .class );
4950
51+ @ Value ("${securecodebox.persistence.defectdojo.optional:false}" )
52+ protected boolean isOptional ;
53+
5054 @ Autowired
5155 DefectDojoService defectDojoService ;
5256
@@ -66,6 +70,18 @@ public void persist(SecurityTest securityTest) throws PersistenceException {
6670 LOG .debug ("Starting defectdojo persistence provider" );
6771 LOG .debug ("RawFindings: {}" , securityTest .getReport ().getRawFindings ());
6872
73+ try {
74+ persistInDefectDojo (securityTest );
75+ } catch (Exception e ) {
76+ // ignore error if defect dojo provider is set to optional
77+ if (isOptional ) {
78+ LOG .error ("Failed to persist security test in defect dojo" , e );
79+ return ;
80+ } else throw e ;
81+ }
82+ }
83+
84+ private void persistInDefectDojo (SecurityTest securityTest ) throws PersistenceException {
6985 checkConnection ();
7086 checkToolTypes ();
7187
@@ -77,15 +93,15 @@ public void persist(SecurityTest securityTest) throws PersistenceException {
7793 long userUrl = defectDojoService .retrieveUserId (username );
7894
7995 List <String > results = getDefectDojoScanName (securityTest .getName ()).equals ("Generic Findings Import" ) ? getGenericResults (securityTest ) : getRawResults (securityTest );
80- for (String result : results ) {
81- defectDojoService .createFindings (
82- result ,
83- engagementId ,
84- userUrl ,
85- currentDate (),
86- getDefectDojoScanName (securityTest .getName ())
87- );
88- }
96+ for (String result : results ) {
97+ defectDojoService .createFindings (
98+ result ,
99+ engagementId ,
100+ userUrl ,
101+ currentDate (),
102+ getDefectDojoScanName (securityTest .getName ())
103+ );
104+ }
89105 }
90106
91107 static final String GIT_SERVER_NAME = "Git Server" ;
0 commit comments