1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.catalog.UUID; 26 import org.apache.derby.iapi.sql.conn.Authorizer; 27 import org.apache.derby.iapi.reference.SQLState; 28 import org.apache.derby.iapi.services.io.FormatableBitSet; 29 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 30 31 34 35 public class StatementColumnPermission extends StatementTablePermission 36 { 37 private FormatableBitSet columns; 38 39 48 public StatementColumnPermission(UUID tableUUID, int privType, FormatableBitSet columns) 49 { 50 super( tableUUID, privType); 51 this.columns = columns; 52 } 53 54 59 public FormatableBitSet getColumns() 60 { 61 return columns; 62 } 63 64 72 public boolean equals( Object obj) 73 { 74 if( obj instanceof StatementColumnPermission) 75 { 76 StatementColumnPermission other = (StatementColumnPermission) obj; 77 if( ! columns.equals( other.columns)) 78 return false; 79 return super.equals( obj); 80 } 81 return false; 82 } 83 84 87 public void check( LanguageConnectionContext lcc, 88 String authorizationId, 89 boolean forGrant) 90 throws StandardException 91 { 92 DataDictionary dd = lcc.getDataDictionary(); 93 94 if( hasPermissionOnTable(dd, authorizationId, forGrant)) 95 return; 96 FormatableBitSet permittedColumns = null; 97 if( ! forGrant) 98 { 99 permittedColumns = addPermittedColumns( dd, 100 false , 101 Authorizer.PUBLIC_AUTHORIZATION_ID, 102 permittedColumns); 103 permittedColumns = addPermittedColumns( dd, 104 false , 105 authorizationId, 106 permittedColumns); 107 } 108 permittedColumns = addPermittedColumns( dd, 109 true , 110 Authorizer.PUBLIC_AUTHORIZATION_ID, 111 permittedColumns); 112 permittedColumns = addPermittedColumns( dd, 113 true , 114 authorizationId, 115 permittedColumns); 116 117 for( int i = columns.anySetBit(); i >= 0; i = columns.anySetBit( i)) 118 { 119 if( permittedColumns != null && permittedColumns.get(i)) 120 continue; 121 122 TableDescriptor td = getTableDescriptor( dd); 124 ColumnDescriptor cd = td.getColumnDescriptor( i + 1); 125 if( cd == null) 126 throw StandardException.newException( SQLState.AUTH_INTERNAL_BAD_UUID, "column"); 127 throw StandardException.newException( forGrant ? SQLState.AUTH_NO_COLUMN_PERMISSION_FOR_GRANT 128 : SQLState.AUTH_NO_COLUMN_PERMISSION, 129 authorizationId, 130 getPrivName(), 131 cd.getColumnName(), 132 td.getSchemaName(), 133 td.getName()); 134 } 135 } 137 140 private FormatableBitSet addPermittedColumns( DataDictionary dd, 141 boolean forGrant, 142 String authorizationId, 143 FormatableBitSet permittedColumns) 144 throws StandardException 145 { 146 if( permittedColumns != null && permittedColumns.getNumBitsSet() == permittedColumns.size()) 147 return permittedColumns; 148 ColPermsDescriptor perms = dd.getColumnPermissions( tableUUID, privType, false, authorizationId); 149 if( perms != null) 150 { 151 if( permittedColumns == null) 152 return perms.getColumns(); 153 permittedColumns.or( perms.getColumns()); 154 } 155 return permittedColumns; 156 } 158 161 public PermissionsDescriptor getPermissionDescriptor(String authid, DataDictionary dd) 162 throws StandardException 163 { 164 if (oneAuthHasPermissionOnTable( dd, authid, false)) 166 return dd.getTablePermissions(tableUUID, authid); 167 if (oneAuthHasPermissionOnTable( dd, Authorizer.PUBLIC_AUTHORIZATION_ID, false)) 169 return dd.getTablePermissions(tableUUID, Authorizer.PUBLIC_AUTHORIZATION_ID); 170 171 ColPermsDescriptor colsPermsDesc = dd.getColumnPermissions(tableUUID, privType, false, authid); 176 if( colsPermsDesc != null) 177 { 178 if( colsPermsDesc.getColumns() != null){ 179 FormatableBitSet permittedColumns = colsPermsDesc.getColumns(); 180 for( int i = columns.anySetBit(); i >= 0; i = columns.anySetBit( i)) 181 { 182 if(permittedColumns.get(i)) 183 return colsPermsDesc; 184 } 185 } 186 } 187 return null; 188 } 189 190 206 public PermissionsDescriptor getPUBLIClevelColPermsDescriptor(String authid, DataDictionary dd) 207 throws StandardException 208 { 209 ColPermsDescriptor colsPermsDesc = dd.getColumnPermissions(tableUUID, privType, false, authid); 210 FormatableBitSet permittedColumns = colsPermsDesc.getColumns(); 211 boolean allColumnsCoveredByUserLevelPrivilege = true; 212 for( int i = columns.anySetBit(); i >= 0 && allColumnsCoveredByUserLevelPrivilege; i = columns.anySetBit( i)) 213 { 214 if(permittedColumns.get(i)) 215 continue; 216 else 217 allColumnsCoveredByUserLevelPrivilege = false; 218 } 219 if (allColumnsCoveredByUserLevelPrivilege) 220 return null; 221 else 222 return (dd.getColumnPermissions(tableUUID, privType, false, Authorizer.PUBLIC_AUTHORIZATION_ID)); 223 } 224 } 225 | Popular Tags |