1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.*; 8 import com.daffodilwoods.daffodildb.server.sql99.common.*; 9 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 10 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 12 import com.daffodilwoods.daffodildb.server.sql99.token.*; 13 import com.daffodilwoods.database.resource.*; 14 15 public class grantrolestatement implements grantstatement { 16 public SNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor _OptSNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor0; 17 public SRESERVEDWORD1206543922SRESERVEDWORD1206543922SNONRESERVEDWORD136444255 _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922SNONRESERVEDWORD1364442551; 18 public grantee[] _OptRepScomma94843605grantee2; 19 public grantee _grantee3; 20 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224; 21 public rolegranted[] _OptRepScomma94843605rolegranted5; 22 public rolegranted _rolegranted6; 23 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439227; 24 25 private SchemaDescriptor schemaDes; 26 private boolean isGrantorRole; 27 28 47 public Object run(Object object) throws 48 DException { 49 _ServerSession currentSession = (_ServerSession) object; 50 TreeSet grantees = getGrantees(currentSession); 51 String grantor0 = getGrantor(currentSession); 52 ArrayList rolesList = getRolesTobeGranted(currentSession, grantees, grantor0); 53 saveRoleAuthorizationDescriptors(currentSession, grantees, rolesList, grantor0); 54 57 return null; 58 } 59 60 66 private TreeSet getGrantees(_ServerSession currentSession) throws DException { 67 TreeSet granttesList = new TreeSet(String.CASE_INSENSITIVE_ORDER); 68 _Executer userExecuter = SqlSchemaConstants.getExecuter(currentSession, QueryMaker.getUsersQuery()); 69 _Executer rolesExecuter = SqlSchemaConstants.getExecuter(currentSession, QueryMaker.getRolesQuery()); 70 String granteeName = (String ) _grantee3.run(null); 71 if (! (granteeName.equalsIgnoreCase(SystemTables.SYSTEM) || granteeName.equalsIgnoreCase(ServerSystem.browserUser))) { 72 checkGranteeExistance(userExecuter, rolesExecuter, granteeName); 73 } 74 granttesList.add(granteeName); 75 if (_OptRepScomma94843605grantee2 != null) { 76 for (int i = 0; i < _OptRepScomma94843605grantee2.length; i++) { 77 String granteeName1 = (String ) _OptRepScomma94843605grantee2[i].run(null); 78 if (! (granteeName1.equalsIgnoreCase(SystemTables.SYSTEM) || granteeName1.equalsIgnoreCase(ServerSystem.browserUser))) { 79 checkGranteeExistance(userExecuter, rolesExecuter, granteeName1); 80 } 81 granttesList.add(granteeName1); 82 } 83 } 84 return granttesList; 85 } 86 87 94 private void checkGranteeExistance(_Executer userExecuter, _Executer rolesExecuter, String granteeName) throws DException { 95 _SelectQueryIterator iterator = (_SelectQueryIterator) userExecuter.executeForFresh(new Object [] {granteeName}); 96 if (!iterator.first()) { 97 iterator = (_SelectQueryIterator) rolesExecuter.executeForFresh(new Object [] {granteeName}); 98 if (!iterator.first()) { 99 throw new DException("DSE8094", new Object [] {granteeName}); 100 } 101 } 102 } 103 104 116 private String getGrantor(_ServerSession currentSession) throws DException { 117 String grantor0 = null; 118 if (_OptSNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor0 == null) { 119 String current_role = currentSession.getCurrentRole(); 120 isGrantorRole = current_role == null; 121 grantor0 = isGrantorRole ? 122 currentSession.getCurrentUser() : current_role; 123 124 } else { 125 String grantorType = 126 _OptSNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor0. 127 _grantor0.toString(); 128 isGrantorRole = grantorType.equalsIgnoreCase(SqlKeywords.CURRENT_ROLE); 129 grantor0 = isGrantorRole ? currentSession.getCurrentRole() : currentSession.getCurrentUser(); 130 if (grantor0 == null) { 131 throw new DException("DSE520", null); 132 } 133 } 134 return grantor0; 135 } 136 137 151 private ArrayList getRolesTobeGranted(_ServerSession currentSession, 152 TreeSet granteesList, String grantor0) throws DException { 153 ArrayList rolesList = new ArrayList(); 154 TreeMap applicableRoles = isGrantorRole ? GeneralUtility.getApplicableRoles(currentSession, grantor0) 155 : GeneralUtility.getApplicableRolesForUser(currentSession, grantor0); 156 _Executer rolesExecuter = ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter().getExecuterForRoleValidity(); 157 String roleName = (String ) _rolegranted6.run(null); 158 _Iterator iterator = (_Iterator) rolesExecuter.executeForFresh(new Object [] {roleName}); 159 if (!iterator.first()) { 160 throw new DException("DSE8185", new Object [] {roleName}); 161 } 162 checkCyclicRoles(currentSession, roleName, granteesList); 163 164 RoleAuthorizationDescriptor roleAuthDes = (RoleAuthorizationDescriptor) applicableRoles.get(roleName); 165 if (roleAuthDes == null || roleAuthDes.is_grantable.equalsIgnoreCase(SqlSchemaConstants.NO)) { 166 throw new DException("DSE8096", new Object [] {grantor0}); 167 } 168 rolesList.add(roleName); 169 if (_OptRepScomma94843605rolegranted5 != null) { 170 for (int i = 0; i < _OptRepScomma94843605rolegranted5.length; i++) { 171 String roleName1 = (String ) _OptRepScomma94843605rolegranted5[i].run(null); 172 _Iterator iter = (_Iterator) rolesExecuter.executeForFresh(new Object [] {roleName1}); 173 if (!iter.first()) { 174 throw new DException("DSE8185", new Object [] {roleName1}); 175 } 176 checkCyclicRoles(currentSession, roleName1, granteesList); 177 roleAuthDes = (RoleAuthorizationDescriptor) applicableRoles.get(roleName); 178 if (roleAuthDes == null || roleAuthDes.is_grantable.equalsIgnoreCase(SqlSchemaConstants.NO)) { 179 throw new DException("DSE8096", new Object [] {grantor0}); 180 } 181 rolesList.add(roleName1); 182 } 183 } 184 return rolesList; 185 } 186 187 private void checkCyclicRoles(_ServerSession currentSession, String roleName, TreeSet granteesList) throws DException { 188 if (granteesList.contains(roleName)) { 189 throw new DException("DSE8093", null); 190 } 191 String [] applicableRolesOfRole = GeneralUtility.getApplicableRoleNames( ( (DataDictionary) currentSession.getDataDictionary()).getPreparedStatementGetter(), roleName); 192 if (applicableRolesOfRole != null) { 193 for (int i = 0; i < applicableRolesOfRole.length; i++) { 194 if (granteesList.contains(applicableRolesOfRole[i])) { 195 throw new DException("DSE8093", null); 196 } 197 } 198 } 199 } 200 201 212 private void saveRoleAuthorizationDescriptors(_ServerSession currentSession, TreeSet grantees, ArrayList rolesList, String grantor0) throws DException { 213 String isGranteable = _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922SNONRESERVEDWORD1364442551 != null 214 ? SqlSchemaConstants.YES : SqlSchemaConstants.NO; 215 Object [] granteeList = grantees.toArray(); 216 int noOfGrantees = grantees.size(); 217 for (int i = 0, size = rolesList.size(); i < size; i++) { 218 for (int j = 0; j < noOfGrantees; j++) { 219 RoleAuthorizationDescriptor roleAuthoDes = new RoleAuthorizationDescriptor(); 220 roleAuthoDes.role_name = (String ) rolesList.get(i); 221 roleAuthoDes.grantee = (String ) granteeList[j]; 222 roleAuthoDes.grantor = grantor0; 223 roleAuthoDes.is_grantable = isGranteable; 224 try { 225 roleAuthoDes.save(currentSession); 226 } catch (DException ex) { 227 if (ex.getDseCode().equals("DSE1151") && 228 roleAuthoDes.is_grantable.equalsIgnoreCase(SqlSchemaConstants.YES)) { 229 roleAuthoDes.updateIsGrantableValue(currentSession, 230 roleAuthoDes.is_grantable); 231 } 232 } 233 } 234 } 235 } 236 237 public Object clone() throws CloneNotSupportedException { 238 return this; 239 } 240 241 public String toString() { 242 StringBuffer sb = new StringBuffer (); 243 sb.append(" "); 244 sb.append(_SRESERVEDWORD12065439227); 245 sb.append(" "); 246 sb.append(_rolegranted6); 247 sb.append(" "); 248 if (_OptRepScomma94843605rolegranted5 != null) { 249 for (int i = 0; i < _OptRepScomma94843605rolegranted5.length; i++) { 250 sb.append(",").append(_OptRepScomma94843605rolegranted5[i]); 251 } 252 } 253 sb.append(" "); 254 sb.append(_SRESERVEDWORD12065439224); 255 sb.append(" "); 256 sb.append(_grantee3); 257 sb.append(" "); 258 if (_OptRepScomma94843605grantee2 != null) { 259 for (int i = 0; i < _OptRepScomma94843605grantee2.length; i++) { 260 sb.append(",").append(_OptRepScomma94843605grantee2[i]); 261 } 262 } 263 sb.append(" "); 264 if ( 265 _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922SNONRESERVEDWORD1364442551 != null) { 266 sb.append( 267 _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922SNONRESERVEDWORD1364442551); 268 } 269 sb.append(" "); 270 if (_OptSNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor0 != null) { 271 sb.append(_OptSNONRESERVEDWORD136444255SRESERVEDWORD1206543922grantor0); 272 } 273 return sb.toString(); 274 } 275 276 public void setSchemaDescriptor(_Descriptor schemaDes0) throws 277 DException { 278 schemaDes = (SchemaDescriptor) schemaDes0; 279 } 280 } 281 | Popular Tags |