浏览代码

only send first-time message once

tags/v0.1.8
Jonathan Cobb 4 年前
父节点
当前提交
b0c4c198ea
共有 1 个文件被更改,包括 30 次插入28 次删除
  1. +30
    -28
      bubble-server/src/main/java/bubble/server/listener/BubbleFirstTimeListener.java

+ 30
- 28
bubble-server/src/main/java/bubble/server/listener/BubbleFirstTimeListener.java 查看文件

@@ -45,36 +45,38 @@ public class BubbleFirstTimeListener extends RestServerLifecycleListenerBase<Bub
redis.set(configuration.getBean(RedisService.class));

if (FIRST_TIME_FILE.exists()) {
// final FirstTimeType firstTimeType = FirstTimeType.fromString(FileUtil.toStringOrDie(FIRST_TIME_FILE));
final AccountDAO accountDAO = configuration.getBean(AccountDAO.class);
final Account adminAccount = accountDAO.getFirstAdmin();
if (adminAccount == null) {
log.error("onStart: no admin account found, cannot send first time install message, unlocking now");
accountDAO.unlock();
return;
}
final AccountPolicy adminPolicy = configuration.getBean(AccountPolicyDAO.class).findSingleByAccount(adminAccount.getUuid());
if (adminPolicy == null || !adminPolicy.hasVerifiedNonAuthenticatorAccountContacts()) {
log.error("onStart: no AccountPolicy found (or no verified non-authenticator contacts) for admin account ("+adminAccount.getName()+"), cannot send first time install message, unlocking now");
accountDAO.unlock();
return;
}
final BubbleNetwork network = configuration.getThisNetwork();

final String unlockKey = randomAlphabetic(UNLOCK_KEY_LEN).toUpperCase();
redis.get().set(UNLOCK_KEY, unlockKey, EX, UNLOCK_EXPIRATION);
try {
// final FirstTimeType firstTimeType = FirstTimeType.fromString(FileUtil.toStringOrDie(FIRST_TIME_FILE));
final AccountDAO accountDAO = configuration.getBean(AccountDAO.class);
final Account adminAccount = accountDAO.getFirstAdmin();
if (adminAccount == null) {
log.error("onStart: no admin account found, cannot send first time install message, unlocking now");
accountDAO.unlock();
return;
}
final AccountPolicy adminPolicy = configuration.getBean(AccountPolicyDAO.class).findSingleByAccount(adminAccount.getUuid());
if (adminPolicy == null || !adminPolicy.hasVerifiedNonAuthenticatorAccountContacts()) {
log.error("onStart: no AccountPolicy found (or no verified non-authenticator contacts) for admin account (" + adminAccount.getName() + "), cannot send first time install message, unlocking now");
accountDAO.unlock();
return;
}
final BubbleNetwork network = configuration.getThisNetwork();

final SageHelloService helloService = configuration.getBean(SageHelloService.class);
helloService.setUnlockMessage(new AccountMessage()
.setAccount(adminAccount.getUuid())
.setName(network.getUuid())
.setMessageType(AccountMessageType.request)
.setAction(AccountAction.verify)
.setTarget(ActionTarget.network)
.setData(unlockKey));
final String unlockKey = randomAlphabetic(UNLOCK_KEY_LEN).toUpperCase();
redis.get().set(UNLOCK_KEY, unlockKey, EX, UNLOCK_EXPIRATION);

if (!FIRST_TIME_FILE.delete()) {
log.error("onStart: error deleting: "+abs(FIRST_TIME_FILE));
final SageHelloService helloService = configuration.getBean(SageHelloService.class);
helloService.setUnlockMessage(new AccountMessage()
.setAccount(adminAccount.getUuid())
.setName(network.getUuid())
.setMessageType(AccountMessageType.request)
.setAction(AccountAction.verify)
.setTarget(ActionTarget.network)
.setData(unlockKey));
} finally {
if (!FIRST_TIME_FILE.delete()) {
log.error("onStart: error deleting: "+abs(FIRST_TIME_FILE));
}
}
}
}


正在加载...
取消
保存