public synchronized Database createEmbeddedDatabase(String name, ConnectionInfo ci) { Database db = databases.get(name); if (db != null) return db; HashMap<String, String> parameters = new HashMap<>(); for (Entry<Object, Object> e : ci.getProperties().entrySet()) { parameters.put(e.getKey().toString(), e.getValue().toString()); } int id = INSTANCE.allocateObjectId(); db = new Database(id, name, parameters); db.setRunMode(RunMode.EMBEDDED); db.init(); String userName = ci.getUserName(); byte[] userPasswordHash = ci.getUserPasswordHash(); db.createAdminUser(userName, userPasswordHash); addDatabaseObject(getSystemSession(), db); getSystemSession().commit(); return db; }
public static Session getSession(ServerSession originalSession, String url, boolean remote) { Session session = remote ? getQueue(url).poll() : null; // 在本地创建session时不用从缓存队列中找 if (session == null || session.isClosed()) { ConnectionInfo oldCi = originalSession.getConnectionInfo(); // 未来新加的代码如果忘记设置这个字段,出问题时方便查找原因 if (oldCi == null) { throw DbException.throwInternalError(); } ConnectionInfo ci = new ConnectionInfo(url, oldCi.getProperties()); ci.setProperty("IS_LOCAL", "true"); ci.setUserName(oldCi.getUserName()); ci.setUserPasswordHash(oldCi.getUserPasswordHash()); ci.setFilePasswordHash(oldCi.getFilePasswordHash()); ci.setFileEncryptionKey(oldCi.getFileEncryptionKey()); ci.setRemote(remote); // 因为已经精确知道要连哪个节点了,connect不用考虑运行模式,所以用false session = ci.createSession().connect(false); } return session; }
transfer.writeBytes(ci.getUserPasswordHash()); transfer.writeBytes(ci.getFilePasswordHash()); transfer.writeBytes(ci.getFileEncryptionKey());
user = database.findUser(ci.getUserName()); if (user != null) { if (!user.validateUserPasswordHash(ci.getUserPasswordHash())) { user = null; } else {