0
私はレルムを初めて使用しています。私は、レルムサーバ上の異なるユーザの認証に問題があります。 私はサーバーとドメイン分離への後続のログインをテストするために数行のコードを書きました。レルム・サーバーでの認証に問題 - 同じファイルを開くために使用すると構成が異なることはありません
- 私は最初のユーザーでログインし、私はRealmObject(UserApp)を移入
- を[email protected]と私は が
- 私は[email protected]
- でログアウトするサーバーに保存します私はUserAppこのユーザー(ドメイン分離)のために読み込まれていないことを確認し、第2のユーザ[email protected]
- でログインし
- 私がログインするためにもう一度試して次に[email protected]
- とログアウト〜で最初のユーザーは[email protected]ですが、次のエラーメッセージが表示されます。
*java.lang.IllegalArgumentException: Configurations cannot be different if used to open the same file.
Cached configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: [email protected]
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: false, Sessions: 0}
errorHandler: [email protected]
deleteRealmOnLogout: false
waitForInitialRemoteData: false
New configuration:
realmDirectory: /data/user/0/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc
realmFileName : default
canonicalPath: /data/data/com.my.assistant/files/realm-object-server/621c2e6db5e0cf421741f6e9a428c3dc/621c2e6db5e0cf421741f6e9a428c3dc/default
key: [length: 0]
schemaVersion: 0
migration: null
deleteRealmIfMigrationNeeded: false
durability: FULL
schemaMediator: [email protected]
readOnly: false
compactOnLaunch: null
serverUrl: realm://localhost:9080/621c2e6db5e0cf421741f6e9a428c3dc/default
user: {UserId: 621c2e6db5e0cf421741f6e9a428c3dc, AuthUrl: http://localhost:9080/auth, IsValid: true, Sessions: 0}
errorHandler: [email protected]
deleteRealmOnLogout: false
waitForInitialRemoteData: false
at io.realm.RealmCache.validateConfiguration(RealmCache.java:461)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:337)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getInstance(Realm.java:301)
at com.my.assistant.LoginInstrTest2.setConfigurationSyncUser(LoginInstrTest2.java:149)
at com.my.assistant.LoginInstrTest2.loginUser(LoginInstrTest2.java:129)
at com.my.assistant.LoginInstrTest2.veryfyRealmUserInstance(LoginInstrTest2.java:98)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)*
なぜ誰に教えてもらえますか?このコードの私の意図は、領域を使用してアンドロイドアプリケーションの初期ログイン/ログアウトをテストすることです。ユーザーは、異なる資格情報を使用してアプリケーションにログインまたはログアウトする必要があります。新しいユーザーを作成するのではなく、以前に作成したSyncConfigurationを取得する方法が必要なように私には聞こえますが、そうであれば、どうすればいいのかわかりません。
これは私のコードです:
// -----------メインコード:
SyncUser userLogged;
//Login with first user. This time the login completes successfully
userLogged = loginUser("[email protected]", "pluto");
insertUserAppSyncRealm();
RealmResults<UserApp> res = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res.size());
UserApp resUser = res.last();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ID " + resUser.getId());
userLogged.logout();
//Login with second user OK
userLogged = loginUser("[email protected]", "paperino");
RealmResults<UserApp> res2 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll(); //arrivato qui da "Configurations cannot be different if used to open the same file"
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table usertest " + res2.size());
userLogged.logout();
//Login again with first user. This time the login fails ("Configurations cannot be different if used to open the same file")
userLogged = loginUser("[email protected]", "pluto");
RealmResults<UserApp> res3 = realm.where(UserApp.class)
.beginsWith("username", "situs")
.findAll();
System.out.println(" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Size table pippo " + res3.size());
userLogged.logout();
// -----------使用機能:あなたの親切なアドバイスを事前に
public SyncUser loginUser(String username, String password) {
SyncUser userLogged;
SyncCredentials myCredentials = SyncCredentials.usernamePassword(username, password, false);
userLogged = SyncUser.login(myCredentials, authURL);
setConfigurationSyncUser(userLogged);
return userLogged;
}
public void setConfigurationSyncUser(SyncUser user) {
String user1RealmUrl = "realm://localhost:9080/~/default";
SyncConfiguration config = new SyncConfiguration.Builder(user, user1RealmUrl).
errorHandler(new SyncSession.ErrorHandler() {
public void onError(SyncSession session, ObjectServerError error) {
fail("Realm unexpected error: " + error);
}
})
.build();
realm = Realm.getInstance(config); //fails ("Configurations cannot be different if used to open the same file")
}
public void insertUserAppSyncRealm() {
UserApp user = new UserApp();
populateUser(user);
realm.beginTransaction();
realm.insert(user);
realm.commitTransaction();
}
private void populateUser(UserApp user) {
user.setUsername("[email protected]");
user.setPassword("12345678");
user.setId(UUID.randomUUID().toString());
}
おかげで...
これは動作するはずです。問題は、2つの設定の間でエラーハンドラが異なることです: 'com.my.assistant.LoginInstrTest2 $ 1 @ 397b523'対' com.my.assistant.LoginInstrTest2 $ 1 @ cdafa20' –
残念ながら、それはうまくいきませんでした...私また、エラーハンドラを完全に削除しようとしましたが、私は同じエラーが発生します...他のアイデア? – Selvaggia
新しいスタックトレースとログがありますか? – EpicPandaForce