use of io.crate.user.UserLookup in project crate by crate.
the class BaseUsersIntegrationTest method executeAs.
public SQLResponse executeAs(String stmt, String userName) {
SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class);
UserLookup userLookup = internalCluster().getInstance(UserLookup.class);
User user = Objects.requireNonNull(userLookup.findUser(userName), "User " + userName + " must exist");
Session session = sqlOperations.createSession(null, user);
return execute(stmt, null, session);
}
use of io.crate.user.UserLookup in project crate by crate.
the class SQLIntegrationTestCase method systemExecute.
/**
* Execute a SQL statement as system query on a specific node in the cluster
*
* @param stmt the SQL statement
* @param schema the schema that should be used for this statement
* schema is nullable, which means the default schema ("doc") is used
* @param node the name of the node on which the stmt is executed
* @return the SQL Response
*/
public SQLResponse systemExecute(String stmt, @Nullable String schema, String node) {
SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class, node);
UserLookup userLookup;
try {
userLookup = internalCluster().getInstance(UserLookup.class, node);
} catch (ConfigurationException ignored) {
// If enterprise is not enabled there is no UserLookup instance bound in guice
userLookup = userName -> User.CRATE_USER;
}
try (Session session = sqlOperations.createSession(schema, userLookup.findUser("crate"))) {
response = sqlExecutor.exec(stmt, session);
}
return response;
}
Aggregations