• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/client/security/EditPropertiesDialog.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.client.security;
50

51
import java.util.ArrayList;
52
import java.util.Arrays;
53
import java.util.HashSet;
54
import java.util.List;
55
import java.util.Set;
56
import javax.annotation.Nullable;
57
import javax.swing.JOptionPane;
58
import javax.swing.table.DefaultTableModel;
59

60
import org.exist.client.*;
61
import org.exist.client.tristatecheckbox.TristateCheckboxTableCellEditor;
62
import org.exist.client.tristatecheckbox.TristateCheckBoxTableCellRenderer;
63
import org.exist.client.tristatecheckbox.TristateState;
64
import org.exist.security.ACLPermission;
65
import org.exist.security.Permission;
66
import org.exist.security.PermissionDeniedException;
67
import org.exist.security.SecurityManager;
68
import org.exist.security.internal.aider.ACEAider;
69
import org.exist.security.internal.aider.SimpleACLPermissionAider;
70
import org.exist.xmldb.UserManagementService;
71
import org.xmldb.api.base.Collection;
72
import org.xmldb.api.base.Resource;
73
import org.xmldb.api.base.XMLDBException;
74

75
import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple;
76
import static org.exist.client.ClientFrame.MULTIPLE_INDICATOR;
77

78
/**
79
 *
80
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
81
 */
82
public class EditPropertiesDialog extends javax.swing.JFrame {
83
    private final UserManagementService userManagementService;
84
    private final String currentUser;
85
    private final Collection parent;
86
    private final String uri;
87
    private final String internetMediaType;
88
    private final String created;
89
    private final String lastModified;
90
    private String size;
91
    private final String messageDigestType;
92
    private final String messageDigestValue;
93
    private final String owner;
94
    private final String group;
95
    private final ModeDisplay mode;
96
    @Nullable private final SimpleACLPermissionAider acl;
97
    private final List<ResourceDescriptor> applyTo;
98
    
99
    private BasicPermissionsTableModel basicPermissionsTableModel = null;
×
100
    private DefaultTableModel aclTableModel = null;
×
101

102
    private final static String ERROR_TITLE = "Edit Properties Error";
103

104
    public EditPropertiesDialog(final UserManagementService userManagementService, final String currentUser, final Collection parent, final String uri, final String internetMediaType, final String created, final String lastModified, final String size, final String messageDigestType, final String messageDigestValue, final String owner, final String group, final ModeDisplay mode, @Nullable final SimpleACLPermissionAider acl, final List<ResourceDescriptor> applyTo) {
×
105
        this.userManagementService = userManagementService;
×
106
        this.currentUser = currentUser;
×
107
        this.parent = parent;
×
108
        this.uri = uri;
×
109
        this.internetMediaType = internetMediaType;
×
110
        this.created = created;
×
111
        this.lastModified = lastModified;
×
112
        this.size = size;
×
113
        this.messageDigestType = messageDigestType;
×
114
        this.messageDigestValue = messageDigestValue;
×
115
        this.owner = owner;
×
116
        this.group = group;
×
117
        this.mode = mode;
×
118
        this.acl = acl;
×
119
        this.applyTo = applyTo;
×
120
        this.setIconImage(InteractiveClient.getElementalIcon(getClass()).getImage());
×
121
        initComponents();
×
122
        setFormProperties();
×
123
    }
×
124

125
    private void setFormProperties() {
126
        lblResourceValue.setText(uri);
×
127
        lblInternetMediaTypeValue.setText(internetMediaType);
×
128
        lblCreatedValue.setText(created);
×
129
        lblLastModifiedValue.setText(lastModified);
×
130
        lblSizeValue.setText(size);
×
131
        lblDigestAlgorithmValue.setText(messageDigestType);
×
132
        txtDigest.setText(messageDigestValue);
×
133
        txtDigest.setVisible(true);
×
134
        spDigest.setVisible(true);
×
135
        lblOwnerValue.setText(owner);
×
136
        lblGroupValue.setText(group);
×
137
        
138
        try {
139
            final boolean canModify = canModifyPermissions();
×
140
        
141
            btnChangeOwner.setEnabled(isDba());
×
142
            btnChangeGroup.setEnabled(isDba());
×
143
            
144
            tblBasePermissions.setEnabled(canModify);
×
145

146
            final boolean canModifyAcl = acl != null && canModify;
×
147

148
            tblAcl.setEnabled(canModifyAcl);
×
149
            
150
            miInsertAceBefore.setEnabled(canModifyAcl);
×
151
            miInsertAceAfter.setEnabled(canModifyAcl);
×
152
            btnAddAce.setEnabled(canModifyAcl);
×
153
        
154
            miMoveUp.setEnabled(false);
×
155
            miMoveDown.setEnabled(false);
×
156
        
157
            miRemoveAce.setEnabled(false);
×
158
        } catch(final XMLDBException xmldbe) {
×
159
            JOptionPane.showMessageDialog(this, "Could not get dba group members: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
160
        }
161
    }
×
162

163
    private BasicPermissionsTableModel getBasicPermissionsTableModel() {
164
        if(basicPermissionsTableModel == null) {
×
165
            basicPermissionsTableModel = new BasicPermissionsTableModel(mode);
×
166
        }
167
        
168
        return basicPermissionsTableModel;
×
169
    }
170
    
171
    private DefaultTableModel getAclTableModel() {
172
        if(aclTableModel == null) {
×
173
            aclTableModel = new AclTableModel(acl);
×
174
        }
175
        return aclTableModel;
×
176
    }
177

178
    private UserManagementService getUserManagementService() {
179
        return userManagementService;
×
180
    }
181
            
182
    
183
    /**
184
     * This method is called from within the constructor to initialize the form.
185
     * WARNING: Do NOT modify this code. The content of this method is always
186
     * regenerated by the Form Editor.
187
     */
188
    @SuppressWarnings("unchecked")
189
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
190
    private void initComponents() {
191

192
        pmAcl = new javax.swing.JPopupMenu();
×
193
        miInsertAceBefore = new javax.swing.JMenuItem();
×
194
        miInsertAceAfter = new javax.swing.JMenuItem();
×
195
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
×
196
        miMoveUp = new javax.swing.JMenuItem();
×
197
        miMoveDown = new javax.swing.JMenuItem();
×
198
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
×
199
        miRemoveAce = new javax.swing.JMenuItem();
×
200
        jScrollPane1 = new javax.swing.JScrollPane();
×
201
        jTextArea1 = new javax.swing.JTextArea();
×
202
        lblResource = new javax.swing.JLabel();
×
203
        lblInternetMediaType = new javax.swing.JLabel();
×
204
        lblCreated = new javax.swing.JLabel();
×
205
        lblLastModified = new javax.swing.JLabel();
×
206
        lblOwner = new javax.swing.JLabel();
×
207
        lblGroup = new javax.swing.JLabel();
×
208
        lblResourceValue = new javax.swing.JLabel();
×
209
        lblInternetMediaTypeValue = new javax.swing.JLabel();
×
210
        lblCreatedValue = new javax.swing.JLabel();
×
211
        lblLastModifiedValue = new javax.swing.JLabel();
×
212
        lblOwnerValue = new javax.swing.JLabel();
×
213
        lblGroupValue = new javax.swing.JLabel();
×
214
        btnChangeOwner = new javax.swing.JButton();
×
215
        btnChangeGroup = new javax.swing.JButton();
×
216
        jScrollPane2 = new javax.swing.JScrollPane();
×
217
        tblBasePermissions = new javax.swing.JTable();
×
218
        if (applyTo.size() > 1) {
×
219
            tblBasePermissions.setDefaultRenderer(Boolean.class, new TristateCheckBoxTableCellRenderer<Boolean>(bool -> Tuple(null, TristateState.fromBoolean(bool))));
×
220
            tblBasePermissions.setDefaultEditor(Boolean.class, new TristateCheckboxTableCellEditor<>(bool -> Tuple(null, TristateState.fromBoolean(bool)), state -> TristateState.toBoolean(state._2)));
×
221
            tblBasePermissions.setDefaultRenderer(LabelledBoolean.class, new TristateCheckBoxTableCellRenderer<LabelledBoolean>(labelledBool -> Tuple(labelledBool.getLabel(), TristateState.fromBoolean(labelledBool.isSet()))));
×
222
            tblBasePermissions.setDefaultEditor(LabelledBoolean.class, new TristateCheckboxTableCellEditor<>(labelledBool -> Tuple(labelledBool.getLabel(), TristateState.fromBoolean(labelledBool.isSet())), state -> new LabelledBoolean(state._1, TristateState.toBoolean(state._2))));
×
223
        } else {
×
224
            tblBasePermissions.setDefaultRenderer(LabelledBoolean.class, new CheckboxTableCellRenderer<LabelledBoolean>(labelledBoolean -> Tuple(labelledBoolean.getLabel(), labelledBoolean.isSet())));
×
225
            tblBasePermissions.setDefaultEditor(LabelledBoolean.class, new CheckboxTableCellEditor<>(labelledBoolean -> Tuple(labelledBoolean.getLabel(), labelledBoolean.isSet()), state -> new LabelledBoolean(state._1, state._2)));
×
226
        }
227
        lblAccessControlList = new javax.swing.JLabel();
×
228
        jSeparator1 = new javax.swing.JSeparator();
×
229
        lblBasePermissions = new javax.swing.JLabel();
×
230
        jScrollPane3 = new javax.swing.JScrollPane();
×
231
        tblAcl = new javax.swing.JTable();
×
232
        jSeparator2 = new javax.swing.JSeparator();
×
233
        btnSave = new javax.swing.JButton();
×
234
        btnClose = new javax.swing.JButton();
×
235
        btnAddAce = new javax.swing.JButton();
×
236
        lblDigest = new javax.swing.JLabel();
×
237
        lblDigestAlgorithmValue = new javax.swing.JLabel();
×
238
        spDigest = new javax.swing.JScrollPane();
×
239
        txtDigest = new javax.swing.JTextArea();
×
240
        lblSize = new javax.swing.JLabel();
×
241
        lblSizeValue = new javax.swing.JLabel();
×
242

243
        miInsertAceBefore.setText("Insert ACE before...");
×
244
        miInsertAceBefore.addActionListener(this::miInsertAceBeforeActionPerformed);
×
245
        pmAcl.add(miInsertAceBefore);
×
246

247
        miInsertAceAfter.setText("Insert ACE after...");
×
248
        miInsertAceAfter.addActionListener(this::miInsertAceAfterActionPerformed);
×
249
        pmAcl.add(miInsertAceAfter);
×
250
        pmAcl.add(jSeparator3);
×
251

252
        miMoveUp.setText("Move ACE up");
×
253
        miMoveUp.addActionListener(this::miMoveUpActionPerformed);
×
254
        pmAcl.add(miMoveUp);
×
255

256
        miMoveDown.setText("Move ACE down");
×
257
        miMoveDown.addActionListener(this::miMoveDownActionPerformed);
×
258
        pmAcl.add(miMoveDown);
×
259
        pmAcl.add(jSeparator4);
×
260

261
        miRemoveAce.setText("Remove ACE");
×
262
        miRemoveAce.addActionListener(this::miRemoveAceActionPerformed);
×
263
        pmAcl.add(miRemoveAce);
×
264

265
        jTextArea1.setColumns(20);
×
266
        jTextArea1.setRows(5);
×
267
        jScrollPane1.setViewportView(jTextArea1);
×
268

269
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
×
270
        setTitle("Properties");
×
271

272
        lblResource.setText("Resource:");
×
273

274
        lblInternetMediaType.setText("Internet Media Type:");
×
275

276
        lblCreated.setText("Created:");
×
277

278
        lblLastModified.setText("Last Modified:");
×
279

280
        lblOwner.setText("Owner:");
×
281

282
        lblGroup.setText("Group:");
×
283

284
        lblResourceValue.setText("<resource>");
×
285

286
        lblInternetMediaTypeValue.setText("<internet media type>");
×
287

288
        lblCreatedValue.setText("<created>");
×
289

290
        lblLastModifiedValue.setText("<last modified>");
×
291

292
        lblOwnerValue.setText("<owner>");
×
293

294
        lblGroupValue.setText("<group>");
×
295

296
        btnChangeOwner.setText("...");
×
297
        btnChangeOwner.addActionListener(this::btnChangeOwnerActionPerformed);
×
298

299
        btnChangeGroup.setText("...");
×
300
        btnChangeGroup.addActionListener(this::btnChangeGroupActionPerformed);
×
301

302
        tblBasePermissions.setModel(getBasicPermissionsTableModel());
×
303
        tblBasePermissions.setRowSelectionAllowed(false);
×
304
        jScrollPane2.setViewportView(tblBasePermissions);
×
305

306
        lblAccessControlList.setText("Access Control List");
×
307

308
        lblBasePermissions.setText("Base Permissions");
×
309

310
        tblAcl.setModel(getAclTableModel());
×
311
        tblAcl.setComponentPopupMenu(pmAcl);
×
312
        tblAcl.addMouseListener(new java.awt.event.MouseAdapter() {
×
313
            public void mouseClicked(java.awt.event.MouseEvent evt) {
314
                tblAclMouseClicked(evt);
×
315
            }
×
316
        });
317
        jScrollPane3.setViewportView(tblAcl);
×
318

319
        btnSave.setText("Save");
×
320
        btnSave.addActionListener(this::btnSaveActionPerformed);
×
321

322
        btnClose.setText("Close");
×
323
        btnClose.addActionListener(this::btnCloseActionPerformed);
×
324

325
        btnAddAce.setText("Add Access Control Entry...");
×
326
        btnAddAce.addActionListener(this::btnAddAceActionPerformed);
×
327

328
        lblDigest.setText("Digest:");
×
329

330
        lblDigestAlgorithmValue.setText("<digest algorithm>");
×
331

332
        txtDigest.setEditable(false);
×
333
        txtDigest.setColumns(20);
×
334
        txtDigest.setLineWrap(true);
×
335
        txtDigest.setRows(5);
×
336
        txtDigest.setBorder(javax.swing.BorderFactory.createEtchedBorder());
×
337
        spDigest.setViewportView(txtDigest);
×
338

339
        lblSize.setText("Size:");
×
340

341
        lblSizeValue.setText("<size>");
×
342

343
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
×
344
        getContentPane().setLayout(layout);
×
345
        layout.setHorizontalGroup(
×
346
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
347
            .addGroup(layout.createSequentialGroup()
×
348
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
×
349
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
×
350
                        .addContainerGap()
×
351
                        .addComponent(jSeparator1))
×
352
                    .addGroup(layout.createSequentialGroup()
×
353
                        .addGap(25, 25, 25)
×
354
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
355
                            .addComponent(lblAccessControlList)
×
356
                            .addComponent(btnAddAce)
×
357
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
×
358
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
×
359
                            .addComponent(lblBasePermissions)
×
360
                            .addComponent(spDigest, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
×
361
                            .addGroup(layout.createSequentialGroup()
×
362
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
363
                                    .addComponent(lblResource)
×
364
                                    .addComponent(lblInternetMediaType)
×
365
                                    .addComponent(lblOwner)
×
366
                                    .addComponent(lblLastModified)
×
367
                                    .addComponent(lblCreated)
×
368
                                    .addComponent(lblGroup)
×
369
                                    .addComponent(lblSize)
×
370
                                    .addComponent(lblDigest))
×
371
                                .addGap(28, 28, 28)
×
372
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
373
                                    .addComponent(lblDigestAlgorithmValue, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
×
374
                                    .addComponent(lblSizeValue)
×
375
                                    .addGroup(layout.createSequentialGroup()
×
376
                                        .addComponent(lblGroupValue, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
×
377
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
378
                                        .addComponent(btnChangeGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
×
379
                                    .addGroup(layout.createSequentialGroup()
×
380
                                        .addComponent(lblOwnerValue, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
×
381
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
382
                                        .addComponent(btnChangeOwner, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
×
383
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
×
384
                                        .addComponent(lblResourceValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
×
385
                                        .addComponent(lblInternetMediaTypeValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
×
386
                                        .addComponent(lblCreatedValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
×
387
                                        .addComponent(lblLastModifiedValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))))
×
388
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
×
389
            .addGroup(layout.createSequentialGroup()
×
390
                .addContainerGap()
×
391
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
×
392
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
×
393
                    .addGroup(layout.createSequentialGroup()
×
394
                        .addComponent(btnClose)
×
395
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
396
                        .addComponent(btnSave)))
×
397
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
×
398
        );
399
        layout.setVerticalGroup(
×
400
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
401
            .addGroup(layout.createSequentialGroup()
×
402
                .addGap(17, 17, 17)
×
403
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
404
                    .addComponent(lblResource)
×
405
                    .addComponent(lblResourceValue))
×
406
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
407
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
408
                    .addComponent(lblInternetMediaType)
×
409
                    .addComponent(lblInternetMediaTypeValue))
×
410
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
411
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
412
                    .addComponent(lblCreated)
×
413
                    .addComponent(lblCreatedValue))
×
414
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
415
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
416
                    .addComponent(lblLastModified)
×
417
                    .addComponent(lblLastModifiedValue))
×
418
                .addGap(12, 12, 12)
×
419
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
420
                    .addComponent(lblSize)
×
421
                    .addComponent(lblSizeValue))
×
422
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
423
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
424
                    .addComponent(lblDigest)
×
425
                    .addComponent(lblDigestAlgorithmValue))
×
426
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
427
                .addComponent(spDigest, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
×
428
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
429
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
×
430
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
431
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
432
                    .addComponent(lblOwner)
×
433
                    .addComponent(lblOwnerValue)
×
434
                    .addComponent(btnChangeOwner, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
×
435
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
×
436
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
437
                    .addComponent(lblGroup)
×
438
                    .addComponent(lblGroupValue)
×
439
                    .addComponent(btnChangeGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
×
440
                .addGap(18, 18, 18)
×
441
                .addComponent(lblBasePermissions)
×
442
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
443
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
×
444
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
445
                .addComponent(lblAccessControlList)
×
446
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
447
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
×
448
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
449
                .addComponent(btnAddAce)
×
450
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
451
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
×
452
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
453
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
454
                    .addComponent(btnClose)
×
455
                    .addComponent(btnSave))
×
456
                .addContainerGap())
×
457
        );
458

459
        pack();
×
460
    }// </editor-fold>//GEN-END:initComponents
×
461

462
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
463
        
464
        try {
465

466
            for (final ResourceDescriptor desc : applyTo) {
×
467

468
                final String newOwner;
469
                if (MULTIPLE_INDICATOR.equals(lblOwnerValue.getText()) || desc.getOwner().equals(lblOwnerValue.getText())) {
×
470
                    newOwner = desc.getOwner();
×
471
                } else {
×
472
                    newOwner = lblOwnerValue.getText();
×
473
                }
474

475
                final String newGroup;
476
                if (MULTIPLE_INDICATOR.equals(lblGroupValue.getText()) || desc.getGroup().equals(lblGroupValue.getText())) {
×
477
                    newGroup = desc.getGroup();
×
478
                } else {
×
479
                    newGroup = lblGroupValue.getText();
×
480
                }
481

482
                final Permission existingPermission = desc.getPermissions();
×
483
                final ModeDisplay modeChanges = getBasicPermissionsTableModel().getMode();
×
484
                final Permission updatedPermission = getUpdatedPermission(existingPermission, modeChanges);
×
485

486
                final List<ACEAider> dlgAces = new ArrayList<>();
×
487
                if (acl == null) {
×
488
                    if (existingPermission instanceof ACLPermission existingAclPermission) {
×
489
                        for (int i = 0; i < existingAclPermission.getACECount(); i++) {
×
490
                            dlgAces.add(new ACEAider(existingAclPermission.getACEAccessType(i), existingAclPermission.getACETarget(i), existingAclPermission.getACEWho(i), existingAclPermission.getACEMode(i)));
×
491
                        }
492
                    }
493
                } else {
×
494
                    for (int i = 0; i < tblAcl.getRowCount(); i++) {
×
495
                        final ACLPermission.ACE_TARGET target = ACLPermission.ACE_TARGET.valueOf((String) getAclTableModel().getValueAt(i, 0));
×
496
                        final String who = (String) getAclTableModel().getValueAt(i, 1);
×
497
                        final ACLPermission.ACE_ACCESS_TYPE access = ACLPermission.ACE_ACCESS_TYPE.valueOf((String) getAclTableModel().getValueAt(i, 2));
×
498
                        int mode = 0;
×
499
                        if ((Boolean) tblAcl.getValueAt(i, 3)) {
×
500
                            mode |= Permission.READ;
×
501
                        }
502
                        if ((Boolean) tblAcl.getValueAt(i, 4)) {
×
503
                            mode |= Permission.WRITE;
×
504
                        }
505
                        if ((Boolean) tblAcl.getValueAt(i, 5)) {
×
506
                            mode |= Permission.EXECUTE;
×
507
                        }
508

509
                        dlgAces.add(new ACEAider(access, target, who, mode));
×
510
                    }
511
                }
512

513
                if (desc.isCollection()) {
×
514
                    final Collection coll = parent.getChildCollection(desc.getName().toString());
×
515
                    getUserManagementService().setPermissions(coll, newOwner, newGroup, updatedPermission.getMode(), dlgAces);
×
516
                } else {
×
517
                    final Resource res = parent.getResource(desc.getName().toString());
×
518
                    getUserManagementService().setPermissions(res, newOwner, newGroup, updatedPermission.getMode(), dlgAces);
×
519
                }
520
            }
521

522
            setVisible(false);
×
523
            dispose();
×
524
        } catch(final PermissionDeniedException | XMLDBException e) {
×
525
            JOptionPane.showMessageDialog(this, "Could not update properties: " + e.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
526
        }
527
    }//GEN-LAST:event_btnSaveActionPerformed
×
528

529
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
530
        setVisible(false);
×
531
        dispose();
×
532
    }//GEN-LAST:event_btnCloseActionPerformed
×
533

534
    private void btnChangeOwnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeOwnerActionPerformed
535
        final DialogCompleteWithResponse<String> callback = username -> lblOwnerValue.setText(username);
×
536
        
537
        try {
538
            final FindUserForm findUserForm = new FindUserForm(getUserManagementService());
×
539
            findUserForm.addDialogCompleteWithResponseCallback(callback);
×
540
            findUserForm.setTitle("Change Owner...");
×
541
            findUserForm.setVisible(true);
×
542
        } catch(final XMLDBException xmldbe) {
×
543
            JOptionPane.showMessageDialog(this, "Could not retrieve list of users: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
544
        }
545
    }//GEN-LAST:event_btnChangeOwnerActionPerformed
×
546

547
    private void btnChangeGroupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeGroupActionPerformed
548
        final DialogCompleteWithResponse<String> callback = groupName -> lblGroupValue.setText(groupName);
×
549
        
550
        try {
551
            final FindGroupForm findGroupForm = new FindGroupForm(getUserManagementService());
×
552
            findGroupForm.addDialogCompleteWithResponseCallback(callback);
×
553
            findGroupForm.setTitle("Change Group...");
×
554
            findGroupForm.setVisible(true);
×
555
        } catch(final XMLDBException xmldbe) {
×
556
            JOptionPane.showMessageDialog(this, "Could not retrieve list of groups: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
557
        }
558
    }//GEN-LAST:event_btnChangeGroupActionPerformed
×
559

560
    private void miRemoveAceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miRemoveAceActionPerformed
561
        getAclTableModel().removeRow(tblAcl.getSelectedRow());
×
562
    }//GEN-LAST:event_miRemoveAceActionPerformed
×
563

564
    private void miMoveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMoveUpActionPerformed
565
        if(tblAcl.getSelectedRow() > 0) {
×
566
            getAclTableModel().moveRow(tblAcl.getSelectedRow(), tblAcl.getSelectedRow(), tblAcl.getSelectedRow() - 1);
×
567
        }
568
    }//GEN-LAST:event_miMoveUpActionPerformed
×
569

570
    private void miMoveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMoveDownActionPerformed
571
        if(tblAcl.getSelectedRow() < getAclTableModel().getRowCount() - 1) {
×
572
            getAclTableModel().moveRow(tblAcl.getSelectedRow(), tblAcl.getSelectedRow(), tblAcl.getSelectedRow() + 1);
×
573
        }
574
    }//GEN-LAST:event_miMoveDownActionPerformed
×
575

576
    private void btnAddAceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAceActionPerformed
577
        
578
        final DialogCompleteWithResponse<ACEAider> callback = ace -> getAclTableModel().addRow(new Object[]{
×
579
            ace.getTarget().toString(),
×
580
            ace.getWho(),
×
581
            ace.getAccessType().toString(),
×
582
            (ace.getMode() & Permission.READ) == Permission.READ,
×
583
            (ace.getMode() & Permission.WRITE) == Permission.WRITE,
×
584
            (ace.getMode() & Permission.EXECUTE) == Permission.EXECUTE,
×
585
        });
×
586
        
587
        try {
588
            final AccessControlEntryDialog aceDialog = new AccessControlEntryDialog(getUserManagementService(), "Create Access Control Entry");
×
589
            aceDialog.addDialogCompleteWithResponseCallback(callback);
×
590
            aceDialog.setVisible(true);
×
591
        } catch(final XMLDBException xmldbe) {
×
592
            JOptionPane.showMessageDialog(this, "Could not get user/group members: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
593
        }
594
    }//GEN-LAST:event_btnAddAceActionPerformed
×
595

596
    private void miInsertAceBeforeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miInsertAceBeforeActionPerformed
597
        final DialogCompleteWithResponse<ACEAider> callback = ace -> {
×
598
            final int insertAt = tblAcl.getSelectedRow();
×
599
            getAclTableModel().insertRow(insertAt, new Object[]{
×
600
                ace.getTarget().toString(),
×
601
                ace.getWho(),
×
602
                ace.getAccessType().toString(),
×
603
                (ace.getMode() & Permission.READ) == Permission.READ,
×
604
                (ace.getMode() & Permission.WRITE) == Permission.WRITE,
×
605
                (ace.getMode() & Permission.EXECUTE) == Permission.EXECUTE,
×
606
            });
607
        };
×
608
        
609
        try {
610
            final AccessControlEntryDialog aceDialog = new AccessControlEntryDialog(getUserManagementService(), "Insert Access Control Entry (before...)");
×
611
            aceDialog.addDialogCompleteWithResponseCallback(callback);
×
612
            aceDialog.setVisible(true);
×
613
        } catch(final XMLDBException xmldbe) {
×
614
            JOptionPane.showMessageDialog(this, "Could not get user/group members: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
615
        }
616
    }//GEN-LAST:event_miInsertAceBeforeActionPerformed
×
617

618
    private void miInsertAceAfterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miInsertAceAfterActionPerformed
619
        final DialogCompleteWithResponse<ACEAider> callback = ace -> {
×
620
            final int insertAt = tblAcl.getSelectedRow() < getAclTableModel().getRowCount() - 1 ? tblAcl.getSelectedRow() + 1 : getAclTableModel().getRowCount();
×
621
            getAclTableModel().insertRow(insertAt, new Object[]{
×
622
                ace.getTarget().toString(),
×
623
                ace.getWho(),
×
624
                ace.getAccessType().toString(),
×
625
                (ace.getMode() & Permission.READ) == Permission.READ,
×
626
                (ace.getMode() & Permission.WRITE) == Permission.WRITE,
×
627
                (ace.getMode() & Permission.EXECUTE) == Permission.EXECUTE,
×
628
            });
629
        };
×
630
        
631
        try {
632
            final AccessControlEntryDialog aceDialog = new AccessControlEntryDialog(getUserManagementService(), "Insert Access Control Entry (after...)");
×
633
            aceDialog.addDialogCompleteWithResponseCallback(callback);
×
634
            aceDialog.setVisible(true);
×
635
        } catch(final XMLDBException xmldbe) {
×
636
            JOptionPane.showMessageDialog(this, "Could not get user/group members: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
637
        }
638
    }//GEN-LAST:event_miInsertAceAfterActionPerformed
×
639

640
    private Permission getUpdatedPermission(final Permission existingMode, final ModeDisplay modeChanges) throws PermissionDeniedException {
641
        final Permission newMode = existingMode.copy();
×
642
        modeChanges.writeToPermission(newMode);
×
643
        return newMode;
×
644
    }
645

646
    private boolean isDba() throws XMLDBException {
647
        final Set<String> dbaMembers = new HashSet<>(Arrays.asList(getUserManagementService().getGroupMembers(SecurityManager.DBA_GROUP)));
×
648
        return dbaMembers.contains(currentUser);
×
649
    }
650
    
651
    private boolean canModifyPermissions() throws XMLDBException {
652
        return isDba() || owner.equals(currentUser);
×
653
    }
654
    
655
    private void tblAclMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAclMouseClicked
656
        final boolean aclSelected = tblAcl.getSelectedRow() > -1;
×
657
        try {
658
            final boolean canModify = canModifyPermissions();
×
659
        
660
            miInsertAceBefore.setEnabled(canModify);
×
661
            miInsertAceAfter.setEnabled(canModify);
×
662
        
663
            miMoveUp.setEnabled(canModify && aclSelected);
×
664
            miMoveDown.setEnabled(canModify && aclSelected);
×
665
        
666
            miRemoveAce.setEnabled(canModify && aclSelected);
×
667
        } catch(final XMLDBException xmldbe) {
×
668
            JOptionPane.showMessageDialog(this, "Could not get dba group members: " + xmldbe.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
×
669
        }
670
    }//GEN-LAST:event_tblAclMouseClicked
×
671

672
    // Variables declaration - do not modify//GEN-BEGIN:variables
673
    private javax.swing.JButton btnAddAce;
674
    private javax.swing.JButton btnChangeGroup;
675
    private javax.swing.JButton btnChangeOwner;
676
    private javax.swing.JButton btnClose;
677
    private javax.swing.JButton btnSave;
678
    private javax.swing.JScrollPane jScrollPane1;
679
    private javax.swing.JScrollPane jScrollPane2;
680
    private javax.swing.JScrollPane jScrollPane3;
681
    private javax.swing.JSeparator jSeparator1;
682
    private javax.swing.JSeparator jSeparator2;
683
    private javax.swing.JPopupMenu.Separator jSeparator3;
684
    private javax.swing.JPopupMenu.Separator jSeparator4;
685
    private javax.swing.JTextArea jTextArea1;
686
    private javax.swing.JLabel lblAccessControlList;
687
    private javax.swing.JLabel lblBasePermissions;
688
    private javax.swing.JLabel lblCreated;
689
    private javax.swing.JLabel lblCreatedValue;
690
    private javax.swing.JLabel lblDigest;
691
    private javax.swing.JLabel lblDigestAlgorithmValue;
692
    private javax.swing.JLabel lblGroup;
693
    private javax.swing.JLabel lblGroupValue;
694
    private javax.swing.JLabel lblInternetMediaType;
695
    private javax.swing.JLabel lblInternetMediaTypeValue;
696
    private javax.swing.JLabel lblLastModified;
697
    private javax.swing.JLabel lblLastModifiedValue;
698
    private javax.swing.JLabel lblOwner;
699
    private javax.swing.JLabel lblOwnerValue;
700
    private javax.swing.JLabel lblResource;
701
    private javax.swing.JLabel lblResourceValue;
702
    private javax.swing.JLabel lblSize;
703
    private javax.swing.JLabel lblSizeValue;
704
    private javax.swing.JMenuItem miInsertAceAfter;
705
    private javax.swing.JMenuItem miInsertAceBefore;
706
    private javax.swing.JMenuItem miMoveDown;
707
    private javax.swing.JMenuItem miMoveUp;
708
    private javax.swing.JMenuItem miRemoveAce;
709
    private javax.swing.JPopupMenu pmAcl;
710
    private javax.swing.JScrollPane spDigest;
711
    private javax.swing.JTable tblAcl;
712
    private javax.swing.JTable tblBasePermissions;
713
    private javax.swing.JTextArea txtDigest;
714
    // End of variables declaration//GEN-END:variables
715
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc