Browse Source

Rename sync password to sync account

pull/52/head
Kristijan Mitrovic 4 years ago
parent
commit
64c24d3ff5
18 changed files with 63 additions and 60 deletions
  1. +4
    -4
      bubble-server/src/main/java/bubble/dao/account/AccountDAO.java
  2. +5
    -5
      bubble-server/src/main/java/bubble/model/account/Account.java
  3. +4
    -4
      bubble-server/src/main/java/bubble/model/bill/AccountPlan.java
  4. +3
    -3
      bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java
  5. +1
    -1
      bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java
  6. +9
    -9
      bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_account.java
  7. +1
    -1
      bubble-server/src/main/java/bubble/resources/account/AuthResource.java
  8. +20
    -19
      bubble-server/src/main/java/bubble/service/account/StandardSyncAccountService.java
  9. +2
    -2
      bubble-server/src/main/java/bubble/service/account/SyncAccountNotification.java
  10. +2
    -2
      bubble-server/src/main/java/bubble/service/account/SyncAccountService.java
  11. +1
    -1
      bubble-server/src/main/java/bubble/service/boot/ActivationService.java
  12. +3
    -3
      bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSyncAccountService.java
  13. +1
    -1
      bubble-server/src/main/resources/META-INF/bubble/bubble.properties
  14. +2
    -0
      bubble-server/src/main/resources/db/migration/V2020090601__rename_sync_fileds.sql
  15. +1
    -1
      bubble-server/src/main/resources/messages
  16. +2
    -2
      bubble-server/src/test/resources/models/include/new_bubble.json
  17. +1
    -1
      bubble-server/src/test/resources/models/tests/live/backup_and_restore.json
  18. +1
    -1
      bubble-web

+ 4
- 4
bubble-server/src/main/java/bubble/dao/account/AccountDAO.java View File

@@ -21,7 +21,7 @@ import bubble.model.bill.BubblePlan;
import bubble.model.cloud.*;
import bubble.server.BubbleConfiguration;
import bubble.service.SearchService;
import bubble.service.account.SyncPasswordService;
import bubble.service.account.SyncAccountService;
import bubble.service.boot.SelfNodeService;
import bubble.service.cloud.DeviceIdService;
import bubble.service.stream.RuleEngineService;
@@ -76,7 +76,7 @@ public class AccountDAO extends AbstractCRUDDAO<Account> implements SqlViewSearc
@Autowired private DeviceDAO deviceDAO;
@Autowired private SelfNodeService selfNodeService;
@Autowired private SearchService searchService;
@Autowired private SyncPasswordService syncPasswordService;
@Autowired private SyncAccountService syncAccountService;
@Autowired private ReferralCodeDAO referralCodeDAO;
@Autowired private DeviceIdService deviceService;
@Autowired private RuleEngineService ruleEngineService;
@@ -192,8 +192,8 @@ public class AccountDAO extends AbstractCRUDDAO<Account> implements SqlViewSearc
}
if (context instanceof Account) {
final Account previousState = (Account) context;
if (account.syncPassword() && previousState.isHashedPasswordChanged() && !previousState.skipSyncPassword()) {
syncPasswordService.syncPassword(account);
if (account.sync() && previousState.isHashedPasswordChanged() && !previousState.skipSync()) {
syncAccountService.syncAccount(account);
}
if (previousState.isRefreshShowBlockStats()) {
deviceService.initBlockStats(account);


+ 5
- 5
bubble-server/src/main/java/bubble/model/account/Account.java View File

@@ -80,7 +80,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx;
public class Account extends IdentifiableBaseParentEntity implements TokenPrincipal, SqlViewSearchResult {

public static final String[] UPDATE_FIELDS = {
"url", "description", "autoUpdatePolicy", "syncPassword", "preferredPlan", "showBlockStats"
"url", "description", "autoUpdatePolicy", "sync", "preferredPlan", "showBlockStats"
};
public static final String[] ADMIN_UPDATE_FIELDS = ArrayUtil.append(UPDATE_FIELDS, "suspended", "admin");
public static final String[] CREATE_FIELDS = ArrayUtil.append(ADMIN_UPDATE_FIELDS,
@@ -170,8 +170,8 @@ public class Account extends IdentifiableBaseParentEntity implements TokenPrinci
public Account setTermsAgreed() { return setTermsAgreed(now()); }

@ECField(index=130)
@Getter @Setter private Boolean syncPassword;
public boolean syncPassword() { return syncPassword == null ? true : syncPassword; }
@Getter @Setter private Boolean sync;
public boolean sync() { return sync == null ? true : sync; }

@ECField(index=140)
@Getter @Setter private Boolean showBlockStats;
@@ -187,8 +187,8 @@ public class Account extends IdentifiableBaseParentEntity implements TokenPrinci
}
@JsonIgnore @Transient @Getter @Setter private boolean hashedPasswordChanged = false;
@JsonIgnore @Transient @Getter @Setter private String previousPasswordHash;
@JsonIgnore @Transient @Getter @Setter private Boolean skipSyncPassword;
public boolean skipSyncPassword() { return bool(skipSyncPassword); }
@JsonIgnore @Transient @Getter @Setter private Boolean skipSync;
public boolean skipSync() { return bool(skipSync); }

public static final int MIN_PASSWORD_LENGTH = 8;
public static ConstraintViolationBean validatePassword(String password) {


+ 4
- 4
bubble-server/src/main/java/bubble/model/bill/AccountPlan.java View File

@@ -47,7 +47,7 @@ public class AccountPlan extends IdentifiableBase implements HasNetwork {

public static final String[] CREATE_FIELDS = ArrayUtil.append(UPDATE_FIELDS,
"name", "forkHost", "locale", "timezone", "domain", "network",
"sshKey", "syncPassword", "launchLock", "sendErrors", "sendMetrics", "plan", "footprint");
"sshKey", "syncAccount", "launchLock", "sendErrors", "sendMetrics", "plan", "footprint");

@SuppressWarnings("unused")
public AccountPlan (AccountPlan other) { copy(this, other, CREATE_FIELDS); }
@@ -162,8 +162,8 @@ public class AccountPlan extends IdentifiableBase implements HasNetwork {
@Transient @Getter @Setter private transient String forkHost = null;
public boolean hasForkHost () { return !empty(forkHost); }

@Transient @Getter @Setter private transient Boolean syncPassword = null;
public boolean syncPassword () { return syncPassword == null || syncPassword; }
@Transient @Getter @Setter private transient Boolean syncAccount = null;
public boolean syncAccount() { return syncAccount == null || syncAccount; }

@Transient @Getter @Setter private Boolean launchLock;
public boolean launchLock() { return bool(launchLock); }
@@ -186,7 +186,7 @@ public class AccountPlan extends IdentifiableBase implements HasNetwork {
.setTimezone(getTimezone())
.setAccount(account.getUuid())
.setSshKey(getSshKey())
.setSyncPassword(syncPassword())
.setSyncAccount(syncAccount())
.setLaunchLock(launchLock())
.setSendErrors(sendErrors())
.setSendMetrics(sendMetrics())


+ 3
- 3
bubble-server/src/main/java/bubble/model/cloud/BubbleNetwork.java View File

@@ -61,7 +61,7 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD;
public class BubbleNetwork extends IdentifiableBase implements HasNetwork, HasBubbleTags<BubbleNetwork> {

public static final String[] UPDATE_FIELDS = {
"nickname", "footprint", "description", "locale", "timezone", "state", "syncPassword", "launchLock"
"nickname", "footprint", "description", "locale", "timezone", "state", "syncAccount", "launchLock"
};
public static final String[] CREATE_FIELDS = ArrayUtil.append(UPDATE_FIELDS,
"name", "domain", "sendErrors", "sendMetrics");
@@ -178,8 +178,8 @@ public class BubbleNetwork extends IdentifiableBase implements HasNetwork, HasBu

@ECSearchable @ECField(index=150)
@Column(nullable=false)
@ECIndex @Getter @Setter private Boolean syncPassword;
public boolean syncPassword() { return bool(syncPassword); }
@ECIndex @Getter @Setter private Boolean syncAccount;
public boolean syncAccount() { return bool(syncAccount); }

@ECSearchable @ECField(index=160)
@Column(nullable=false)


+ 1
- 1
bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java View File

@@ -35,7 +35,7 @@ import static org.cobbzilla.util.reflect.ReflectionUtil.instantiate;
public enum NotificationType {

// network-level notifications
health_check, hello_to_sage, hello_from_sage, peer_hello, sync_password,
health_check, hello_to_sage, hello_from_sage, peer_hello, sync_account,
register_backup, retrieve_backup, backup_response, restore_complete, fork,

// upgrade notifications


bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_password.java → bubble-server/src/main/java/bubble/notify/NotificationHandler_sync_account.java View File

@@ -10,7 +10,7 @@ import bubble.model.account.Account;
import bubble.model.cloud.AnsibleInstallType;
import bubble.model.cloud.BubbleNode;
import bubble.model.cloud.notify.ReceivedNotification;
import bubble.service.account.SyncPasswordNotification;
import bubble.service.account.SyncAccountNotification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@@ -18,7 +18,7 @@ import static org.cobbzilla.util.json.JsonUtil.json;
import static org.cobbzilla.wizard.server.RestServerBase.reportError;

@Slf4j
public class NotificationHandler_sync_password extends ReceivedNotificationHandlerBase {
public class NotificationHandler_sync_account extends ReceivedNotificationHandlerBase {

@Autowired private BubbleNodeDAO nodeDAO;
@Autowired private AccountDAO accountDAO;
@@ -26,26 +26,26 @@ public class NotificationHandler_sync_password extends ReceivedNotificationHandl
@Override public void handleNotification(ReceivedNotification n) {
final BubbleNode node = nodeDAO.findByUuid(n.getFromNode());
if (node == null) {
log.warn("sync_password: node not found: "+n.getFromNode());
log.warn("sync_account: node not found: "+n.getFromNode());
} else {
final SyncPasswordNotification notification = json(n.getPayloadJson(), SyncPasswordNotification.class);
final SyncAccountNotification notification = json(n.getPayloadJson(), SyncAccountNotification.class);

final Account account = accountDAO.findByUuid(notification.getAccountUuid());
if (account == null) {
reportError("sync_password: account not found: "+notification.getAccountUuid());
reportError("sync_account: account not found: "+notification.getAccountUuid());
return;
}
if (!account.syncPassword()) {
log.info("sync_password: account "+account.getName()+" has syncPassword disabled, not synchronizing");
if (!account.sync()) {
log.info("sync_account: account "+account.getName()+" has sync disabled, not synchronizing");
return;
}

account.getHashedPassword().setHashedPassword(notification.getHashedPassword());

// if we are a node, set skipSyncPassword so we don't get caught in an infinite loop
// 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)
if (configuration.getThisNetwork().getInstallType() == AnsibleInstallType.node) {
account.setSkipSyncPassword(true);
account.setSkipSync(true);
}

// update password, if we are a sage, this will notify all networks of password change

+ 1
- 1
bubble-server/src/main/java/bubble/resources/account/AuthResource.java View File

@@ -399,7 +399,7 @@ public class AuthResource {
if (sessionAccount == null) {
final BubbleNetwork thisNetwork = configuration.getThisNetwork();
if (thisNetwork != null
&& thisNetwork.syncPassword()
&& thisNetwork.syncAccount()
&& thisNetwork.getInstallType() == AnsibleInstallType.node
&& configuration.hasSageNode()) {
// check if session is valid on sage


bubble-server/src/main/java/bubble/service/account/StandardSyncPasswordService.java → bubble-server/src/main/java/bubble/service/account/StandardSyncAccountService.java View File

@@ -17,61 +17,62 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static bubble.model.cloud.notify.NotificationType.sync_password;
import static bubble.model.cloud.notify.NotificationType.sync_account;
import static org.cobbzilla.wizard.server.RestServerBase.reportError;

@Service @Slf4j
public class StandardSyncPasswordService implements SyncPasswordService {
public class StandardSyncAccountService implements SyncAccountService {

@Autowired private BubbleNetworkDAO networkDAO;
@Autowired private BubbleNodeDAO nodeDAO;
@Autowired private NotificationService notificationService;
@Autowired private BubbleConfiguration configuration;

public void syncPassword(Account account) {
public void syncAccount(Account account) {
final BubbleNetwork thisNetwork = configuration.getThisNetwork();
if (thisNetwork == null) {
// should never happen
log.warn("syncPassword: thisNetwork was null, sync_password is impossible");
log.warn("syncAccount: thisNetwork was null, sync_account is impossible");
return;
}
if (!account.admin()) {
log.info("syncPassword: not syncing non-admin password");
log.info("syncAccount: not syncing non-admin password");
return;
}
if (!account.syncPassword()) {
log.info("syncPassword: password sync disabled for account: "+account.getName());
if (!account.sync()) {
log.info("syncAccount: password sync disabled for account: "+account.getName());
return;
}
final AnsibleInstallType installType = thisNetwork.getInstallType();
final SyncPasswordNotification notification = new SyncPasswordNotification(account);
final SyncAccountNotification notification = new SyncAccountNotification(account);
if (installType == AnsibleInstallType.sage) {
// changing password on sage, notify all bubbles launched by user that have syncPassword == true
// changing password on sage, notify all bubbles launched by user that have syncAccount == true

for (BubbleNetwork network : networkDAO.findByAccount(account.getUuid())) {
if (network.getState() != BubbleNetworkState.running) continue;
if (!network.syncPassword()) continue;
if (!network.syncAccount()) continue;
for (BubbleNode node : nodeDAO.findByNetwork(network.getUuid())) {
if (node.getUuid().equals(configuration.getThisNode().getUuid())) {
log.info("syncPassword: not notifying self");
log.info("syncAccount: not notifying self");
continue;
}
log.info("syncPassword: sending sync_password notification from sage to node: "+node.id());
notificationService.notify(node, sync_password, notification);
log.info("syncAccount: sending sync_account notification from sage to node: "+node.id());
notificationService.notify(node, sync_account, notification);
}
}

} else if (installType == AnsibleInstallType.node) {
if (!thisNetwork.syncPassword()) {
log.info("syncPassword: disabled for node, not sending sync_password notification");
if (!thisNetwork.syncAccount()) {
log.info("syncAccount: disabled for node, not sending sync_account notification");
return;
}
// changing password on node, notify sage, which will then notify all bubbles launched by user that have syncPassword == true
log.info("syncPassword: sending sync_password notification from node to sage: "+configuration.getSageNode());
notificationService.notify(configuration.getSageNode(), sync_password, notification);
// changing password on node, notify sage, which will then notify all bubbles launched by user that have
// syncAccount == true
log.info("syncAccount: sending sync_account notification from node to sage: "+configuration.getSageNode());
notificationService.notify(configuration.getSageNode(), sync_account, notification);

} else {
reportError("syncPassword("+account.getEmail()+"/"+account.getUuid()+"): invalid installType: "+installType);
reportError("syncAccount("+account.getEmail()+"/"+account.getUuid()+"): invalid installType: "+installType);
}
}


bubble-server/src/main/java/bubble/service/account/SyncPasswordNotification.java → bubble-server/src/main/java/bubble/service/account/SyncAccountNotification.java View File

@@ -11,12 +11,12 @@ import lombok.Setter;
import lombok.experimental.Accessors;

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

@Getter @Setter private String accountUuid;
@Getter @Setter private String hashedPassword;

public SyncPasswordNotification(Account account) {
public SyncAccountNotification(Account account) {
this.accountUuid = account.getUuid();
this.hashedPassword = account.getHashedPassword().getHashedPassword();
}

bubble-server/src/main/java/bubble/service/account/SyncPasswordService.java → bubble-server/src/main/java/bubble/service/account/SyncAccountService.java View File

@@ -6,8 +6,8 @@ package bubble.service.account;

import bubble.model.account.Account;

public interface SyncPasswordService {
public interface SyncAccountService {

void syncPassword(Account account);
void syncAccount(Account account);

}

+ 1
- 1
bubble-server/src/main/java/bubble/service/boot/ActivationService.java View File

@@ -173,7 +173,7 @@ public class ActivationService {
.setTag(TAG_PARENT_ACCOUNT, account.getUuid())
.setStorage(networkStorage != null ? networkStorage.getUuid() : localStorage.getUuid())
.setState(BubbleNetworkState.running)
.setSyncPassword(false)
.setSyncAccount(false)
.setLaunchLock(false)
.setSendErrors(false)
.setSendMetrics(false));


bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSyncPasswordService.java → bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSyncAccountService.java View File

@@ -5,14 +5,14 @@
package bubble.service_dbfilter;

import bubble.model.account.Account;
import bubble.service.account.SyncPasswordService;
import bubble.service.account.SyncAccountService;
import org.springframework.stereotype.Service;

import static org.cobbzilla.util.daemon.ZillaRuntime.notSupported;

@Service
public class DbFilterSyncPasswordService implements SyncPasswordService {
public class DbFilterSyncAccountService implements SyncAccountService {

@Override public void syncPassword(Account account) { notSupported("syncPassword"); }
@Override public void syncAccount(Account account) { notSupported("syncAccount"); }

}

+ 1
- 1
bubble-server/src/main/resources/META-INF/bubble/bubble.properties View File

@@ -1 +1 @@
bubble.version=Adventure 1.0.7
bubble.version=Kris 0.0.2

+ 2
- 0
bubble-server/src/main/resources/db/migration/V2020090601__rename_sync_fileds.sql View File

@@ -0,0 +1,2 @@
ALTER TABLE account ALTER COLUMN sync_password RENAME TO sync;
ALTER TABLE bubble_network ALTER COLUMN sync_password RENAME TO sync_account;

+ 1
- 1
bubble-server/src/main/resources/messages

@@ -1 +1 @@
Subproject commit 9fcd7bc0a768b124b09b7e8995c27fc94dedf9d8
Subproject commit 98259e3f0853693a3043489c3b8ce1d516b8b6e6

+ 2
- 2
bubble-server/src/test/resources/models/include/new_bubble.json View File

@@ -22,7 +22,7 @@
"bubbleConnectionVar": "bubbleConnection",
"bubbleUserSessionVar": "bubbleUserSession",
"bubbleUserVar": "bubbleUserAccount",
"syncPassword": null,
"syncAccount": null,
"sendErrors": null,
"sendMetrics": null
}
@@ -146,7 +146,7 @@
"timezone": "<<timezone>>",
"plan": "<<plan>>",
"footprint": "<<footprint>>",
"syncPassword": <<syncPassword>>,
"syncAccount": <<syncAccount>>,
"sendErrors": <<sendErrors>>,
"sendMetrics": <<sendMetrics>>,
"paymentMethodObject": {


+ 1
- 1
bubble-server/src/test/resources/models/tests/live/backup_and_restore.json View File

@@ -49,7 +49,7 @@
"plan": "bubble",
"networkVar": "bubbleNetwork",
"bubbleConnectionVar": "bubbleConnection",
"syncPassword": true,
"syncAccount": true,
"sendErrors": true,
"sendMetrics": true
}


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit 58137b47c8488c172508eb74ee93b1529646513c
Subproject commit d542bb482667a094ed2468ef92786052416329b5

Loading…
Cancel
Save