use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class StatementTablePermission method hasPermissionOnTable.
// end of getTableDescriptor
/**
* Check if current session has permission on the table (current user,
* PUBLIC or role) and, if applicable, register a dependency of ps on the
* current role.
*
* @param lcc the current language connection context
* @param activation the activation of ps
* @param forGrant true if FOR GRANT is required
* @param ps the prepared statement for which we are checking necessary
* privileges
*/
protected boolean hasPermissionOnTable(LanguageConnectionContext lcc, Activation activation, boolean forGrant, ExecPreparedStatement ps) throws StandardException {
DataDictionary dd = lcc.getDataDictionary();
String currentUserId = lcc.getCurrentUserId(activation);
boolean result = oneAuthHasPermissionOnTable(dd, Authorizer.PUBLIC_AUTHORIZATION_ID, forGrant) || oneAuthHasPermissionOnTable(dd, currentUserId, forGrant);
if (!result) {
// Since no permission exists for the current user or PUBLIC,
// check if a permission exists for the current role (if set).
String role = lcc.getCurrentRoleId(activation);
if (role != null) {
// Check that role is still granted to current user or
// to PUBLIC: A revoked role which is current for this
// session, is lazily set to none when it is attempted
// used.
String dbo = dd.getAuthorizationDatabaseOwner();
RoleGrantDescriptor rd = dd.getRoleGrantDescriptor(role, currentUserId, dbo);
if (rd == null) {
rd = dd.getRoleGrantDescriptor(role, Authorizer.PUBLIC_AUTHORIZATION_ID, dbo);
}
if (rd == null) {
// We have lost the right to set this role, so we can't
// make use of any permission granted to it or its
// ancestors.
lcc.setCurrentRole(activation, null);
} else {
// The current role is OK, so we can make use of
// any permission granted to it.
//
// Look at the current role and, if necessary, the
// transitive closure of roles granted to current role to
// see if permission has been granted to any of the
// applicable roles.
RoleClosureIterator rci = dd.createRoleClosureIterator(activation.getTransactionController(), role, true);
String r;
while (!result && (r = rci.next()) != null) {
result = oneAuthHasPermissionOnTable(dd, r, forGrant);
}
if (result) {
// Also add a dependency on the role (qua provider), so
// that if role is no longer available to the current
// user (e.g. grant is revoked, role is dropped,
// another role has been set), we are able to
// invalidate the ps or activation (the latter is used
// if the current role changes).
DependencyManager dm = dd.getDependencyManager();
RoleGrantDescriptor rgd = dd.getRoleDefinitionDescriptor(role);
ContextManager cm = lcc.getContextManager();
dm.addDependency(ps, rgd, cm);
dm.addDependency(activation, rgd, cm);
}
}
}
}
return result;
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class DMLStatementNode method bindTables.
/**
* Bind the tables in this DML statement.
*
* @param dataDictionary The data dictionary to use to look up the tables
*
* @exception StandardException Thrown on error
*/
protected void bindTables(DataDictionary dataDictionary) throws StandardException {
/* Bind the tables in the resultSet
* (DMLStatementNode is above all ResultSetNodes, so table numbering
* will begin at 0.)
* In case of referential action on delete , the table numbers can be
* > 0 because the nodes are create for dependent tables also in the
* the same context.
*/
boolean doJOO = getOptimizerFactory().doJoinOrderOptimization();
ContextManager cm = getContextManager();
resultSet = resultSet.bindNonVTITables(dataDictionary, new FromList(doJOO, cm));
resultSet = resultSet.bindVTITables(new FromList(doJOO, cm));
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class FromVTI method getAllResultColumns.
/**
* Expand a "*" into a ResultColumnList with all of the
* result columns from the subquery.
* @exception StandardException Thrown on error
*/
@Override
ResultColumnList getAllResultColumns(TableName allTableName) throws StandardException {
TableName toCompare;
if (allTableName != null)
toCompare = makeTableName(allTableName.getSchemaName(), correlationName);
else
toCompare = makeTableName(null, correlationName);
if (allTableName != null && !allTableName.equals(toCompare)) {
return null;
}
final ContextManager cm = getContextManager();
final ResultColumnList rcList = new ResultColumnList(cm);
/* Build a new result column list based off of resultColumns.
* NOTE: This method will capture any column renaming due to
* a derived column list.
*/
for (ResultColumn rc : getResultColumns()) {
if (!rc.isGenerated()) {
// Build a ResultColumn/ColumnReference pair for the column //
ResultColumn newRc = new ResultColumn(rc.getName(), new ColumnReference(rc.getName(), exposedName, cm), cm);
// Build the ResultColumnList to return //
rcList.addResultColumn(newRc);
}
}
return rcList;
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class BaseMonitor method bootService.
/**
* Boot (start or create) a service (persistent or non-persistent).
*/
protected Object bootService(PersistentService provider, String factoryInterface, String serviceName, Properties properties, boolean create) throws StandardException {
// after we got service name.(like in case of restoring from backup).
if (provider != null)
serviceName = provider.getCanonicalServiceName(serviceName);
ProtocolKey serviceKey = ProtocolKey.create(factoryInterface, serviceName);
if (SanityManager.DEBUG && reportOn) {
report("Booting service " + serviceKey + " create = " + create);
}
ContextManager previousCM = contextService.getCurrentContextManager();
ContextManager cm = previousCM;
Object instance;
TopService ts = null;
Context sb = null;
try {
synchronized (this) {
if (inShutdown) {
throw StandardException.newException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
}
for (int i = 1; i < services.size(); i++) {
TopService ts2 = services.get(i);
if (ts2.isPotentialService(serviceKey)) {
// if the service already exists then just return null
return null;
}
}
Locale serviceLocale = null;
if (create) {
// always wrap the property set in an outer set.
// this ensures that any random attributes from
// a JDBC URL are not written into the service.properties
// file (e.g. like user and password :-)
properties = new Properties(properties);
serviceLocale = setLocale(properties);
properties.put(Property.SERVICE_PROTOCOL, factoryInterface);
serviceName = provider.createServiceRoot(serviceName, Boolean.valueOf(properties.getProperty(Property.DELETE_ON_CREATE)).booleanValue());
serviceKey = ProtocolKey.create(factoryInterface, serviceName);
} else if (properties != null) {
String serverLocaleDescription = properties.getProperty(Property.SERVICE_LOCALE);
if (serverLocaleDescription != null)
serviceLocale = staticGetLocaleFromString(serverLocaleDescription);
}
ts = new TopService(this, serviceKey, provider, serviceLocale);
services.add(ts);
}
if (SanityManager.DEBUG) {
if (provider != null) {
SanityManager.ASSERT(provider.getCanonicalServiceName(serviceName).equals(serviceName), "mismatched canonical names " + provider.getCanonicalServiceName(serviceName) + " != " + serviceName);
SanityManager.ASSERT(serviceName.equals(serviceKey.getIdentifier()), "mismatched names " + serviceName + " != " + serviceKey.getIdentifier());
}
}
if (properties != null) {
// these properties must not be stored in the persistent properties,
// otherwise moving databases from one directory to another
// will not work. Thus they all have a fixed prefix
// the root of the data
properties.put(PersistentService.ROOT, serviceName);
// the type of the service
properties.put(PersistentService.TYPE, provider.getType());
}
if (SanityManager.DEBUG && reportOn) {
dumpProperties("Service Properties: " + serviceKey.toString(), properties);
}
// push a new context manager
if (previousCM == null) {
cm = contextService.newContextManager();
contextService.setCurrentContextManager(cm);
}
sb = new ServiceBootContext(cm);
UpdateServiceProperties usProperties;
Properties serviceProperties;
// while doing restore from backup, we don't want service properties to be
// updated until all the files are copied from backup.
boolean inRestore = (properties != null ? properties.getProperty(Property.IN_RESTORE_FROM_BACKUP) != null : false);
if ((provider != null) && (properties != null)) {
// we need to track to see if the properties have
// been updated or not. If the database is not created yet, we don't create the
// services.properties file yet. We let the following if (create) statement do
// that at the end of the database creation. After that, the changes in
// services.properties file will be tracked by UpdateServiceProperties.
usProperties = new UpdateServiceProperties(provider, serviceName, properties, !(create || inRestore));
serviceProperties = usProperties;
} else {
usProperties = null;
serviceProperties = properties;
}
instance = ts.bootModule(create, null, serviceKey, serviceProperties);
// touch or remove any of the files there
if (create) {
provider.createDataWarningFile(usProperties.getStorageFactory());
}
if (create || inRestore) {
// remove all the in-memory properties
provider.saveServiceProperties(serviceName, usProperties.getStorageFactory(), BaseMonitor.removeRuntimeProperties(properties), false);
usProperties.setServiceBooted();
}
if (cm != previousCM) {
// Assume database is not active. DERBY-4856 thread dump
cm.cleanupOnError(StandardException.closeException(), false);
}
} catch (Throwable t) {
StandardException se;
// ensure that the severity will shutdown the service
if ((t instanceof StandardException) && (((StandardException) t).getSeverity() == ExceptionSeverity.DATABASE_SEVERITY))
se = (StandardException) t;
else
se = Monitor.exceptionStartingModule(t);
if (cm != previousCM) {
// Assume database is not active. DERBY-4856 thread dump
cm.cleanupOnError(se, false);
}
if (ts != null) {
ts.shutdown();
synchronized (this) {
services.remove(ts);
}
// Service root will only have been created if
// ts is non-null.
boolean deleteOnError = (properties != null ? properties.getProperty(Property.DELETE_ROOT_ON_ERROR) != null : false);
if (create || deleteOnError)
provider.removeServiceRoot(serviceName);
}
Throwable nested = se.getCause();
// never hide ThreadDeath
if (nested instanceof ThreadDeath)
throw (ThreadDeath) nested;
throw se;
} finally {
if ((previousCM == cm) && (sb != null))
sb.popMe();
if (previousCM == null)
contextService.resetCurrentContextManager(cm);
}
// from this point onwards the service is open for business
ts.setTopModule(instance);
//
// The following yield allows our background threads to
// execute their run methods. This is needed due to
// bug 4081540 on Solaris. When the bug is fixed we can
// remove this yield.
Thread.yield();
return instance;
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class GenericPreparedStatement method setCacheHolder.
// cache holder stuff.
public void setCacheHolder(Cacheable cacheHolder) {
this.cacheHolder = cacheHolder;
if (cacheHolder == null) {
// need to invalidate the statement
if (!isValid || (inUseCount != 0))
return;
ContextManager cm = getContextService().getCurrentContextManager();
LanguageConnectionContext lcc = (LanguageConnectionContext) (cm.getContext(LanguageConnectionContext.CONTEXT_ID));
// prepareToInvalidate(this, DependencyManager.PREPARED_STATEMENT_INVALID);
try {
/* NOTE: Since we are non-persistent, we "know" that no exception
* will be thrown under us.
*/
makeInvalid(DependencyManager.PREPARED_STATEMENT_RELEASE, lcc);
} catch (StandardException se) {
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Unexpected exception", se);
}
}
}
}
Aggregations