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;
}
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;
}
Aggregations