Search in sources :

Example 1 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class InteractiveClient method getResources.

/**
 * Get list of resources contained in collection.
 *
 * @throws XMLDBException Description of the Exception
 */
protected void getResources() throws XMLDBException {
    if (current == null) {
        return;
    }
    setProperties();
    final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
    final String[] childCollections = current.listChildCollections();
    final String[] childResources = current.listResources();
    resources = new String[childCollections.length + childResources.length];
    // Collection child;
    Permission perm;
    // A list of ResourceDescriptor for the GUI
    final List<ResourceDescriptor> tableData = new ArrayList<>(resources.length);
    int i = 0;
    for (; i < childCollections.length; i++) {
        // child = current.getChildCollection(childCollections[i]);
        perm = mgtService.getSubCollectionPermissions(current, childCollections[i]);
        final Date created = mgtService.getSubCollectionCreationTime(current, childCollections[i]);
        if ("true".equals(properties.getProperty(PERMISSIONS))) {
            resources[i] = 'c' + perm.toString() + '\t' + getOwnerName(perm) + '\t' + getGroupName(perm) + '\t' + created.toString() + '\t' + childCollections[i];
        } else {
            resources[i] = childCollections[i];
        }
        if (options.startGUI) {
            try {
                tableData.add(new ResourceDescriptor.Collection(XmldbURI.xmldbUriFor(childCollections[i]), perm, created));
            } catch (final URISyntaxException e) {
                errorln("could not parse collection name into a valid URI: " + e.getMessage());
            }
        }
        completitions.add(childCollections[i]);
    }
    Resource res;
    for (int j = 0; j < childResources.length; i++, j++) {
        res = current.getResource(childResources[j]);
        perm = mgtService.getPermissions(res);
        if (perm == null) {
            // TODO this is not useful!
            System.out.println("null");
        }
        final Date lastModificationTime = ((EXistResource) res).getLastModificationTime();
        if ("true".equals(properties.getProperty(PERMISSIONS))) {
            resources[i] = '-' + perm.toString() + '\t' + getOwnerName(perm) + '\t' + getGroupName(perm) + '\t' + lastModificationTime.toString() + '\t' + childResources[j];
        } else {
            resources[i] = childResources[j];
        }
        if (options.startGUI) {
            try {
                tableData.add(new ResourceDescriptor.Document(XmldbURI.xmldbUriFor(childResources[j]), perm, lastModificationTime));
            } catch (final URISyntaxException e) {
                errorln("could not parse document name into a valid URI: " + e.getMessage());
            }
        }
        completitions.add(childResources[j]);
    }
    if (options.startGUI) {
        frame.setResources(tableData);
    }
}
Also used : ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryResource(org.xmldb.api.modules.BinaryResource) EXistResource(org.exist.xmldb.EXistResource) UserManagementService(org.exist.xmldb.UserManagementService) URISyntaxException(java.net.URISyntaxException) EXistResource(org.exist.xmldb.EXistResource) ACLPermission(org.exist.security.ACLPermission) Permission(org.exist.security.Permission)

Example 2 with UserManagementService

use of org.exist.xmldb.UserManagementService 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 3 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class DocumentView method unlockView.

private void unlockView() {
    if (readOnly) {
        return;
    }
    try {
        final UserManagementService service = (UserManagementService) collection.getService("UserManagementService", // $NON-NLS-1$ //$NON-NLS-2$
        "1.0");
        service.unlockResource(resource);
    } catch (final XMLDBException e) {
        e.printStackTrace();
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 4 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class DocumentView method viewDocument.

public void viewDocument() {
    try {
        if (// $NON-NLS-1$
        "XMLResource".equals(resource.getResourceType())) {
            setText((String) resource.getContent());
        } else {
            setText(new String((byte[]) resource.getContent()));
        }
        // lock the resource for editing
        final UserManagementService service = (UserManagementService) // $NON-NLS-1$ //$NON-NLS-2$
        client.current.getService("UserManagementService", "1.0");
        // $NON-NLS-1$
        final Account user = service.getAccount(properties.getProperty("user"));
        final String lockOwner = service.hasUserLock(resource);
        if (lockOwner != null) {
            if (JOptionPane.showConfirmDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.6") + lockOwner + // $NON-NLS-1$
            Messages.getString("DocumentView.7"), // $NON-NLS-1$
            Messages.getString("DocumentView.8"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                dispose();
                this.setCursor(Cursor.getDefaultCursor());
                return;
            }
        }
        try {
            service.lockResource(resource, user);
        } catch (final XMLDBException ex) {
            System.out.println(ex.getMessage());
            JOptionPane.showMessageDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.9"));
            setReadOnly();
        }
        setVisible(true);
    } catch (final XMLDBException ex) {
        // $NON-NLS-1$
        showErrorMessage(Messages.getString("DocumentView.10") + ex.getMessage(), ex);
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 5 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class AbstractXMLDBTask method setPermissions.

protected final void setPermissions(final Resource res) throws BuildException {
    Collection base = null;
    UserManagementService service = null;
    if (uri == null) {
        throw (new BuildException("you have to specify an XMLDB collection URI"));
    }
    try {
        log("Get base collection: " + uri, Project.MSG_DEBUG);
        base = DatabaseManager.getCollection(uri, user, password);
        if (base == null) {
            final String msg = "Collection " + uri + " could not be found.";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        } else {
            service = (UserManagementService) base.getService("UserManagementService", "1.0");
            setPermissions(res, service);
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService) BuildException(org.apache.tools.ant.BuildException)

Aggregations

UserManagementService (org.exist.xmldb.UserManagementService)106 Collection (org.xmldb.api.base.Collection)91 Test (org.junit.Test)79 BinaryResource (org.xmldb.api.modules.BinaryResource)55 Resource (org.xmldb.api.base.Resource)52 XMLResource (org.xmldb.api.modules.XMLResource)51 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)26 XMLDBException (org.xmldb.api.base.XMLDBException)15 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 UserAider (org.exist.security.internal.aider.UserAider)9 GroupAider (org.exist.security.internal.aider.GroupAider)8 ResourceSet (org.xmldb.api.base.ResourceSet)8 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)7 EXistResource (org.exist.xmldb.EXistResource)6 Account (org.exist.security.Account)5 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 URISyntaxException (java.net.URISyntaxException)2 ExtendedResource (org.exist.xmldb.ExtendedResource)2 WindowAdapter (java.awt.event.WindowAdapter)1