@Override public String toString() { return "#" + serialId + " (user: " + user.getName() + ")"; }
@Override public Session createSession(Properties ci) { String userName = ci.getProperty("user"); String password = ci.getProperty("password"); if (userName == null) { userName = Database.SYSTEM_USER_NAME; } User user = database.findUser(userName); if (user == null) { // users is the last thing we add, so if no user is around, // the database is new (or not initialized correctly) user = new User(database, userName); user.setAdmin(true); user.setPassword(password); database.addDatabaseObject(user); } User userObject = database.getUser(userName); Session session = database.createSession(userObject); return session; }
/** * Checks that this user has the given rights for this database object. * * @param table the database object * @param rightMask the rights required * @throws DbException if this user does not have the required rights */ public void checkRight(Table table, int rightMask) { if (!hasRight(table, rightMask)) { throw DbException.get(ErrorCode.NOT_ENOUGH_RIGHTS_FOR_1, table.getSQL()); } }
result = ValueString.get(session.getUser().getName(), database.getMode().treatEmptyStringsAsNull); break; session.getUser().checkAdmin(); result = ValueInt.get(Utils.getMemoryFree()); break; case MEMORY_USED: session.getUser().checkAdmin(); result = ValueInt.get(Utils.getMemoryUsed()); break;
private static boolean cancelStatement(Session session, int targetSessionId) { session.getUser().checkAdmin(); Session[] sessions = session.getDatabase().getSessions(); for (Session s : sessions) { if (s.getId() == targetSessionId) { Command c = s.getCurrentCommand(); if (c == null) { return false; } c.cancel(); return true; } } return false; }
public User(Database database, String userName) { initDbObjectBase(database, userName); }
switch (type) { case SetTypes.ALLOW_LITERALS: { session.getUser().checkAdmin(); int value = getIntValue(); if (value < 0 || value > 2) { session.getUser().checkAdmin(); final boolean binaryUnsigned = database.getCompareMode().isBinaryUnsigned(); CompareMode compareMode; session.getUser().checkAdmin(); CompareMode currentMode = database.getCompareMode(); CompareMode newMode; session.getUser().checkAdmin(); database.setIgnoreCase(getIntValue() == 1); break; session.getUser().checkAdmin(); database.setMaxMemoryRows(getIntValue()); break; session.getUser().checkAdmin(); int value = getIntValue(); database.setMaxOperationMemory(value); session.getUser().checkAdmin(); database.setMode(mode);
private synchronized void openDatabase() { User systemUser = new User(this, SYSTEM_USER_NAME); systemUser.setAdmin(true); systemUser.setPassword(SYSTEM_USER_NAME); users.put(SYSTEM_USER_NAME, systemUser);
/** * Check that this user does not own any schema. An exception is thrown if * he owns one or more schemas. * * @throws DbException if this user owns a schema */ public void checkOwnsNoSchemas() { for (Schema s : database.getAllSchemas()) { if (this == s.getOwner()) { throw DbException.get(ErrorCode.CANNOT_DROP_2, getName(), s.getName()); } } }
private boolean initValue(SQLMethodInvokeExpr expr) { Session session = target.getSession().getDbSession(); List<SQLExpr> parameters = expr.getParameters(); if (!parameters.isEmpty()) { return false; } String name = expr.getMethodName().toLowerCase(); if ("user".equals(name) || "current_user".equals(name)) { expr.putAttribute(EVAL_VALUE, session.getUser().getName()); return true; } else if ("connection_id".equals(name)) { long threadId = target.getSession().getThreadId(); expr.putAttribute(EVAL_VALUE, threadId); return true; } else if ("version_comment".equals(name)) { expr.putAttribute(EVAL_VALUE, MySQLServer.VERSION_COMMENT); return true; } return false; }
private CreateSchema parseCreateSchema() { CreateSchema command = new CreateSchema(session); command.setIfNotExists(readIfNotExists()); command.setSchemaName(readUniqueIdentifier()); if (readIf("AUTHORIZATION")) { command.setAuthorization(readUniqueIdentifier()); } else { command.setAuthorization(session.getUser().getName()); } return command; }