Search in sources :

Example 6 with PermissionsDescriptor

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

the class DDLConstantAction method storeViewTriggerDependenciesOnPrivileges.

/**
 *	This method saves dependencies of views and triggers on privileges in
 *  the dependency system. It gets called by CreateViewConstantAction
 *  and CreateTriggerConstantAction. Views and triggers and constraints
 *  run with definer's privileges. If one of the required privileges is
 *  revoked from the definer, the dependent view/trigger/constraint on
 *  that privilege will be dropped automatically. In order to implement
 *  this behavior, we need to save view/trigger/constraint dependencies
 *  on required privileges in the dependency system. Following method
 *  accomplishes that part of the equation for views and triggers. The
 *  dependency collection for constraints is not same as for views and
 *  triggers and hence constraints are not covered by this method.
 *  Views and triggers can depend on many different kind of privileges
 *  where as constraints only depend on REFERENCES privilege on a table.
 *  Another difference is only one view or trigger can be defined by a
 *  sql statement and hence all the dependencies collected for the sql
 *  statement apply to the view or trigger in question. As for constraints,
 *  one sql statement can defined multiple constraints and hence the
 *  all the privileges required by the statement are not necessarily
 *  required by all the constraints defined by that sql statement. We need
 *  to identify right privileges for right constraints for a given sql
 *  statement. Because of these differences between constraints and views
 *  (and triggers), there are 2 different methods in this class to save
 *  their privileges in the dependency system.
 *
 *  For each required privilege, we now register of a dependency on a role
 *  if that role was required to find an applicable privilege.
 *
 *  @param activation The execution environment for this constant action.
 *  @param dependent Make this object depend on required privileges
 *
 * @exception StandardException		Thrown on failure
 */
protected void storeViewTriggerDependenciesOnPrivileges(Activation activation, Dependent dependent) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    String dbo = dd.getAuthorizationDatabaseOwner();
    String currentUser = lcc.getCurrentUserId(activation);
    SettableBoolean roleDepAdded = new SettableBoolean();
    // access any objects without any restrictions.
    if (!currentUser.equals(dbo)) {
        PermissionsDescriptor permDesc;
        List<StatementPermission> requiredPermissionsList = activation.getPreparedStatement().getRequiredPermissionsList();
        if (requiredPermissionsList != null && !requiredPermissionsList.isEmpty()) {
            for (StatementPermission statPerm : requiredPermissionsList) {
                // Also, StatementRolePermission should not occur here.
                if (statPerm instanceof StatementSchemaPermission || statPerm instanceof StatementRolePermission) {
                    if (SanityManager.DEBUG) {
                        if (statPerm instanceof StatementRolePermission) {
                            SanityManager.THROWASSERT("Unexpected StatementRolePermission");
                        }
                    }
                    continue;
                }
                // See if we can find the required privilege for given authorizer?
                permDesc = statPerm.getPermissionDescriptor(currentUser, dd);
                if (// privilege not found for given authorizer
                permDesc == null) {
                    // The if condition above means that required privilege does
                    // not exist at the user level. The privilege has to exist at
                    // PUBLIC level... ,
                    permDesc = statPerm.getPermissionDescriptor(Authorizer.PUBLIC_AUTHORIZATION_ID, dd);
                    boolean roleUsed = false;
                    // .. or at role level
                    if (permDesc == null || ((permDesc instanceof ColPermsDescriptor) && !((StatementColumnPermission) statPerm).allColumnsCoveredByUserOrPUBLIC(currentUser, dd))) {
                        roleUsed = true;
                        permDesc = findRoleUsage(activation, statPerm);
                    }
                    // owner.
                    if (!permDesc.checkOwner(currentUser)) {
                        dm.addDependency(dependent, permDesc, lcc.getContextManager());
                        // dependency, too.
                        if (roleUsed) {
                            trackRoleDependency(activation, dependent, roleDepAdded);
                        }
                    }
                    continue;
                }
                // object's privilege dependency in the dependency system
                if (!permDesc.checkOwner(currentUser)) {
                    dm.addDependency(dependent, permDesc, lcc.getContextManager());
                    if (permDesc instanceof ColPermsDescriptor) {
                        // For a given table, the table owner can give privileges
                        // on some columns at individual user level and privileges
                        // on some columns at PUBLIC level. Hence, when looking for
                        // column level privileges, we need to look both at user
                        // level as well as PUBLIC level(only if user level column
                        // privileges do not cover all the columns accessed by this
                        // object). We have finished adding dependency for user level
                        // columns, now we are checking if some required column
                        // level privileges are at PUBLIC level.
                        // A specific eg of a view
                        // user1
                        // create table t11(c11 int, c12 int);
                        // grant select(c11) on t1 to user2;
                        // grant select(c12) on t1 to PUBLIC;
                        // user2
                        // create view v1 as select c11 from user1.t11 where c12=2;
                        // For the view above, there are 2 column level privilege
                        // depencies, one for column c11 which exists directly
                        // for user2 and one for column c12 which exists at PUBLIC level.
                        StatementColumnPermission statementColumnPermission = (StatementColumnPermission) statPerm;
                        permDesc = statementColumnPermission.getPUBLIClevelColPermsDescriptor(currentUser, dd);
                        if (permDesc != null && permDesc.getObjectID() != null) {
                            // User did not have all required column
                            // permissions and at least one column is
                            // covered by PUBLIC.
                            dm.addDependency(dependent, permDesc, lcc.getContextManager());
                        }
                        // upon?
                        if (!statementColumnPermission.allColumnsCoveredByUserOrPUBLIC(currentUser, dd)) {
                            trackRoleDependency(activation, dependent, roleDepAdded);
                        }
                    }
                }
            }
        }
    }
}
Also used : PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) StatementSchemaPermission(org.apache.derby.iapi.sql.dictionary.StatementSchemaPermission) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) StatementColumnPermission(org.apache.derby.iapi.sql.dictionary.StatementColumnPermission) StatementPermission(org.apache.derby.iapi.sql.dictionary.StatementPermission) ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) StatementRolePermission(org.apache.derby.iapi.sql.dictionary.StatementRolePermission)

Example 7 with PermissionsDescriptor

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

the class DataDictionaryImpl method dropColumnPermDescriptor.

/**
 * Delete the appropriate rows from syscolperms when
 * dropping a table
 *
 * @param tc			The TransactionController
 * @param keyRow		Start/stop position.
 *
 * @exception StandardException		Thrown on failure
 */
private void dropColumnPermDescriptor(TransactionController tc, ExecIndexRow keyRow) throws StandardException {
    ExecRow curRow;
    PermissionsDescriptor perm;
    TabInfoImpl ti = getNonCoreTI(SYSCOLPERMS_CATALOG_NUM);
    SYSCOLPERMSRowFactory rf = (SYSCOLPERMSRowFactory) ti.getCatalogRowFactory();
    while ((curRow = ti.getRow(tc, keyRow, rf.TABLEID_INDEX_NUM)) != null) {
        perm = (PermissionsDescriptor) rf.buildDescriptor(curRow, (TupleDescriptor) null, this);
        removePermEntryInCache(perm);
        // Build key on UUID and drop the entry as we want to drop only this row
        ExecIndexRow uuidKey;
        uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, perm);
        ti.deleteRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM);
    }
}
Also used : PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 8 with PermissionsDescriptor

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

the class DataDictionaryImpl method dropAllPermDescriptors.

/**
 * Drops all permission descriptors for the object whose Id is given.
 *
 * @param objectID The UUID of the object from which to drop
 *                 all the permission descriptors
 * @param tc       TransactionController for the transaction
 * @throws StandardException Thrown on error
 */
public void dropAllPermDescriptors(UUID objectID, TransactionController tc) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSPERMS_CATALOG_NUM);
    SYSPERMSRowFactory rf = (SYSPERMSRowFactory) ti.getCatalogRowFactory();
    DataValueDescriptor objIdOrderable;
    ExecRow curRow;
    PermissionsDescriptor perm;
    // In Derby authorization mode, permission catalogs may not be present
    if (!usesSqlAuthorization)
        return;
    /* Use objIDOrderable in both start and stop position for scan. */
    objIdOrderable = getIDValueAsCHAR(objectID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, objIdOrderable);
    while ((curRow = ti.getRow(tc, keyRow, rf.PERMS_OBJECTID_IDX_NUM)) != null) {
        perm = (PermissionsDescriptor) rf.buildDescriptor(curRow, (TupleDescriptor) null, this);
        removePermEntryInCache(perm);
        // Build new key based on UUID and drop the entry as we want to drop
        // only this row
        ExecIndexRow uuidKey;
        uuidKey = rf.buildIndexKeyRow(rf.PERMS_UUID_IDX_NUM, perm);
        ti.deleteRow(tc, uuidKey, rf.PERMS_UUID_IDX_NUM);
    }
}
Also used : PermissionsDescriptor(org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

PermissionsDescriptor (org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor)8 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)5 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)2 ColPermsDescriptor (org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor)2 StatementColumnPermission (org.apache.derby.iapi.sql.dictionary.StatementColumnPermission)2 StatementPermission (org.apache.derby.iapi.sql.dictionary.StatementPermission)2 StatementRolePermission (org.apache.derby.iapi.sql.dictionary.StatementRolePermission)2 StatementSchemaPermission (org.apache.derby.iapi.sql.dictionary.StatementSchemaPermission)2 RoleClosureIterator (org.apache.derby.iapi.sql.dictionary.RoleClosureIterator)1 StatementGenericPermission (org.apache.derby.iapi.sql.dictionary.StatementGenericPermission)1 StatementRoutinePermission (org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission)1 StatementTablePermission (org.apache.derby.iapi.sql.dictionary.StatementTablePermission)1 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 RowLocation (org.apache.derby.iapi.types.RowLocation)1 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)1