Search in sources :

Example 11 with RoleGrantDescriptor

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

the class SYSROLESRowFactory method makeRow.

/**
 * Make a SYSROLES row
 *
 * @param td a role grant descriptor
 * @param parent unused
 *
 * @return  Row suitable for inserting into SYSROLES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    ExecRow row;
    String oid_string = null;
    String roleid = null;
    String grantee = null;
    String grantor = null;
    boolean wao = false;
    boolean isdef = false;
    if (td != null) {
        RoleGrantDescriptor rgd = (RoleGrantDescriptor) td;
        roleid = rgd.getRoleName();
        grantee = rgd.getGrantee();
        grantor = rgd.getGrantor();
        wao = rgd.isWithAdminOption();
        isdef = rgd.isDef();
        UUID oid = rgd.getUUID();
        oid_string = oid.toString();
    }
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSROLES_COLUMN_COUNT);
    /* 1st column is UUID */
    row.setColumn(1, new SQLChar(oid_string));
    /* 2nd column is ROLEID */
    row.setColumn(2, new SQLVarchar(roleid));
    /* 3rd column is GRANTEE */
    row.setColumn(3, new SQLVarchar(grantee));
    /* 4th column is GRANTOR */
    row.setColumn(4, new SQLVarchar(grantor));
    /* 5th column is WITHADMINOPTION */
    row.setColumn(5, new SQLChar(wao ? "Y" : "N"));
    /* 6th column is ISDEF */
    row.setColumn(6, new SQLChar(isdef ? "Y" : "N"));
    return row;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) RoleGrantDescriptor(org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)

Example 12 with RoleGrantDescriptor

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

the class DataDictionaryImpl method getRoleGrantGraph.

/**
 * Return an in-memory representation of the role grant graph (sans
 * grant of roles to users, only role-role relation.
 *
 * @param tc        Transaction Controller
 * @param inverse   make graph on inverse grant relation
 * @return          hash map representing role grant graph.
 *                  <ul><li>Key: rolename,</li>
 *                      <li>Value: List<RoleGrantDescriptor> representing a
 *                      grant of that rolename to another role (not user).
 *                      </li>
 *                  </ul>
 *
 * FIXME: Need to cache graph and invalidate when role graph is modified.
 * Currently, we always read from SYSROLES.
 */
HashMap<String, List<RoleGrantDescriptor>> getRoleGrantGraph(TransactionController tc, boolean inverse) throws StandardException {
    HashMap<String, List<RoleGrantDescriptor>> hm = new HashMap<String, List<RoleGrantDescriptor>>();
    TabInfoImpl ti = getNonCoreTI(SYSROLES_CATALOG_NUM);
    SYSROLESRowFactory rf = (SYSROLESRowFactory) ti.getCatalogRowFactory();
    DataValueDescriptor isDefOrderable = new SQLVarchar("N");
    ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
    scanQualifier[0][0].setQualifier(SYSROLESRowFactory.SYSROLES_ISDEF - 1, /* to zero-based */
    isDefOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    ScanController sc = tc.openScan(ti.getHeapConglomerate(), // don't hold open across commit
    false, // for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position -
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // 
    scanQualifier, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    ExecRow outRow = rf.makeEmptyRow();
    RoleGrantDescriptor grantDescr;
    while (sc.fetchNext(outRow.getRowArray())) {
        grantDescr = (RoleGrantDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
        // Next call is potentially inefficient.  We could read in
        // definitions first in a separate hash table limiting
        // this to a 2-pass scan.
        RoleGrantDescriptor granteeDef = getRoleDefinitionDescriptor(grantDescr.getGrantee());
        if (granteeDef == null) {
            // not a role, must be user authid, skip
            continue;
        }
        String hashKey;
        if (inverse) {
            hashKey = granteeDef.getRoleName();
        } else {
            hashKey = grantDescr.getRoleName();
        }
        List<RoleGrantDescriptor> arcs = hm.get(hashKey);
        if (arcs == null) {
            arcs = new LinkedList<RoleGrantDescriptor>();
        }
        arcs.add(grantDescr);
        hm.put(hashKey, arcs);
    }
    sc.close();
    return hm;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) HashMap(java.util.HashMap) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) RoleGrantDescriptor(org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Aggregations

RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)12 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)8 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)7 TransactionController (org.apache.derby.iapi.store.access.TransactionController)5 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)3 RoleClosureIterator (org.apache.derby.iapi.sql.dictionary.RoleClosureIterator)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 UUID (org.apache.derby.catalog.UUID)1 ParameterValueSet (org.apache.derby.iapi.sql.ParameterValueSet)1 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)1 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)1 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)1 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)1