1 package com.daffodilwoods.daffodildb.server.sessionsystem; 2 3 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator; 4 5 6 import java.util.*; 7 import com.daffodilwoods.database.resource.*; 8 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 9 import com.daffodilwoods.database.general.*; 10 import com.daffodilwoods.daffodildb.utils.*; 11 import com.daffodilwoods.daffodildb.server.serversystem.*; 12 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 13 14 28 public class AuthorizationIdentifier 29 { 30 String user; String role; 33 ArrayList enabledAuthorizationIdentifiers; 34 ArrayList applicableRoles; 35 36 public AuthorizationIdentifier() throws DException 37 {} 38 39 44 public void setUser(String user) throws DException { 45 this.user = user; 46 } 47 48 53 public void setRole(String role) throws DException { 54 this.role = role; 55 } 56 57 62 public String getUser() throws DException { 63 return this.user; 64 } 65 66 71 public String getRole() throws DException { 72 return this.role; 73 } 74 75 76 81 public String getCurrentAuthorizationIdentifier() throws DException { 82 return user == null ? role : user ; 83 } 84 85 91 public ArrayList getEnabledAuthorizationIdentifiers(_ServerSession globalSession) throws com.daffodilwoods.database.resource.DException{ 92 if( enabledAuthorizationIdentifiers != null ) 93 return enabledAuthorizationIdentifiers; 94 95 enabledAuthorizationIdentifiers = new ArrayList(2); 96 enabledAuthorizationIdentifiers.add(user); 97 enabledAuthorizationIdentifiers.addAll( getEnabledRoles(globalSession) ); 98 return enabledAuthorizationIdentifiers; 99 } 100 101 111 public ArrayList getEnabledRoles(_ServerSession globalSession) throws com.daffodilwoods.database.resource.DException{ 112 if( role == null ) 113 return new ArrayList(1); 114 115 ArrayList enabledRoles = new ArrayList(5); 116 enabledRoles.add(role); 117 enabledRoles.addAll( getApplicableRoles(globalSession) ); 118 return enabledRoles; 119 } 120 121 133 public ArrayList getApplicableRoles(_ServerSession globalSession) throws com.daffodilwoods.database.resource.DException{ 134 if( applicableRoles != null ) return applicableRoles; 136 137 applicableRoles = new ArrayList(4); 138 applicableRoles.add(role); 139 String query = "Select * from "+ SystemTables.role_authorization_TableName ; 140 141 _Iterator iterator = (_Iterator)((_ServerSession)globalSession).executeQuery( query,0 ); 142 143 int pointer = 0; 144 while(pointer != applicableRoles.size()){ 145 String currentRole = (String )applicableRoles.get(pointer); 146 150 if( iterator.first() ){ 151 do{ 152 com.daffodilwoods.daffodildb.server.datasystem.utility._Record record = iterator.getRecord(); 153 String grantee = (String )((FieldBase)record.getObject("grantee")).getObject(); 154 if( grantee.equalsIgnoreCase(currentRole) || grantee.equalsIgnoreCase("PUBLIC") ) 155 applicableRoles.add( ((FieldBase) record.getObject("role_name")).getObject() ); 156 }while( iterator.next() ); 157 } 158 pointer++; 159 } 160 return applicableRoles; 161 } 162 163 164 165 171 public ArrayList getRolePrivileges(_ServerSession globalSession) throws com.daffodilwoods.database.resource.DException{ 172 ArrayList rolePrivileges = new ArrayList(5); 173 ArrayList applicableRoles = getApplicableRoles(globalSession); 174 String clause = getClauseForRolePrivileges(applicableRoles); 175 176 177 return rolePrivileges; 178 } 179 180 private String getClauseForRolePrivileges(ArrayList applicableRoles) throws DException { 181 StringBuffer clause = new StringBuffer (50); 182 clause.append("grantee == 'PUBLIC'"); 183 for(int a=0,count = applicableRoles.size();a <count;a++){ 184 clause.append("or grantee == '"); 185 clause.append(applicableRoles.get(a)); 186 clause.append('\''); 187 } 188 return clause.toString(); 189 } 190 } 191 | Popular Tags |