use of org.exist.security.PermissionDeniedException in project exist by eXist-db.
the class RemoteUserManagementService method listResourcePermissions.
@Override
public Permission[] listResourcePermissions() throws XMLDBException {
try {
final List<Object> params = new ArrayList<>();
params.add(collection.getPath());
final Map result = (Map) collection.execute("listDocumentPermissions", params);
final Permission[] perm = new Permission[result.size()];
final String[] resources = collection.listResources();
Object[] t;
for (int i = 0; i < resources.length; i++) {
t = (Object[]) result.get(resources[i]);
final String owner = (String) t[0];
final String group = (String) t[1];
final int mode = (Integer) t[2];
final Stream<ACEAider> aces = extractAces(t[3]);
perm[i] = getPermission(owner, group, mode, aces);
}
return perm;
} catch (final PermissionDeniedException pde) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
}
}
use of org.exist.security.PermissionDeniedException in project exist by eXist-db.
the class RemoteUserManagementService method getGroup.
@Override
public Group getGroup(final String name) throws XMLDBException {
try {
final List<Object> params = new ArrayList<>();
params.add(name);
final Map<String, Object> tab = (Map<String, Object>) collection.execute("getGroup", params);
if (tab != null && !tab.isEmpty()) {
final Group group = new GroupAider((Integer) tab.get("id"), (String) tab.get("realmId"), (String) tab.get("name"));
final Object[] managers = (Object[]) tab.get("managers");
for (final Object manager : managers) {
group.addManager(getAccount((String) manager));
}
final Map<String, String> metadata = (Map<String, String>) tab.get("metadata");
for (final Map.Entry<String, String> m : metadata.entrySet()) {
if (AXSchemaType.valueOfNamespace(m.getKey()) != null) {
group.setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
} else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
group.setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
}
}
return group;
}
return null;
} catch (final PermissionDeniedException pde) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde);
}
}
use of org.exist.security.PermissionDeniedException in project exist by eXist-db.
the class RemoteUserManagementService method getPermissions.
@Override
public Permission getPermissions(final Resource res) throws XMLDBException {
if (res == null) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "resource is null");
}
// TODO : use dedicated function in XmldbURI
final String path = ((RemoteCollection) res.getParentCollection()).getPath() + "/" + res.getId();
try {
final List<Object> params = new ArrayList<>();
params.add(path);
final Map result = (Map) collection.execute("getPermissions", params);
final String owner = (String) result.get("owner");
final String group = (String) result.get("group");
final int mode = (Integer) result.get("permissions");
final Stream<ACEAider> aces = extractAces(result.get("acl"));
return getPermission(owner, group, mode, aces);
} catch (final PermissionDeniedException pde) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
}
}
use of org.exist.security.PermissionDeniedException in project exist by eXist-db.
the class RpcConnection method parse.
private boolean parse(final byte[] xml, final XmldbURI docUri, final int overwrite, @Nullable final Date created, @Nullable final Date modified) throws EXistException, PermissionDeniedException {
return this.<Boolean>writeCollection(docUri.removeLastSegment()).apply((collection, broker, transaction) -> {
try (final ManagedDocumentLock lockedDocument = broker.getBrokerPool().getLockManager().acquireDocumentWriteLock(docUri)) {
if (overwrite == 0) {
// NOTE: we have the document write lock above
final DocumentImpl old = collection.getDocument(broker, docUri.lastSegment());
if (old != null) {
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
collection.close();
throw new PermissionDeniedException("Document exists and overwrite is not allowed");
}
}
final InputSource source = new StringInputSource(xml);
final long startTime = System.currentTimeMillis();
final MimeType mime = MimeTable.getInstance().getContentTypeFor(docUri.lastSegment());
broker.storeDocument(transaction, docUri.lastSegment(), source, mime, created, modified, null, null, null, collection);
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
collection.close();
if (LOG.isDebugEnabled()) {
LOG.debug("parsing {} took {}ms.", docUri, System.currentTimeMillis() - startTime);
}
return true;
}
});
}
use of org.exist.security.PermissionDeniedException in project exist by eXist-db.
the class RpcConnection method updateAccount.
/**
* Added by {Marco.Tampucci, Massimo.Martinelli} @isti.cnr.it
*
* modified by Chris Tomlinson based on above updateAccount - it appears
* that this code can rely on the SecurityManager to enforce policy about
* whether user is or is not permitted to update the Account with name.
*
* This is called via RemoteUserManagementService.removeGroup(Account,
* String)
*
* @param name username to update
* @param groups a list of groups
* @param rgroup the user will be removed from this group
* @return true, if the action succeeded
*/
public boolean updateAccount(final String name, final List<String> groups, final String rgroup) {
try {
return withDb((broker, transaction) -> {
final SecurityManager manager = broker.getBrokerPool().getSecurityManager();
final Account u = manager.getAccount(name);
for (final String g : groups) {
if (g.equals(rgroup)) {
u.remGroup(g);
}
}
return manager.updateAccount(u);
});
} catch (final EXistException | PermissionDeniedException ex) {
if (LOG.isDebugEnabled()) {
LOG.debug("removeGroup encountered error", ex);
}
return false;
}
}
Aggregations