|
|
@@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |