@@ -7,6 +7,7 @@ package bubble.dao.device; | |||
import bubble.dao.account.AccountOwnedEntityDAO; | |||
import bubble.dao.app.AppDataDAO; | |||
import bubble.model.cloud.BubbleNetwork; | |||
import bubble.model.device.BubbleDeviceType; | |||
import bubble.model.device.Device; | |||
import bubble.server.BubbleConfiguration; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -40,6 +41,13 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> { | |||
return findByUniqueFields("network", networkUuid, "name", name); | |||
} | |||
@Override public Object preCreate(Device device) { | |||
if (device.uninitialized()) { | |||
device.setDeviceType(BubbleDeviceType.uninitialized); | |||
} | |||
return super.preCreate(device); | |||
} | |||
@Override public Device create(Device device) { | |||
if (!device.uninitialized()) { | |||
final String account = device.getAccount(); | |||
@@ -0,0 +1,25 @@ | |||
package bubble.model.device; | |||
import bubble.model.CertType; | |||
import com.fasterxml.jackson.annotation.JsonCreator; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Getter; | |||
import static bubble.ApiConstants.enumFromString; | |||
@AllArgsConstructor | |||
public enum BubbleDeviceType { | |||
uninitialized (null), | |||
windows (CertType.cer), | |||
macosx (CertType.pem), | |||
ios (CertType.pem), | |||
android (CertType.cer), | |||
linux (CertType.crt), | |||
other (null); | |||
@Getter private CertType certType; | |||
@JsonCreator public static BubbleDeviceType fromString (String v) { return enumFromString(BubbleDeviceType.class, v); } | |||
} |
@@ -20,6 +20,8 @@ import org.hibernate.annotations.Type; | |||
import javax.persistence.Column; | |||
import javax.persistence.Entity; | |||
import javax.persistence.EnumType; | |||
import javax.persistence.Enumerated; | |||
import javax.validation.constraints.Size; | |||
import static bubble.ApiConstants.EP_DEVICES; | |||
@@ -40,7 +42,7 @@ import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; | |||
public class Device extends IdentifiableBase implements HasAccount { | |||
public static final String[] CREATE_FIELDS = { UUID, "name", "enabled", "totpKey" }; | |||
public static final String[] UPDATE_FIELDS = { "name", "enabled" }; | |||
public static final String[] UPDATE_FIELDS = { "name", "enabled", "deviceType" }; | |||
public static final String UNINITIALIZED_DEVICE = "__uninitialized_device__"; | |||
public static final String UNINITIALIZED_DEVICE_LIKE = UNINITIALIZED_DEVICE+"%"; | |||
@@ -78,13 +80,17 @@ public class Device extends IdentifiableBase implements HasAccount { | |||
@Getter @Setter private String account; | |||
@ECSearchable @ECField(index=30) | |||
@ECIndex @Enumerated(EnumType.STRING) @Column(nullable=false, length=20) | |||
@Getter @Setter private BubbleDeviceType deviceType; | |||
@ECSearchable @ECField(index=40) | |||
@ECIndex @Column(nullable=false) | |||
@Getter @Setter private Boolean enabled = true; | |||
public boolean uninitialized () { return name.startsWith(UNINITIALIZED_DEVICE); } | |||
public boolean initialized () { return !uninitialized(); } | |||
@ECSearchable @ECField(index=40) | |||
@ECSearchable @ECField(index=50) | |||
@ECForeignKey(entity=BubbleNetwork.class) | |||
@Column(nullable=false, updatable=false, length=UUID_MAXLEN) | |||
@Getter @Setter private String network; | |||
@@ -18,6 +18,7 @@ import bubble.model.cloud.BubbleNetwork; | |||
import bubble.model.cloud.BubbleNode; | |||
import bubble.model.cloud.NetworkKeys; | |||
import bubble.model.cloud.notify.NotificationReceipt; | |||
import bubble.model.device.Device; | |||
import bubble.server.BubbleConfiguration; | |||
import bubble.service.account.StandardAuthenticatorService; | |||
import bubble.service.account.StandardAccountMessageService; | |||
@@ -25,6 +26,7 @@ import bubble.service.backup.RestoreService; | |||
import bubble.service.bill.PromotionService; | |||
import bubble.service.boot.ActivationService; | |||
import bubble.service.boot.SageHelloService; | |||
import bubble.service.cloud.DeviceIdService; | |||
import bubble.service.notify.NotificationService; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.cobbzilla.util.collection.NameAndValue; | |||
@@ -82,6 +84,7 @@ public class AuthResource { | |||
@Autowired private BubbleConfiguration configuration; | |||
@Autowired private StandardAuthenticatorService authenticatorService; | |||
@Autowired private PromotionService promoService; | |||
@Autowired private DeviceIdService deviceIdService; | |||
public Account updateLastLogin(Account account) { return accountDAO.update(account.setLastLogin()); } | |||
@@ -460,9 +463,19 @@ public class AuthResource { | |||
@GET @Path(EP_CA_CERT) | |||
@Produces(CONTENT_TYPE_ANY) | |||
public Response getCaCert(@Context ContainerRequest ctx, | |||
public Response getCaCert(@Context Request req, | |||
@Context ContainerRequest ctx, | |||
@QueryParam("type") CertType type) { | |||
final Account caller = optionalUserPrincipal(ctx); | |||
if (type == null) { | |||
final String remoteHost = getRemoteHost(req); | |||
if (!empty(remoteHost)) { | |||
final Device device = deviceIdService.findDeviceByIp(remoteHost); | |||
if (device != null) { | |||
type = device.getDeviceType().getCertType(); | |||
} | |||
} | |||
} | |||
if (type == null) type = CertType.pem; | |||
final BubbleNetwork thisNet = configuration.getThisNetwork(); | |||
if (thisNet == null) return die("getCaCert: thisNetwork was null"); | |||