22
22
import java .awt .Component ;
23
23
import java .util .ArrayList ;
24
24
import java .util .List ;
25
+ import java .util .Locale ;
25
26
import javax .swing .JButton ;
26
27
import javax .swing .JTextField ;
27
28
import org .parosproxy .paros .core .scanner .Plugin .AlertThreshold ;
28
29
import org .parosproxy .paros .core .scanner .Plugin .AttackStrength ;
29
30
import org .zaproxy .addon .automation .jobs .ActiveScanJob ;
30
31
import org .zaproxy .addon .automation .jobs .ActiveScanJob .Parameters ;
31
32
import org .zaproxy .addon .automation .jobs .JobUtils ;
33
+ import org .zaproxy .addon .automation .jobs .PolicyDefinition ;
32
34
import org .zaproxy .addon .automation .jobs .PolicyDefinition .Rule ;
33
35
import org .zaproxy .zap .utils .DisplayUtils ;
34
36
@@ -41,6 +43,7 @@ public class ActiveScanJobDialog extends ActiveScanPolicyDialog {
41
43
"automation.dialog.tab.params" ,
42
44
"automation.dialog.ascan.tab.policydefaults" ,
43
45
"automation.dialog.ascan.tab.policyrules" ,
46
+ "automation.dialog.ascan.tab.policyalerttags" ,
44
47
"automation.dialog.ascan.tab.adv"
45
48
};
46
49
@@ -68,48 +71,51 @@ public class ActiveScanJobDialog extends ActiveScanPolicyDialog {
68
71
public ActiveScanJobDialog (ActiveScanJob job ) {
69
72
super (TITLE , DisplayUtils .getScaledDimension (500 , 400 ), TAB_LABELS );
70
73
this .job = job ;
74
+ int tabIndex = -1 ;
71
75
72
- this .addTextField (0 , NAME_PARAM , this .job .getData ().getName ());
76
+ this .addTextField (++ tabIndex , NAME_PARAM , this .job .getData ().getName ());
73
77
List <String > contextNames = this .job .getEnv ().getContextNames ();
74
78
// Add blank option
75
79
contextNames .add (0 , "" );
76
- this .addComboField (0 , CONTEXT_PARAM , contextNames , this .job .getParameters ().getContext ());
80
+ this .addComboField (
81
+ tabIndex , CONTEXT_PARAM , contextNames , this .job .getParameters ().getContext ());
77
82
78
83
List <String > users = job .getEnv ().getAllUserNames ();
79
84
// Add blank option
80
85
users .add (0 , "" );
81
- this .addComboField (0 , USER_PARAM , users , this .job .getData ().getParameters ().getUser ());
86
+ this .addComboField (
87
+ tabIndex , USER_PARAM , users , this .job .getData ().getParameters ().getUser ());
82
88
83
89
// Cannot select the node as it might not be present in the Sites tree
84
- this .addNodeSelectField (0 , URL_PARAM , null , true , false );
90
+ this .addNodeSelectField (tabIndex , URL_PARAM , null , true , false );
85
91
Component urlField = this .getField (URL_PARAM );
86
92
if (urlField instanceof JTextField ) {
87
93
((JTextField ) urlField ).setText (this .job .getParameters ().getUrl ());
88
94
}
89
95
90
- this .addTextField (0 , POLICY_PARAM , this .job .getParameters ().getPolicy ());
96
+ this .addTextField (tabIndex , POLICY_PARAM , this .job .getParameters ().getPolicy ());
91
97
this .addNumberField (
92
- 0 ,
98
+ tabIndex ,
93
99
MAX_RULE_DURATION_PARAM ,
94
100
0 ,
95
101
Integer .MAX_VALUE ,
96
102
JobUtils .unBox (job .getParameters ().getMaxRuleDurationInMins ()));
97
103
this .addNumberField (
98
- 0 ,
104
+ tabIndex ,
99
105
MAX_SCAN_DURATION_PARAM ,
100
106
0 ,
101
107
Integer .MAX_VALUE ,
102
108
JobUtils .unBox (job .getParameters ().getMaxScanDurationInMins ()));
103
109
addNumberField (
104
- 0 ,
110
+ tabIndex ,
105
111
MAX_ALERTS_PER_RULE_PARAM ,
106
112
0 ,
107
113
Integer .MAX_VALUE ,
108
114
JobUtils .unBox (job .getParameters ().getMaxAlertsPerRule ()));
109
- this .addCheckBoxField (0 , FIELD_ADVANCED , advOptionsSet ());
115
+ this .addCheckBoxField (tabIndex , FIELD_ADVANCED , advOptionsSet ());
110
116
this .addFieldListener (FIELD_ADVANCED , e -> setAdvancedTabs (getBoolValue (FIELD_ADVANCED )));
111
117
112
- this .addPadding (0 );
118
+ this .addPadding (tabIndex );
113
119
114
120
String thresholdName =
115
121
JobUtils .thresholdToI18n (job .getData ().getPolicyDefinition ().getDefaultThreshold ());
@@ -131,7 +137,7 @@ public ActiveScanJobDialog(ActiveScanJob job) {
131
137
allthresholds .add (JobUtils .thresholdToI18n (at .name ()));
132
138
}
133
139
134
- this .addComboField (1 , DEFAULT_THRESHOLD_PARAM , allthresholds , thresholdName );
140
+ this .addComboField (++ tabIndex , DEFAULT_THRESHOLD_PARAM , allthresholds , thresholdName );
135
141
136
142
List <String > allstrengths = new ArrayList <>();
137
143
@@ -142,45 +148,73 @@ public ActiveScanJobDialog(ActiveScanJob job) {
142
148
allstrengths .add (JobUtils .strengthToI18n (at .name ()));
143
149
}
144
150
145
- this .addComboField (1 , DEFAULT_STRENGTH_PARAM , allstrengths , strengthName );
151
+ this .addComboField (tabIndex , DEFAULT_STRENGTH_PARAM , allstrengths , strengthName );
146
152
147
- this .addPadding (1 );
153
+ this .addPadding (tabIndex );
148
154
149
155
List <JButton > buttons = new ArrayList <>();
150
156
buttons .add (getAddButton ());
151
157
buttons .add (getModifyButton ());
152
158
buttons .add (getRemoveButton ());
153
159
154
- this .addTableField (2 , getRulesTable (), buttons );
160
+ this .addTableField (++tabIndex , getRulesTable (), buttons );
161
+
162
+ String tagRuleThresholdName =
163
+ JobUtils .thresholdToI18n (
164
+ job .getData ()
165
+ .getPolicyDefinition ()
166
+ .getAlertTagRule ()
167
+ .getThreshold ()
168
+ .name ());
169
+ if (tagRuleThresholdName .isEmpty ()) {
170
+ tagRuleThresholdName = JobUtils .thresholdToI18n (AlertThreshold .MEDIUM .name ());
171
+ }
172
+ String tagRuleStrengthName =
173
+ JobUtils .strengthToI18n (
174
+ job .getData ().getPolicyDefinition ().getAlertTagRule ().getStrength ().name ());
175
+ if (tagRuleStrengthName .isEmpty ()) {
176
+ tagRuleStrengthName = JobUtils .strengthToI18n (AttackStrength .MEDIUM .name ());
177
+ }
178
+ this .addComboField (
179
+ ++tabIndex , TAG_RULE_THRESHOLD_PARAM , allthresholds , tagRuleThresholdName );
180
+ this .addComboField (tabIndex , TAG_RULE_STRENGTH_PARAM , allstrengths , tagRuleStrengthName );
181
+ this .addTableField (
182
+ tabIndex ,
183
+ getIncludedAlertTagsTable (),
184
+ List .of (getAddIncludedAlertTagButton (), getRemoveIncludedAlertTagButton ()));
185
+ this .addTableField (
186
+ tabIndex ,
187
+ getExcludedAlertTagsTable (),
188
+ List .of (getAddExcludedAlertTagButton (), getRemoveExcludedAlertTagButton ()));
155
189
156
190
this .addNumberField (
157
- 3 ,
191
+ ++ tabIndex ,
158
192
DELAY_IN_MS_PARAM ,
159
193
0 ,
160
194
Integer .MAX_VALUE ,
161
195
JobUtils .unBox (job .getParameters ().getDelayInMs ()));
162
196
this .addNumberField (
163
- 3 ,
197
+ tabIndex ,
164
198
THREADS_PER_HOST_PARAM ,
165
199
1 ,
166
200
Integer .MAX_VALUE ,
167
201
JobUtils .unBox (job .getParameters ().getThreadPerHost ()));
168
202
this .addCheckBoxField (
169
- 3 , ADD_QUERY_PARAM , JobUtils .unBox (job .getParameters ().getAddQueryParam ()));
203
+ tabIndex , ADD_QUERY_PARAM , JobUtils .unBox (job .getParameters ().getAddQueryParam ()));
170
204
this .addCheckBoxField (
171
- 3 ,
205
+ tabIndex ,
172
206
HANDLE_ANTI_CSRF_PARAM ,
173
207
JobUtils .unBox (job .getParameters ().getHandleAntiCSRFTokens ()));
174
208
this .addCheckBoxField (
175
- 3 ,
209
+ tabIndex ,
176
210
INJECT_PLUGIN_ID_PARAM ,
177
211
JobUtils .unBox (job .getParameters ().getInjectPluginIdInHeader ()));
178
212
this .addCheckBoxField (
179
- 3 ,
213
+ tabIndex ,
180
214
SCAN_HEADERS_PARAM ,
181
215
JobUtils .unBox (job .getParameters ().getScanHeadersAllRequests ()));
182
216
183
- this .addPadding (3 );
217
+ this .addPadding (tabIndex );
184
218
185
219
setAdvancedTabs (getBoolValue (FIELD_ADVANCED ));
186
220
}
@@ -248,6 +282,23 @@ public void save() {
248
282
this .job .getParameters ().setScanHeadersAllRequests (null );
249
283
}
250
284
this .job .getData ().getPolicyDefinition ().setRules (this .getRulesModel ().getRules ());
285
+ this .job
286
+ .getData ()
287
+ .getPolicyDefinition ()
288
+ .setAlertTagRule (
289
+ new PolicyDefinition .AlertTagRuleConfig (
290
+ this .getIncludedTagsTableModel ().getAlertTagPatterns (),
291
+ this .getExcludedTagsTableModel ().getAlertTagPatterns (),
292
+ AttackStrength .valueOf (
293
+ JobUtils .i18nToStrength (
294
+ this .getStringValue (
295
+ TAG_RULE_STRENGTH_PARAM ))
296
+ .toUpperCase (Locale .ROOT )),
297
+ AlertThreshold .valueOf (
298
+ JobUtils .i18nToThreshold (
299
+ this .getStringValue (
300
+ TAG_RULE_THRESHOLD_PARAM ))
301
+ .toUpperCase (Locale .ROOT ))));
251
302
this .job .resetAndSetChanged ();
252
303
}
253
304
@@ -261,4 +312,9 @@ public String validateFields() {
261
312
protected List <Rule > getRules () {
262
313
return job .getData ().getPolicyDefinition ().getRules ();
263
314
}
315
+
316
+ @ Override
317
+ protected PolicyDefinition .AlertTagRuleConfig getAlertTagRule () {
318
+ return job .getData ().getPolicyDefinition ().getAlertTagRule ();
319
+ }
264
320
}
0 commit comments