• 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/AccessControlEntryDialog.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.*;
52
import javax.swing.ComboBoxModel;
53
import javax.swing.DefaultComboBoxModel;
54
import javax.swing.table.DefaultTableModel;
55
import org.exist.client.DialogCompleteWithResponse;
56
import org.exist.client.DialogWithResponse;
57
import org.exist.client.InteractiveClient;
58
import org.exist.security.ACLPermission.ACE_ACCESS_TYPE;
59
import org.exist.security.ACLPermission.ACE_TARGET;
60
import org.exist.security.Account;
61
import org.exist.security.Permission;
62
import org.exist.security.internal.aider.ACEAider;
63
import org.exist.xmldb.UserManagementService;
64
import org.xmldb.api.base.XMLDBException;
65

66
/**
67
 *
68
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
69
 */
70
public class AccessControlEntryDialog extends javax.swing.JFrame implements DialogWithResponse<ACEAider> {
71
    
72
    private final UserManagementService userManagementService;
73
    
74
    private DefaultTableModel permissionTableModel = null;
×
75
    private DefaultComboBoxModel<String> usernameModel;
76
    private final Set<String> allUsernames;
77
    private DefaultComboBoxModel<String> groupNameModel = null;
×
78
    private final Set<String> allGroupNames;
79
    private final List<DialogCompleteWithResponse<ACEAider>> dialogCompleteWithResponseCallbacks = new ArrayList<>();
×
80

81
    public AccessControlEntryDialog(final UserManagementService userManagementService, final String title) throws XMLDBException {
×
82
        this.userManagementService = userManagementService;
×
83
        this.setIconImage(InteractiveClient.getElementalIcon(getClass()).getImage());
×
84
        allUsernames = new HashSet<>();
×
85
        for(final Account account : userManagementService.getAccounts()) {
×
86
            allUsernames.add(account.getName());
×
87
        }
88
        
89
        allGroupNames = new HashSet<>();
×
90
        allGroupNames.addAll(Arrays.asList(userManagementService.getGroups()));
×
91
        
92
        initComponents();
×
93
        setTitle(title);
×
94
    }
×
95
    
96
    private DefaultTableModel getPermissionTableModel() {
97
        if(permissionTableModel == null) {
×
98
            permissionTableModel = new DefaultTableModel(
×
99
                new Object[][]{
×
100
                    new Object[]{false, false, false}
×
101
                },
102
                new String[] { "Read", "Write", "Execute" }
×
103
            ){
104
                @Override
105
                public Class getColumnClass(int columnIndex) {
106
                    return Boolean.class;
×
107
                }
108

109
                @Override
110
                public boolean isCellEditable(int rowIndex, int columnIndex) {
111
                    return true;
×
112
                }
113
            };
114
        }
115
        
116
        return permissionTableModel;
×
117
    }
118
    
119
    private ComboBoxModel<String> getUsernameModel() {
120
        if(usernameModel == null) {
×
121
            usernameModel = new DefaultComboBoxModel<>();
×
122
            usernameModel.addElement("");
×
123
            for(final String username : allUsernames) {
×
124
               usernameModel.addElement(username);
×
125
            }
126
        }
127
        
128
        return usernameModel;
×
129
    }
130
    
131
    private ComboBoxModel<String> getGroupNameModel() {
132
        if(groupNameModel == null) {
×
133
            groupNameModel = new DefaultComboBoxModel<>();
×
134
            groupNameModel.addElement("");
×
135
            for(final String groupName : allGroupNames) {
×
136
               groupNameModel.addElement(groupName);
×
137
            }
138
        }
139
        
140
        return groupNameModel;
×
141
    }
142
    
143
    private boolean isValidUsername(final String username) {
144
        return allUsernames.contains(username);
×
145
    }
146
    
147
    private boolean isValidGroupName(final String groupName) {
148
        return allGroupNames.contains(groupName);
×
149
    }
150

151
    /**
152
     * This method is called from within the constructor to initialize the form.
153
     * WARNING: Do NOT modify this code. The content of this method is always
154
     * regenerated by the Form Editor.
155
     */
156
    @SuppressWarnings("unchecked")
157
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
158
    private void initComponents() {
159

160
        lblTarget = new javax.swing.JLabel();
×
161
        cmbTarget = new javax.swing.JComboBox();
×
162
        lblUsername = new javax.swing.JLabel();
×
163
        cmbUsername = new javax.swing.JComboBox<>();
×
164
        AutoCompletion.enable(cmbUsername);
×
165
        lblGroupName = new javax.swing.JLabel();
×
166
        cmbGroupName = new javax.swing.JComboBox<>();
×
167
        AutoCompletion.enable(cmbGroupName);
×
168
        lblAccess = new javax.swing.JLabel();
×
169
        cmbAccess = new javax.swing.JComboBox();
×
170
        lblPermission = new javax.swing.JLabel();
×
171
        jScrollPane1 = new javax.swing.JScrollPane();
×
172
        tblPermission = new javax.swing.JTable();
×
173
        jSeparator1 = new javax.swing.JSeparator();
×
174
        btnCreate = new javax.swing.JButton();
×
175
        btnClose = new javax.swing.JButton();
×
176

177
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
×
178

179
        lblTarget.setText("Target:");
×
180

181
        cmbTarget.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "USER", "GROUP" }));
×
182
        cmbTarget.addActionListener(this::cmbTargetActionPerformed);
×
183

184
        lblUsername.setText("Username:");
×
185

186
        cmbUsername.setEditable(true);
×
187
        cmbUsername.setModel(getUsernameModel());
×
188
        cmbUsername.addActionListener(this::cmbUsernameActionPerformed);
×
189

190
        lblGroupName.setText("Group:");
×
191

192
        cmbGroupName.setEditable(true);
×
193
        cmbGroupName.setModel(getGroupNameModel());
×
194
        cmbGroupName.setEnabled(false);
×
195
        cmbGroupName.addActionListener(this::cmbGroupNameActionPerformed);
×
196

197
        lblAccess.setText("Access:");
×
198

199
        cmbAccess.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALLOWED", "DENIED" }));
×
200

201
        lblPermission.setText("Permission");
×
202

203
        tblPermission.setModel(getPermissionTableModel());
×
204
        tblPermission.setRowSelectionAllowed(false);
×
205
        jScrollPane1.setViewportView(tblPermission);
×
206

207
        btnCreate.setText("Create");
×
208
        btnCreate.addActionListener(this::btnCreateActionPerformed);
×
209

210
        btnClose.setText("Close");
×
211
        btnClose.addActionListener(this::btnCloseActionPerformed);
×
212

213
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
×
214
        getContentPane().setLayout(layout);
×
215
        layout.setHorizontalGroup(
×
216
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
217
            .addGroup(layout.createSequentialGroup()
×
218
                .addGap(25, 25, 25)
×
219
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
220
                    .addGroup(layout.createSequentialGroup()
×
221
                        .addGap(6, 6, 6)
×
222
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE))
×
223
                    .addComponent(lblPermission)
×
224
                    .addGroup(layout.createSequentialGroup()
×
225
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
226
                            .addComponent(lblUsername)
×
227
                            .addComponent(lblTarget)
×
228
                            .addComponent(lblGroupName)
×
229
                            .addComponent(lblAccess))
×
230
                        .addGap(28, 28, 28)
×
231
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
232
                            .addComponent(cmbAccess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
233
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
×
234
                                .addComponent(cmbTarget, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
235
                                .addComponent(cmbUsername, 0, 257, Short.MAX_VALUE)
×
236
                                .addComponent(cmbGroupName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
×
237
                .addContainerGap(24, Short.MAX_VALUE))
×
238
            .addGroup(layout.createSequentialGroup()
×
239
                .addContainerGap()
×
240
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
241
                    .addComponent(jSeparator1)
×
242
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
×
243
                        .addGap(0, 0, Short.MAX_VALUE)
×
244
                        .addComponent(btnClose)
×
245
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
246
                        .addComponent(btnCreate)))
×
247
                .addContainerGap())
×
248
        );
249
        layout.setVerticalGroup(
×
250
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
251
            .addGroup(layout.createSequentialGroup()
×
252
                .addGap(17, 17, 17)
×
253
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
254
                    .addComponent(lblTarget)
×
255
                    .addComponent(cmbTarget, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
256
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
257
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
258
                    .addComponent(lblUsername)
×
259
                    .addComponent(cmbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
260
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
261
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
262
                    .addComponent(lblGroupName)
×
263
                    .addComponent(cmbGroupName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
264
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
265
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
266
                    .addComponent(cmbAccess, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
267
                    .addComponent(lblAccess))
×
268
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
269
                .addComponent(lblPermission)
×
270
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
271
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
×
272
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
×
273
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
×
274
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
275
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
276
                    .addComponent(btnCreate)
×
277
                    .addComponent(btnClose))
×
278
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
×
279
        );
280

281
        pack();
×
282
    }// </editor-fold>//GEN-END:initComponents
×
283

284
    private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateActionPerformed
285

286
        final ACE_TARGET target = ACE_TARGET.valueOf((String)cmbTarget.getSelectedItem());
×
287
        final String who;
288
        if(target == ACE_TARGET.USER) {
×
289
            who =(String)cmbUsername.getSelectedItem();
×
290
            if(!isValidUsername(who)) {
×
291
                return;
×
292
            }
293
        } else {
294
            who = (String)cmbGroupName.getSelectedItem();
×
295
            if(!isValidGroupName(who)) {
×
296
                return;
×
297
            }
298
        }
299
        
300
        final ACE_ACCESS_TYPE accessType = ACE_ACCESS_TYPE.valueOf((String)cmbAccess.getSelectedItem());
×
301
        int mode = 0;
×
302
        if((Boolean)tblPermission.getValueAt(0, 0)) {
×
303
            mode |= Permission.READ;
×
304
        }
305
        if((Boolean)tblPermission.getValueAt(0, 1)) {
×
306
            mode |= Permission.WRITE;
×
307
        }
308
        if((Boolean)tblPermission.getValueAt(0, 2)) {
×
309
            mode |= Permission.EXECUTE;
×
310
        }
311
        
312
        final ACEAider ace = new ACEAider(accessType, target, who, mode);
×
313
        for(final DialogCompleteWithResponse<ACEAider> callback : getDialogCompleteWithResponseCallbacks()) {
×
314
            callback.complete(ace);
×
315
        }
316
        
317
        setVisible(false);
×
318
        dispose();
×
319
    }//GEN-LAST:event_btnCreateActionPerformed
×
320

321
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
322
        setVisible(false);
×
323
        dispose();
×
324
    }//GEN-LAST:event_btnCloseActionPerformed
×
325

326
    private void cmbTargetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTargetActionPerformed
327
        final ACE_TARGET aceTarget = ACE_TARGET.valueOf((String)cmbTarget.getSelectedItem());
×
328
        switch(aceTarget) {
×
329
            case USER:
330
                cmbGroupName.setEnabled(false);
×
331
                cmbUsername.setEnabled(true);
×
332
                break;
×
333
                
334
            case GROUP:
335
                cmbUsername.setEnabled(false);
×
336
                cmbGroupName.setEnabled(true);
×
337
                break;
338
        }
339
    }//GEN-LAST:event_cmbTargetActionPerformed
×
340

341
    private void cmbUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbUsernameActionPerformed
342
        final String currentUsername = (String)cmbUsername.getSelectedItem();
×
343
        final boolean isValid = isValidUsername(currentUsername);
×
344
        btnCreate.setEnabled(isValid);
×
345
    }//GEN-LAST:event_cmbUsernameActionPerformed
×
346

347
    private void cmbGroupNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbGroupNameActionPerformed
348
        final String currentGroupName = (String)cmbGroupName.getSelectedItem();
×
349
        final boolean isValid = isValidGroupName(currentGroupName);
×
350
        btnCreate.setEnabled(isValid);
×
351
    }//GEN-LAST:event_cmbGroupNameActionPerformed
×
352

353
    // Variables declaration - do not modify//GEN-BEGIN:variables
354
    private javax.swing.JButton btnClose;
355
    private javax.swing.JButton btnCreate;
356
    private javax.swing.JComboBox cmbAccess;
357
    private javax.swing.JComboBox<String> cmbGroupName;
358
    private javax.swing.JComboBox cmbTarget;
359
    private javax.swing.JComboBox<String> cmbUsername;
360
    private javax.swing.JScrollPane jScrollPane1;
361
    private javax.swing.JSeparator jSeparator1;
362
    private javax.swing.JLabel lblAccess;
363
    private javax.swing.JLabel lblGroupName;
364
    private javax.swing.JLabel lblPermission;
365
    private javax.swing.JLabel lblTarget;
366
    private javax.swing.JLabel lblUsername;
367
    private javax.swing.JTable tblPermission;
368
    // End of variables declaration//GEN-END:variables
369

370
    private List<DialogCompleteWithResponse<ACEAider>> getDialogCompleteWithResponseCallbacks() {
371
        return dialogCompleteWithResponseCallbacks;
×
372
    }
373
    
374
    @Override
375
    public void addDialogCompleteWithResponseCallback(final DialogCompleteWithResponse<ACEAider> dialogCompleteWithResponseCallback) {
376
        getDialogCompleteWithResponseCallbacks().add(dialogCompleteWithResponseCallback);
×
377
    }
×
378
}
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