22
33import java .awt .BorderLayout ;
44import java .awt .Color ;
5+ import java .awt .Component ;
56import java .awt .FlowLayout ;
67import java .awt .Font ;
78import java .awt .Graphics ;
3940import javax .swing .SwingUtilities ;
4041import javax .swing .UIManager ;
4142import javax .swing .table .AbstractTableModel ;
43+ import javax .swing .table .TableCellRenderer ;
4244import javax .swing .table .TableRowSorter ;
4345
4446import com .arqsz .burpgitleaks .config .GitleaksRule ;
4547import com .arqsz .burpgitleaks .config .PluginSettings ;
4648import com .arqsz .burpgitleaks .config .RuleLoader ;
4749import com .arqsz .burpgitleaks .config .RuleLoader .GitleaksConfiguration ;
4850import com .arqsz .burpgitleaks .scan .GitleaksScanCheck ;
51+ import com .arqsz .burpgitleaks .verification .TemplateManager ;
4952
5053import burp .api .montoya .MontoyaApi ;
5154
@@ -55,6 +58,7 @@ public class SettingsTab extends JPanel {
5558 private final GitleaksScanCheck scanCheck ;
5659 private final PluginSettings settings ;
5760 private final ExecutorService executor ;
61+ private final TemplateManager templateManager ;
5862 private final RulesTableModel rulesModel ;
5963 private List <GitleaksRule > currentRules ;
6064
@@ -73,13 +77,15 @@ protected void paintComponent(Graphics g) {
7377 private final Consumer <Boolean > onIssuesTabVisibilityChange ;
7478
7579 public SettingsTab (MontoyaApi api , GitleaksScanCheck scanCheck , PluginSettings settings ,
76- List <GitleaksRule > initialRules , Consumer <Boolean > onIssuesTabVisibilityChange ) {
80+ List <GitleaksRule > initialRules , TemplateManager templateManager ,
81+ Consumer <Boolean > onIssuesTabVisibilityChange ) {
7782 this .api = api ;
7883 this .scanCheck = scanCheck ;
7984 this .settings = settings ;
85+ this .templateManager = templateManager ;
8086 this .currentRules = initialRules ;
8187 this .onIssuesTabVisibilityChange = onIssuesTabVisibilityChange ;
82- this .rulesModel = new RulesTableModel (initialRules , settings .getDisabledRules ());
88+ this .rulesModel = new RulesTableModel (initialRules , settings .getDisabledRules (), templateManager );
8389 this .executor = Executors .newSingleThreadExecutor ();
8490
8591 setLayout (new BorderLayout ());
@@ -280,6 +286,8 @@ public String getToolTipText(java.awt.event.MouseEvent e) {
280286 table .setFillsViewportHeight (true );
281287 table .setRowHeight (24 );
282288
289+ table .setDefaultRenderer (Boolean .class , new BooleanRenderer ());
290+
283291 JPopupMenu popup = new JPopupMenu ();
284292 addCopyMenuItem (popup , table , "Copy Source" , 1 );
285293 addCopyMenuItem (popup , table , "Copy Rule ID" , 2 );
@@ -316,7 +324,8 @@ private void filter() {
316324 table .getColumnModel ().getColumn (1 ).setPreferredWidth (100 );
317325 table .getColumnModel ().getColumn (1 ).setMaxWidth (350 );
318326 table .getColumnModel ().getColumn (2 ).setPreferredWidth (200 );
319- table .getColumnModel ().getColumn (3 ).setPreferredWidth (400 );
327+ table .getColumnModel ().getColumn (3 ).setMaxWidth (80 );
328+ table .getColumnModel ().getColumn (4 ).setPreferredWidth (400 );
320329
321330 p .add (new JScrollPane (table ), BorderLayout .CENTER );
322331
@@ -560,11 +569,13 @@ private void setConfigBadge(String text, Color bg) {
560569 }
561570
562571 private static class RulesTableModel extends AbstractTableModel {
563- private final String [] cols = { "Enabled" , "Source" , "Rule ID" , "Description" };
572+ private final String [] cols = { "Enabled" , "Source" , "Rule ID" , "Verifiable" , " Description" };
564573 private List <GitleaksRule > rules ;
565574 private List <Boolean > enabledState ;
575+ private final TemplateManager templateManager ;
566576
567- public RulesTableModel (List <GitleaksRule > rules , List <String > disabledIds ) {
577+ public RulesTableModel (List <GitleaksRule > rules , List <String > disabledIds , TemplateManager templateManager ) {
578+ this .templateManager = templateManager ;
568579 setRules (rules , disabledIds );
569580 }
570581
@@ -603,7 +614,7 @@ public String getColumnName(int col) {
603614
604615 @ Override
605616 public Class <?> getColumnClass (int col ) {
606- return col == 0 ? Boolean .class : String .class ;
617+ return ( col == 0 || col == 3 ) ? Boolean .class : String .class ;
607618 }
608619
609620 @ Override
@@ -622,6 +633,8 @@ public Object getValueAt(int row, int col) {
622633 case 2 :
623634 return rule .getId ();
624635 case 3 :
636+ return templateManager .hasTemplate (rule .getId ());
637+ case 4 :
625638 return rule .getDescription ();
626639 default :
627640 return null ;
@@ -635,4 +648,41 @@ public void setValueAt(Object val, int row, int col) {
635648 fireTableCellUpdated (row , col );
636649 }
637650 }
651+
652+ private static class BooleanRenderer extends JPanel implements TableCellRenderer {
653+ private final JCheckBox checkBox = new JCheckBox ();
654+
655+ public BooleanRenderer () {
656+ super (new GridBagLayout ());
657+
658+ setOpaque (true );
659+ checkBox .setOpaque (false );
660+ checkBox .setHorizontalAlignment (JLabel .CENTER );
661+
662+ add (checkBox );
663+ }
664+
665+ @ Override
666+ public Component getTableCellRendererComponent (JTable table , Object value ,
667+ boolean isSelected , boolean hasFocus , int row , int column ) {
668+
669+ if (isSelected ) {
670+ setBackground (table .getSelectionBackground ());
671+ checkBox .setForeground (table .getSelectionForeground ());
672+ } else {
673+ Color alternateColor = UIManager .getColor ("Table.alternateRowColor" );
674+ if (alternateColor != null && row % 2 != 0 ) {
675+ setBackground (alternateColor );
676+ } else {
677+ setBackground (table .getBackground ());
678+ }
679+
680+ checkBox .setForeground (table .getForeground ());
681+ }
682+
683+ checkBox .setSelected (value != null && (Boolean ) value );
684+
685+ return this ;
686+ }
687+ }
638688}
0 commit comments