瀏覽代碼

Fix AccountPolicy sync

pull/52/head
Kristijan Mitrovic 4 年之前
父節點
當前提交
df1d2c9ab5
共有 3 個文件被更改,包括 27 次插入48 次删除
  1. +20
    -28
      bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_account.java
  2. +3
    -2
      bubble-server/src/main/java/bubble/service/account/StandardSyncAccountService.java
  3. +4
    -18
      bubble-server/src/main/java/bubble/service/account/SyncAccountNotification.java

+ 20
- 28
bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_account.java 查看文件

@@ -7,15 +7,13 @@ package bubble.notify;
import bubble.dao.account.AccountDAO;
import bubble.dao.account.AccountPolicyDAO;
import bubble.dao.cloud.BubbleNodeDAO;
import bubble.model.account.Account;
import bubble.model.account.AccountPolicy;
import bubble.model.cloud.AnsibleInstallType;
import bubble.model.cloud.notify.ReceivedNotification;
import bubble.service.account.SyncAccountNotification;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.json.JsonUtil.json;
import static org.cobbzilla.wizard.server.RestServerBase.reportError;

@@ -46,32 +44,26 @@ public class NotificationHandler_sync_account extends ReceivedNotificationHandle
return;
}

notification.getHashedPassword().ifPresent(hashedPassword -> syncAccountPassword(localAccount, hashedPassword));
notification.getAccountPolicy().ifPresent(policy -> syncAccountPolicy(localAccount.getUuid(), policy));
}

private void syncAccountPassword(@NonNull final Account localAccount,
@NonNull final String incomingHashedPassword) {
localAccount.getHashedPassword().setHashedPassword(incomingHashedPassword);

// if we are a node, set skipSync so we don't get caught in an infinite loop
// (the node would notify the sage, which would notify the node, ad infinitum)
localAccount.setSkipSync(configuration.getThisNetwork().getInstallType() == AnsibleInstallType.node);

// update password, if we are a sage, this will notify all networks of password change
accountDAO.update(localAccount);
}

private void syncAccountPolicy(@NonNull final String accountUuid, @NonNull final AccountPolicy incomingPolicy) {
final var localPolicy = accountPolicyDAO.findSingleByAccount(accountUuid);
if (localPolicy == null) {
reportError("sync_account: local AccountPolicy not found for account: " + accountUuid);
return;
final var incomingHashedPassword = notification.getUpdatedHashedPassword();
if (!empty(incomingHashedPassword)) {
localAccount.getHashedPassword().setHashedPassword(incomingHashedPassword);
// if we are a node, set skipSync so we don't get caught in an infinite loop
// (the node would notify the sage, which would notify the node, ad infinitum)
localAccount.setSkipSync(configuration.getThisNetwork().getInstallType() == AnsibleInstallType.node);
// update password, if we are a sage, this will notify all networks of password change
accountDAO.update(localAccount);
}

localPolicy.update(incomingPolicy);
localPolicy.setSkipSync(configuration.getThisNetwork().getInstallType() == AnsibleInstallType.node);
accountPolicyDAO.update(localPolicy);
final var incomingPolicy = notification.getUpdatedPolicy();
if (!empty(incomingPolicy)) {
final var localPolicy = accountPolicyDAO.findSingleByAccount(localAccount.getUuid());
if (localPolicy == null) {
reportError("sync_account: local AccountPolicy not found for account: " + localAccount.getUuid());
return;
}
localPolicy.update(incomingPolicy);
localPolicy.setSkipSync(configuration.getThisNetwork().getInstallType() == AnsibleInstallType.node);
accountPolicyDAO.update(localPolicy);
}
}

}

+ 3
- 2
bubble-server/src/main/java/bubble/service/account/StandardSyncAccountService.java 查看文件

@@ -31,11 +31,12 @@ public class StandardSyncAccountService implements SyncAccountService {
@Autowired private BubbleConfiguration configuration;

public void syncAccount(@NonNull final Account account) {
sync(account, new SyncAccountNotification(account));
sync(account, new SyncAccountNotification(account.getUuid(), account.getHashedPassword().getHashedPassword(),
null));
}

public void syncPolicy(@NonNull final Account account, @NonNull final AccountPolicy policy) {
sync(account, new SyncAccountNotification(account.getUuid(), policy));
sync(account, new SyncAccountNotification(account.getUuid(), null, policy));
}

private void sync(@NonNull final Account account, @NonNull final SyncAccountNotification notification) {


+ 4
- 18
bubble-server/src/main/java/bubble/service/account/SyncAccountNotification.java 查看文件

@@ -4,30 +4,16 @@
*/
package bubble.service.account;

import bubble.model.account.Account;
import bubble.model.account.AccountPolicy;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Optional;

@NoArgsConstructor @Accessors(chain=true)
@AllArgsConstructor @NoArgsConstructor @Accessors(chain=true)
public class SyncAccountNotification {

@Getter @Setter private String accountUuid;
@Getter @Setter private Optional<String> hashedPassword = Optional.empty();
@Getter @Setter private Optional<AccountPolicy> accountPolicy = Optional.empty();

public SyncAccountNotification(@NonNull final Account account) {
this.accountUuid = account.getUuid();
this.hashedPassword = Optional.of(account.getHashedPassword().getHashedPassword());
}

public SyncAccountNotification(@NonNull final String accountUuid, @NonNull final AccountPolicy policy) {
this.accountUuid = accountUuid;
this.accountPolicy = Optional.of(policy);
}
@Getter @Setter private String updatedHashedPassword;
@Getter @Setter private AccountPolicy updatedPolicy;
}

Loading…
取消
儲存