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);
}
}
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);
}
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();
}
}
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);
}
}
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);
}
}
}
Aggregations