这适用于OrientDB以前的(beta)版本,不再适用。那么这样做的正确方法是什么?
用例:创建新(Document)数据库时,我想更改admin
用户的密码。代码:
ODatabaseDocumentTx oDb = ...
if (!oDb.exists()) {
// this will create AND open the database with credentials "admin"/"admin"
oDb.create();
// the "admin" user MUST exists, otherwise it is recreated / "repaired" during login, see OSecurityShared.
// So we always use 'admin' as name and only change the password
if ("admin".equals(userName)) {
OSecurityUser admin = oDb.getUser();
admin.setPassword(password);
....
这将抛出java.lang.UnsupportedOperationException
java.lang.UnsupportedOperationException: null
at
com.orientechnologies.orient.core.metadata.security.OImmutableUser.setPassword(OImmutableUser.java:132)
答案 0 :(得分:2)
引入了不可变用户来改进多线程。您始终可以获取基础文档。
尝试这应该工作
ODocument admin = db.getUser().getDocument();
admin.field("password","newpassword");
admin.save();
答案 1 :(得分:1)
这似乎是另一种解决方案:
// change username and password
ODatabaseDocumentTx database = orientGraphFactory.getDatabase();
OCommandSQL cmd = new OCommandSQL("UPDATE ouser "
+ "SET name = '" + "newName" + "', "
+ "password = '" + "newPassword" + "'"
+ " WHERE name = 'admin'");
database.command(cmd).execute();
database.close();
它会触发编码密码的正确数据库挂钩。