1 65 66 67 package org.hsqldb; 68 69 import org.hsqldb.HsqlNameManager.HsqlName; 70 import org.hsqldb.lib.HashSet; 71 import org.hsqldb.lib.IntValueHashMap; 72 73 81 91 public class User { 92 93 94 private boolean isSys; 95 96 97 private boolean isPublic; 98 99 100 private String sName; 101 102 103 private String sPassword; 104 105 106 private HsqlName initialSchema = null; 107 108 109 private Grantee grantee; 110 111 114 User(String name, String password, 115 Grantee inGrantee) throws HsqlException { 116 117 sName = name; 118 grantee = inGrantee; 119 120 boolean granteeOk = grantee != null 121 || GranteeManager.isReserved(name); 122 123 if (!granteeOk) { 124 Trace.doAssert(false, 125 Trace.getMessage(Trace.MISSING_GRANTEE) + ": " 126 + name); 127 } 128 129 setPassword(password); 130 131 isSys = name.equals(GranteeManager.SYSTEM_AUTHORIZATION_NAME); 132 isPublic = name.equals(GranteeManager.PUBLIC_ROLE_NAME); 133 } 134 135 String getName() { 136 return sName; 137 } 138 139 void setPassword(String password) throws HsqlException { 140 141 sPassword = password; 145 } 146 147 151 void checkPassword(String test) throws HsqlException { 152 Trace.check(test.equals(sPassword), Trace.ACCESS_IS_DENIED); 153 } 154 155 159 boolean isSys() { 160 return isSys; 161 } 162 163 166 HsqlName getInitialSchema() { 167 return initialSchema; 168 } 169 170 177 void setInitialSchema(HsqlName schema) { 178 initialSchema = schema; 179 } 180 181 184 boolean isPublic() { 185 return isPublic; 186 } 187 188 194 String getAlterUserDDL() { 195 196 StringBuffer sb = new StringBuffer (); 197 198 sb.append(Token.T_ALTER).append(' '); 199 sb.append(Token.T_USER).append(' '); 200 sb.append(sName).append(' '); 201 sb.append(Token.T_SET).append(' '); 202 sb.append(Token.T_PASSWORD).append(' '); 203 sb.append('"').append(sPassword).append('"'); 204 205 return sb.toString(); 206 } 207 208 213 String getCreateUserDDL() { 214 215 StringBuffer sb = new StringBuffer (64); 216 217 sb.append(Token.T_CREATE).append(' '); 218 sb.append(Token.T_USER).append(' '); 219 sb.append(sName).append(' '); 220 sb.append(Token.T_PASSWORD).append(' '); 221 sb.append('"').append(sPassword).append('"'); 222 223 return sb.toString(); 224 } 225 226 233 public String getConnectStatement() { 234 235 StringBuffer sb = new StringBuffer (); 236 237 sb.append(Token.T_CONNECT).append(' '); 238 sb.append(Token.T_USER).append(' '); 239 sb.append(sName); 240 241 return sb.toString(); 242 } 243 244 247 Grantee getGrantee() { 248 return grantee; 249 } 250 251 257 void setGrantee(Grantee inGrantee) throws HsqlException { 258 259 if (grantee != null) { 260 Trace.doAssert(false, 261 Trace.getMessage(Trace.CHANGE_GRANTEE) + ": " 262 + sName); 263 } 264 265 grantee = inGrantee; 266 } 267 268 270 274 boolean isAdmin() { 275 return grantee.isAdmin(); 276 } 277 278 289 String [] listGrantedTablePrivileges(HsqlName name) { 290 return grantee.listGrantedTablePrivileges(name); 291 } 292 293 306 HashSet getGrantedClassNames(boolean andToPublic) throws HsqlException { 307 return grantee.getGrantedClassNames(andToPublic); 308 } 309 310 328 IntValueHashMap getRights() { 329 return grantee.getRights(); 330 } 331 332 336 void checkAdmin() throws HsqlException { 337 grantee.checkAdmin(); 338 } 339 340 348 void check(HsqlName dbobject, int rights) throws HsqlException { 349 grantee.check(dbobject, rights); 350 } 351 352 void check(String dbobject) throws HsqlException { 353 grantee.check(dbobject); 354 } 355 356 365 boolean isAccessible(HsqlName dbobject, int rights) throws HsqlException { 366 return grantee.isAccessible(dbobject, rights); 367 } 368 369 373 boolean isAccessible(String dbobject) throws HsqlException { 374 return grantee.isAccessible(dbobject); 375 } 376 377 boolean isAccessible(HsqlName dbobject) throws HsqlException { 378 return grantee.isAccessible(dbobject); 379 } 380 } 381 | Popular Tags |