Search in sources :

Example 1 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class EditGroupDialog method setGroupFromFormProperties.

private void setGroupFromFormProperties() throws PermissionDeniedException, XMLDBException {
    getGroup().setMetadataValue(EXistSchemaType.DESCRIPTION, txtDescription.getText());
    // set managers
    // 1) remove all managers
    final List<Account> currentManagers = getGroup().getManagers();
    for (final Account currentManager : currentManagers) {
        getUserManagementService().removeGroupManager(group.getName(), currentManager.getName());
    }
    // 2) only add those in this dialog
    for (int i = 0; i < getGroupMembersTableModel().getRowCount(); i++) {
        final boolean isManager = (Boolean) getGroupMembersTableModel().getValueAt(i, 1);
        if (isManager) {
            final String manager = (String) getGroupMembersTableModel().getValueAt(i, 0);
            getUserManagementService().addGroupManager(manager, getGroup().getName());
        }
    }
}
Also used : Account(org.exist.security.Account)

Example 2 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class UserManagerDialog method refreshUsersTableModel.

public void refreshUsersTableModel() {
    final int rowCount = usersTableModel.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        usersTableModel.removeRow(0);
    }
    try {
        final Account[] accounts = userManagementService.getAccounts();
        Arrays.sort(accounts, new AccountComparator());
        for (Account account : accounts) {
            usersTableModel.addRow(new String[] { account.getName(), account.getMetadataValue(AXSchemaType.FULLNAME), account.getMetadataValue(EXistSchemaType.DESCRIPTION) });
        }
    } catch (final XMLDBException xmldbe) {
        JOptionPane.showMessageDialog(this, "Could not get users list: " + xmldbe.getMessage(), "User Manager Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) AccountComparator(org.exist.security.AccountComparator)

Example 3 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class UserManagerDialog method showEditUserDialog.

private void showEditUserDialog(final Account account) {
    final UserManagerDialog that = this;
    final DialogCompleteWithResponse<String> callback = response -> {
        // get client to reconnect with edited users new password
        try {
            System.out.println("Detected logged-in user password change, reconnecting to server...");
            that.userManagementService = reconnectClientAndUserManager(response);
            System.out.println("Reconnected.");
        } catch (final XMLDBException xmldbe) {
            JOptionPane.showMessageDialog(that, "Could not edit user '" + getSelectedUsername() + "': " + xmldbe.getMessage(), "User Manager Error", JOptionPane.ERROR_MESSAGE);
        }
    };
    final EditUserDialog userDialog = new EditUserDialog(userManagementService, account);
    if (getSelectedUsername().equals(currentUser)) {
        // register for password update event, if we are changing the password
        // of the current user
        userDialog.addDialogCompleteWithResponseCallback(callback);
    }
    userDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(final WindowEvent e) {
            refreshUsersTableModel();
        }
    });
    userDialog.setVisible(true);
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) Arrays(java.util.Arrays) Properties(java.util.Properties) HighlightedTableCellRenderer(org.exist.client.HighlightedTableCellRenderer) DefaultTableModel(javax.swing.table.DefaultTableModel) Group(org.exist.security.Group) AXSchemaType(org.exist.security.AXSchemaType) AccountComparator(org.exist.security.AccountComparator) DialogCompleteWithResponse(org.exist.client.DialogCompleteWithResponse) WindowAdapter(java.awt.event.WindowAdapter) JOptionPane(javax.swing.JOptionPane) WindowEvent(java.awt.event.WindowEvent) EXistSchemaType(org.exist.security.EXistSchemaType) Account(org.exist.security.Account) SecurityManager(org.exist.security.SecurityManager) InteractiveClient(org.exist.client.InteractiveClient) ClientFrame(org.exist.client.ClientFrame) UserManagementService(org.exist.xmldb.UserManagementService) TableModel(javax.swing.table.TableModel) WindowEvent(java.awt.event.WindowEvent) XMLDBException(org.xmldb.api.base.XMLDBException) WindowAdapter(java.awt.event.WindowAdapter)

Example 4 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class UserManagerDialog method tblUsersMouseClicked.

// GEN-LAST:event_btnCreateActionPerformed
private void tblUsersMouseClicked(java.awt.event.MouseEvent evt) {
    // GEN-FIRST:event_tblUsersMouseClicked
    final boolean userSelected = tblUsers.getSelectedRow() > -1;
    final String selectedUsername = getSelectedUsername();
    boolean canModify = userSelected && !selectedUsername.equals(SecurityManager.SYSTEM);
    boolean canDelete = userSelected && !(selectedUsername.equals(SecurityManager.SYSTEM) || selectedUsername.equals(SecurityManager.DBA_USER) || selectedUsername.equals(SecurityManager.GUEST_USER));
    miEditUser.setEnabled(canModify);
    miRemoveUser.setEnabled(canDelete);
    if (evt.getClickCount() == 2 && canModify) {
        try {
            final Account account = userManagementService.getAccount(selectedUsername);
            showEditUserDialog(account);
        } catch (final XMLDBException xmldbe) {
            JOptionPane.showMessageDialog(this, "Could not edit user '" + selectedUsername + "': " + xmldbe.getMessage(), "User Manager Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 5 with Account

use of org.exist.security.Account in project exist by eXist-db.

the class UserManagerDialog method miEditUserActionPerformed.

// GEN-LAST:event_miRemoveUserActionPerformed
private void miEditUserActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_miEditUserActionPerformed
    final String selectedUsername = getSelectedUsername();
    try {
        final Account account = userManagementService.getAccount(selectedUsername);
        showEditUserDialog(account);
    } catch (final XMLDBException xmldbe) {
        JOptionPane.showMessageDialog(this, "Could not edit user '" + selectedUsername + "': " + xmldbe.getMessage(), "User Manager Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException)

Aggregations

Account (org.exist.security.Account)60 PermissionDeniedException (org.exist.security.PermissionDeniedException)18 SecurityManager (org.exist.security.SecurityManager)17 EXistException (org.exist.EXistException)12 XMLDBException (org.xmldb.api.base.XMLDBException)11 Group (org.exist.security.Group)10 Collection (org.xmldb.api.base.Collection)10 AuthenticationException (org.exist.security.AuthenticationException)9 DBBroker (org.exist.storage.DBBroker)9 AbstractAccount (org.exist.security.AbstractAccount)7 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)7 Txn (org.exist.storage.txn.Txn)6 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 Subject (org.exist.security.Subject)5 UserAider (org.exist.security.internal.aider.UserAider)5 UserManagementService (org.exist.xmldb.UserManagementService)5 Permission (org.exist.security.Permission)4 XPathException (org.exist.xquery.XPathException)4 Before (org.junit.Before)4 Test (org.junit.Test)4