use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class TriggersTest method assertUpdateIsAugmented.
private void assertUpdateIsAugmented(int key) {
UntypedResultSet rs = QueryProcessor.executeInternal(String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cfName, key));
assertTrue(String.format("Expected value (%s) for augmented cell v2 was not found", key), rs.one().has("v2"));
assertEquals(999, rs.one().getInt("v2"));
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class CassandraAuthorizer method revokeAllFrom.
// Called when deleting a role with DROP ROLE query.
// Internal hook, so no permission checks are needed here.
// Executes a logged batch removing the granted premissions
// for the role as well as the entries from the reverse index
// table
public void revokeAllFrom(RoleResource revokee) {
try {
UntypedResultSet rows = process(String.format("SELECT resource FROM %s.%s WHERE role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(revokee.getRoleName())));
List<CQLStatement> statements = new ArrayList<>();
for (UntypedResultSet.Row row : rows) {
statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE resource = '%s' AND role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(row.getString("resource")), escape(revokee.getRoleName())), ClientState.forInternalCalls()).statement);
}
statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(revokee.getRoleName())), ClientState.forInternalCalls()).statement);
executeLoggedBatch(statements);
} catch (RequestExecutionException | RequestValidationException e) {
logger.warn("CassandraAuthorizer failed to revoke all permissions of {}: {}", revokee.getRoleName(), e);
}
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class CassandraAuthorizer method revokeAllOn.
// Called after a resource is removed (DROP KEYSPACE, DROP TABLE, etc.).
// Execute a logged batch removing all the permissions for the resource
// as well as the index table entry
public void revokeAllOn(IResource droppedResource) {
try {
UntypedResultSet rows = process(String.format("SELECT role FROM %s.%s WHERE resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(droppedResource.getName())));
List<CQLStatement> statements = new ArrayList<>();
for (UntypedResultSet.Row row : rows) {
statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE role = '%s' AND resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(row.getString("role")), escape(droppedResource.getName())), ClientState.forInternalCalls()).statement);
}
statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(droppedResource.getName())), ClientState.forInternalCalls()).statement);
executeLoggedBatch(statements);
} catch (RequestExecutionException | RequestValidationException e) {
logger.warn("CassandraAuthorizer failed to revoke all permissions on {}: {}", droppedResource, e);
return;
}
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class CassandraAuthorizer method addPermissionsForRole.
// Add every permission on the resource granted to the role
private void addPermissionsForRole(Set<Permission> permissions, IResource resource, RoleResource role) throws RequestExecutionException, RequestValidationException {
QueryOptions options = QueryOptions.forInternalCalls(ConsistencyLevel.LOCAL_ONE, Lists.newArrayList(ByteBufferUtil.bytes(role.getRoleName()), ByteBufferUtil.bytes(resource.getName())));
SelectStatement statement;
// is being upgraded and so is running with mixed versions of the authz schema
if (Schema.instance.getTableMetadata(SchemaConstants.AUTH_KEYSPACE_NAME, USER_PERMISSIONS) == null)
statement = authorizeRoleStatement;
else {
// If the permissions table was initialised only after the statement got prepared, re-prepare (CASSANDRA-12813)
if (legacyAuthorizeRoleStatement == null)
legacyAuthorizeRoleStatement = prepare(USERNAME, USER_PERMISSIONS);
statement = legacyAuthorizeRoleStatement;
}
ResultMessage.Rows rows = statement.execute(QueryState.forInternalCalls(), options, System.nanoTime());
UntypedResultSet result = UntypedResultSet.create(rows.result);
if (!result.isEmpty() && result.one().has(PERMISSIONS)) {
for (String perm : result.one().getSet(PERMISSIONS, UTF8Type.instance)) {
permissions.add(Permission.valueOf(perm));
}
}
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method getReleaseVersion.
/**
* Get release version for given endpoint.
* If release version is unknown, then this returns null.
*
* @param ep endpoint address to check
* @return Release version or null if version is unknown.
*/
public static CassandraVersion getReleaseVersion(InetAddress ep) {
try {
if (FBUtilities.getBroadcastAddress().equals(ep)) {
return new CassandraVersion(FBUtilities.getReleaseVersionString());
}
String req = "SELECT release_version FROM system.%s WHERE peer=?";
UntypedResultSet result = executeInternal(format(req, PEERS), ep);
if (result != null && result.one().has("release_version")) {
return new CassandraVersion(result.one().getString("release_version"));
}
// version is unknown
return null;
} catch (IllegalArgumentException e) {
// version string cannot be parsed
return null;
}
}
Aggregations