Search in sources :

Example 61 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class DDLStatementNode method getTableDescriptor.

protected final TableDescriptor getTableDescriptor(UUID tableId) throws StandardException {
    TableDescriptor td = getDataDictionary().getTableDescriptor(tableId);
    td = checkTableDescriptor(td, true);
    return td;
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 62 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class DDLStatementNode method getTableDescriptor.

/**
 * Validate that the table is ok for DDL -- e.g.
 * that it exists, it is not a view, and is not
 * a system table, and that its schema is ok.
 *
 * @return the validated table descriptor, never null
 *
 * @exception StandardException on error
 */
protected final TableDescriptor getTableDescriptor(TableName tableName) throws StandardException {
    TableDescriptor td = justGetDescriptor(tableName);
    /* beetle 4444, td may have changed when we obtain shared lock */
    td = checkTableDescriptor(td, true);
    return td;
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 63 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class CompilerContextImpl method addRequiredColumnPriv.

/**
 * Add a column privilege to the list of used column privileges.
 *
 * @param column The column whose privileges we're interested in.
 */
public void addRequiredColumnPriv(ColumnDescriptor column) {
    if (// Using old style authorization
    requiredColumnPrivileges == null || currPrivType == Authorizer.NULL_PRIV || // Table privilege only
    currPrivType == Authorizer.DELETE_PRIV || // Table privilege only
    currPrivType == Authorizer.INSERT_PRIV || // Table privilege only
    currPrivType == Authorizer.TRIGGER_PRIV || currPrivType == Authorizer.EXECUTE_PRIV || column == null) {
        return;
    }
    /*
		* Note that to look up the privileges for this column,
		* we need to know what table the column is in. However,
		* not all ColumnDescriptor objects are associated with
		* a table object. Sometimes a ColumnDescriptor
		* describes a column but doesn't specify the table. An
		* example of this occurs in the set-clause of the
		* UPDATE statement in SQL, where we may have a
		* ColumnDescriptor which describes the expression that
		* is being used in the UPDATE statement to provide the
		* new value that will be computed by the UPDATE. In such a
		* case, there is no column privilege to be added, so we
		* just take an early return. DERBY-1583 has more details.
		*/
    TableDescriptor td = column.getTableDescriptor();
    if (td == null)
        return;
    if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        // no priv needed, it is per session anyway
        return;
    }
    UUID tableUUID = td.getUUID();
    // DERBY-4191
    if (currPrivType == Authorizer.MIN_SELECT_PRIV) {
        // If we are here for MIN_SELECT_PRIV requirement, then first
        // check if there is already a SELECT privilege requirement on any
        // of the columns in the table, or on the table itself. If yes,
        // then we do not need to add MIN_SELECT_PRIV requirement for the
        // table because that requirement is already getting satisfied with
        // the already existing SELECT privilege requirement.
        StatementTablePermission key = new StatementTablePermission(tableUUID, Authorizer.SELECT_PRIV);
        if (requiredColumnPrivileges.containsKey(key) || requiredTablePrivileges.containsKey(key)) {
            return;
        }
    }
    if (currPrivType == Authorizer.SELECT_PRIV) {
        // If we are here for SELECT_PRIV requirement, then first check
        // if there is already any MIN_SELECT_PRIV privilege required
        // on this table. If yes, then that requirement will be fulfilled
        // by the SELECT_PRIV requirement we are adding now. Because of
        // that, remove the MIN_SELECT_PRIV privilege requirement
        StatementTablePermission key = new StatementTablePermission(tableUUID, Authorizer.MIN_SELECT_PRIV);
        requiredColumnPrivileges.remove(key);
    }
    StatementTablePermission key = new StatementTablePermission(tableUUID, currPrivType);
    StatementColumnPermission tableColumnPrivileges = requiredColumnPrivileges.get(key);
    if (tableColumnPrivileges == null) {
        tableColumnPrivileges = new StatementColumnPermission(tableUUID, currPrivType, new FormatableBitSet(td.getNumberOfColumns()));
        requiredColumnPrivileges.put(key, tableColumnPrivileges);
    }
    tableColumnPrivileges.getColumns().set(column.getPosition() - 1);
}
Also used : StatementColumnPermission(org.apache.derby.iapi.sql.dictionary.StatementColumnPermission) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) UUID(org.apache.derby.catalog.UUID) StatementTablePermission(org.apache.derby.iapi.sql.dictionary.StatementTablePermission) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 64 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class TablePrivilegeInfo method checkPrivileges.

/**
 * Determines if the privilege is grantable by this grantor
 * for the given view.
 *
 * Note that the database owner can access database objects
 * without needing to be their owner.  This method should only
 * be called if it is a GRANT.
 *
 * @param user					authorizationId of current user
 * @param td		            TableDescriptor to be checked against
 * @param sd					SchemaDescriptor
 * @param dd					DataDictionary
 * @param lcc                   LanguageConnectionContext
 *
 * @exception StandardException if user does not have permission to grant
 */
private void checkPrivileges(String user, TableDescriptor td, SchemaDescriptor sd, DataDictionary dd, LanguageConnectionContext lcc) throws StandardException {
    if (user.equals(dd.getAuthorizationDatabaseOwner()))
        return;
    // check view specific
    if (td.getTableType() == TableDescriptor.VIEW_TYPE) {
        if (descriptorList != null) {
            TransactionController tc = lcc.getTransactionExecute();
            int siz = descriptorList.size();
            for (int i = 0; i < siz; i++) {
                TupleDescriptor p;
                SchemaDescriptor s = null;
                p = (TupleDescriptor) descriptorList.get(i);
                if (p instanceof TableDescriptor) {
                    TableDescriptor t = (TableDescriptor) p;
                    s = t.getSchemaDescriptor();
                } else if (p instanceof ViewDescriptor) {
                    ViewDescriptor v = (ViewDescriptor) p;
                    s = dd.getSchemaDescriptor(v.getCompSchemaId(), tc);
                } else if (p instanceof AliasDescriptor) {
                    AliasDescriptor a = (AliasDescriptor) p;
                    s = dd.getSchemaDescriptor(a.getSchemaUUID(), tc);
                }
                if (s != null && !user.equals(s.getAuthorizationId())) {
                    throw StandardException.newException(SQLState.AUTH_NO_OBJECT_PERMISSION, user, "grant", sd.getSchemaName(), td.getName());
                }
            // FUTURE: if object is not own by grantor then check if
            // the grantor have grant option.
            }
        }
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Example 65 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class TablePrivilegesNode method bindPrivilegesForView.

/**
 *  Retrieve all the underlying stored dependencies such as table(s),
 *  view(s) and routine(s) descriptors which the view depends on.
 *  This information is then passed to the runtime to determine if
 *  the privilege is grantable to the grantees by this grantor at
 *  execution time.
 *
 *  Go through the providers regardless who the grantor is since
 *  the statement cache may be in effect.
 *
 * @param td the TableDescriptor to check
 *
 * @exception StandardException standard error policy.
 */
private void bindPrivilegesForView(TableDescriptor td) throws StandardException {
    LanguageConnectionContext lcc = getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    ViewDescriptor vd = dd.getViewDescriptor(td);
    DependencyManager dm = dd.getDependencyManager();
    ProviderInfo[] pis = dm.getPersistentProviderInfos(vd);
    this.descriptorList = new ArrayList<Provider>();
    int siz = pis.length;
    for (int i = 0; i < siz; i++) {
        Provider provider = (Provider) pis[i].getDependableFinder().getDependable(dd, pis[i].getObjectId());
        if (provider instanceof TableDescriptor || provider instanceof ViewDescriptor || provider instanceof AliasDescriptor) {
            descriptorList.add(provider);
        }
    }
}
Also used : ProviderInfo(org.apache.derby.iapi.sql.depend.ProviderInfo) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor) Provider(org.apache.derby.iapi.sql.depend.Provider)

Aggregations

TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)80 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)27 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)23 UUID (org.apache.derby.catalog.UUID)22 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)19 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)11 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 StandardException (org.apache.derby.shared.common.error.StandardException)9 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)7 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)7 ArrayList (java.util.ArrayList)6 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 ViewDescriptor (org.apache.derby.iapi.sql.dictionary.ViewDescriptor)6