for (Iterator gIter = grantees.iterator(); gIter.hasNext();) {
String grantee = (String)gIter.next();
// check that role exists
RoleDescriptor rd = dd.getRoleDefinitionDescriptor(role);
if (rd == null) {
throw StandardException.
newException(SQLState.ROLE_INVALID_SPECIFICATION, role);
}
// Check that role is granted to us (or PUBLIC) with
// WITH ADMIN option so we can grant (and hence
// revoke) it. For database owner, a role definition
// always fulfills this requirement. If we implement
// granting with WITH ADMIN option later, we need to
// look for a grant to us or to PUBLIC which has WITH
// ADMIN. The role definition descriptor will not
// suffice in that case, so we need something like:
//
// rd = dd.findRoleGrantWithAdminToRoleOrPublic(grantor)
// if (rd != null) {
// :
if (grantor.equals(rd.getGrantee())) {
// All ok, we are database owner
if (SanityManager.DEBUG) {
SanityManager.ASSERT(
lcc.getDataDictionary().
getAuthorizationDatabaseOwner().
equals(grantor),
"expected database owner in role descriptor");
SanityManager.ASSERT(
rd.isWithAdminOption(),
"expected role definition to have ADMIN OPTION");
}
} else {
throw StandardException.newException
(SQLState.AUTH_ROLE_DBO_ONLY, "REVOKE role");
}
rd = dd.getRoleGrantDescriptor(role, grantee, grantor);
if (rd != null && withAdminOption) {
// NOTE: Never called yet, withAdminOption not yet
// implemented.
// revoke only the ADMIN OPTION from grantee
//
if (rd.isWithAdminOption()) {
// Remove old descriptor and add a new one
// without admin option.
rd.drop(lcc);
rd.setWithAdminOption(false);
dd.addDescriptor(rd,
null, // parent
DataDictionary.SYSROLES_CATALOG_NUM,
false, // no duplicatesAllowed
tc);
} else {
activation.addWarning
(StandardException.newWarning
(SQLState.LANG_WITH_ADMIN_OPTION_NOT_REVOKED,
role, grantee));
}
} else if (rd != null) {
// normal revoke of role from grantee
//
rd.drop(lcc);
} else {
activation.addWarning
(StandardException.newWarning
(SQLState.LANG_ROLE_NOT_REVOKED, role, grantee));
}