use of org.exist.security.SecurityManager in project exist by eXist-db.
the class AbstractTestRunner method executeQuery.
protected static Sequence executeQuery(final BrokerPool brokerPool, final Source query, final List<Function<XQueryContext, Tuple2<String, Object>>> externalVariableBindings) throws EXistException, PermissionDeniedException, XPathException, IOException, DatabaseConfigurationException {
final SecurityManager securityManager = requireNonNull(brokerPool.getSecurityManager(), "securityManager is null");
try (final DBBroker broker = brokerPool.get(Optional.of(securityManager.getSystemSubject()))) {
final XQueryPool queryPool = brokerPool.getXQueryPool();
CompiledXQuery compiledQuery = queryPool.borrowCompiledXQuery(broker, query);
try {
XQueryContext context;
if (compiledQuery == null) {
context = new XQueryContext(broker.getBrokerPool());
} else {
context = compiledQuery.getContext();
context.prepareForReuse();
}
// setup misc. context
context.setBaseURI(new AnyURIValue("/db"));
if (query instanceof FileSource) {
final Path queryPath = Paths.get(((FileSource) query).getPath().toAbsolutePath().toString());
if (Files.isDirectory(queryPath)) {
context.setModuleLoadPath(queryPath.toString());
} else {
context.setModuleLoadPath(queryPath.getParent().toString());
}
}
// declare variables for the query
for (final Function<XQueryContext, Tuple2<String, Object>> externalVariableBinding : externalVariableBindings) {
final Tuple2<String, Object> nameValue = externalVariableBinding.apply(context);
context.declareVariable(nameValue._1, nameValue._2);
}
final XQuery xqueryService = brokerPool.getXQueryService();
// compile or update the context
if (compiledQuery == null) {
compiledQuery = xqueryService.compile(context, query);
} else {
compiledQuery.getContext().updateContext(context);
context.getWatchDog().reset();
}
return xqueryService.execute(broker, compiledQuery, null);
} finally {
queryPool.returnCompiledXQuery(query, compiledQuery);
}
}
}
use of org.exist.security.SecurityManager in project exist by eXist-db.
the class RpcConnection method addGroupManager.
@Override
public void addGroupManager(final String manager, final String groupName) throws EXistException, PermissionDeniedException {
withDb((broker, transaction) -> {
final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
final Account account = sm.getAccount(manager);
final Group group = sm.getGroup(groupName);
group.addManager(account);
sm.updateGroup(group);
return null;
});
}
use of org.exist.security.SecurityManager in project exist by eXist-db.
the class RpcConnection method removeGroupManager.
@Override
public void removeGroupManager(final String groupName, final String manager) throws EXistException, PermissionDeniedException {
withDb((broker, transaction) -> {
final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
final Group group = sm.getGroup(groupName);
final Account account = sm.getAccount(manager);
group.removeManager(account);
sm.updateGroup(group);
return null;
});
}
use of org.exist.security.SecurityManager in project exist by eXist-db.
the class RpcConnection method updateAccount.
@Override
public boolean updateAccount(final String name, String passwd, final String passwdDigest, final List<String> groups, final Boolean enabled, final Integer umask, final Map<String, String> metadata) throws EXistException, PermissionDeniedException {
if (passwd.length() == 0) {
passwd = null;
}
final UserAider account = new UserAider(name);
account.setEncodedPassword(passwd);
account.setPasswordDigest(passwdDigest);
for (final String g : groups) {
account.addGroup(g);
}
if (enabled != null) {
account.setEnabled(enabled);
}
if (umask != null) {
account.setUserMask(umask);
}
if (metadata != null) {
for (final Map.Entry<String, String> m : metadata.entrySet()) {
if (AXSchemaType.valueOfNamespace(m.getKey()) != null) {
account.setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
} else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
account.setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
}
}
}
final SecurityManager manager = factory.getBrokerPool().getSecurityManager();
withDb((broker, transaction) -> manager.updateAccount(account));
return true;
}
use of org.exist.security.SecurityManager in project exist by eXist-db.
the class RpcConnection method removeGroupMember.
@Override
public void removeGroupMember(final String group, final String member) throws EXistException, PermissionDeniedException {
withDb((broker, transaction) -> {
final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
final Account account = sm.getAccount(member);
account.remGroup(group);
sm.updateAccount(account);
return null;
});
}
Aggregations