use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class TablePrivilegeInfo method executeGrantRevoke.
/**
* This is the guts of the Execution-time logic for GRANT/REVOKE of a table privilege
*
* @param activation
* @param grant true if grant, false if revoke
* @param grantees a list of authorization ids (strings)
*
* @exception StandardException Thrown on failure
*/
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
String currentUser = lcc.getCurrentUserId(activation);
TransactionController tc = lcc.getTransactionExecute();
SchemaDescriptor sd = td.getSchemaDescriptor();
// Check that the current user has permission to grant the privileges.
checkOwnership(currentUser, td, sd, dd, lcc, grant);
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
TablePermsDescriptor tablePermsDesc = ddg.newTablePermsDescriptor(td, getPermString(SELECT_ACTION, false), getPermString(DELETE_ACTION, false), getPermString(INSERT_ACTION, false), getPermString(UPDATE_ACTION, false), getPermString(REFERENCES_ACTION, false), getPermString(TRIGGER_ACTION, false), currentUser);
ColPermsDescriptor[] colPermsDescs = new ColPermsDescriptor[columnBitSets.length];
for (int i = 0; i < columnBitSets.length; i++) {
if (columnBitSets[i] != null || // should be removed.
(!grant) && hasColumnPermissions(i) && actionAllowed[i]) {
colPermsDescs[i] = ddg.newColPermsDescriptor(td, getActionString(i, false), columnBitSets[i], currentUser);
}
}
dd.startWriting(lcc);
// Add or remove the privileges to/from the SYS.SYSTABLEPERMS and SYS.SYSCOLPERMS tables
for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
// Keep track to see if any privileges are revoked by a revoke
// statement. If a privilege is not revoked, we need to raise a
// warning. For table privileges, we do not check if privilege for
// a specific action has been revoked or not. Also, we do not check
// privileges for specific columns. If at least one privilege has
// been revoked, we do not raise a warning. This has to be refined
// further to check for specific actions/columns and raise warning
// if any privilege has not been revoked.
boolean privileges_revoked = false;
String grantee = (String) itr.next();
if (tablePermsDesc != null) {
if (dd.addRemovePermissionsDescriptor(grant, tablePermsDesc, grantee, tc)) {
privileges_revoked = true;
dd.getDependencyManager().invalidateFor(tablePermsDesc, DependencyManager.REVOKE_PRIVILEGE, lcc);
// When revoking a privilege from a Table we need to
// invalidate all GPSs refering to it. But GPSs aren't
// Dependents of TablePermsDescr, but of the
// TableDescriptor itself, so we must send
// INTERNAL_RECOMPILE_REQUEST to the TableDescriptor's
// Dependents.
dd.getDependencyManager().invalidateFor(td, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
}
}
for (int i = 0; i < columnBitSets.length; i++) {
if (colPermsDescs[i] != null) {
if (dd.addRemovePermissionsDescriptor(grant, colPermsDescs[i], grantee, tc)) {
privileges_revoked = true;
dd.getDependencyManager().invalidateFor(colPermsDescs[i], DependencyManager.REVOKE_PRIVILEGE, lcc);
// When revoking a privilege from a Table we need to
// invalidate all GPSs refering to it. But GPSs aren't
// Dependents of colPermsDescs[i], but of the
// TableDescriptor itself, so we must send
// INTERNAL_RECOMPILE_REQUEST to the TableDescriptor's
// Dependents.
dd.getDependencyManager().invalidateFor(td, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
}
}
}
addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class SetSchemaConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for SET SCHEMA.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc;
DataDictionary dd;
// find the language context.
lcc = activation.getLanguageConnectionContext();
dd = lcc.getDataDictionary();
String thisSchemaName = schemaName;
if (type == StatementType.SET_SCHEMA_DYNAMIC) {
ParameterValueSet pvs = activation.getParameterValueSet();
DataValueDescriptor dvs = pvs.getParameter(0);
thisSchemaName = dvs.getString();
// null parameter is not allowed
if (thisSchemaName == null || thisSchemaName.length() > Limits.MAX_IDENTIFIER_LENGTH)
throw StandardException.newException(SQLState.LANG_DB2_REPLACEMENT_ERROR, "CURRENT SCHEMA");
} else if (type == StatementType.SET_SCHEMA_USER) {
thisSchemaName = lcc.getCurrentUserId(activation);
}
SchemaDescriptor sd = dd.getSchemaDescriptor(thisSchemaName, lcc.getTransactionExecute(), true);
lcc.setDefaultSchema(activation, sd);
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class StatementSchemaPermission method check.
/**
* @see StatementPermission#check
*/
public void check(LanguageConnectionContext lcc, boolean forGrant, Activation activation) throws StandardException {
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
String currentUserId = lcc.getCurrentUserId(activation);
switch(privType) {
case Authorizer.MODIFY_SCHEMA_PRIV:
case Authorizer.DROP_SCHEMA_PRIV:
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, false);
// does not exists.
if (sd == null)
return;
if (!currentUserId.equals(sd.getAuthorizationId()))
throw StandardException.newException(SQLState.AUTH_NO_ACCESS_NOT_OWNER, currentUserId, schemaName);
break;
case Authorizer.CREATE_SCHEMA_PRIV:
// called at all
if (!schemaName.equals(currentUserId) || (aid != null && !aid.equals(currentUserId)))
throw StandardException.newException(SQLState.AUTH_NOT_DATABASE_OWNER, currentUserId, schemaName);
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Unexpected value (" + privType + ") for privType");
}
break;
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class DMLModStatementNode method getSchemaDescriptor.
/**
* Get a schema descriptor for the given table.
* Uses this.targetTableName.
*
* @return Schema Descriptor
*
* @exception StandardException throws on schema name
* that doesn't exist
*/
SchemaDescriptor getSchemaDescriptor() throws StandardException {
SchemaDescriptor sd;
sd = getSchemaDescriptor(targetTableName.getSchemaName());
return sd;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class DropAliasNode method bindStatement.
/**
* Bind this DropMethodAliasNode.
*
* @exception StandardException Thrown on error
*/
@Override
public void bindStatement() throws StandardException {
DataDictionary dataDictionary = getDataDictionary();
String aliasName = getRelativeName();
AliasDescriptor ad = null;
SchemaDescriptor sd = getSchemaDescriptor();
if (sd.getUUID() != null) {
ad = dataDictionary.getAliasDescriptor(sd.getUUID().toString(), aliasName, nameSpace);
}
if (ad == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(), aliasName);
}
// User cannot drop a system alias
if (ad.getSystemAlias()) {
throw StandardException.newException(SQLState.LANG_CANNOT_DROP_SYSTEM_ALIASES, aliasName);
}
// Statement is dependent on the AliasDescriptor
getCompilerContext().createDependency(ad);
}
Aggregations