|
1 | 1 | package org.cryptomator.hub.api;
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonCreator; |
3 | 4 | import com.fasterxml.jackson.annotation.JsonProperty;
|
4 | 5 | import jakarta.annotation.Nullable;
|
5 | 6 | import org.cryptomator.hub.entities.User;
|
|
10 | 11 |
|
11 | 12 | public final class UserDto extends AuthorityDto {
|
12 | 13 |
|
| 14 | + private final String email; |
| 15 | + private final String language; |
| 16 | + private final Set<DeviceResource.DeviceDto> devices; |
| 17 | + private final String ecdhPublicKey; |
| 18 | + private final String ecdsaPublicKey; |
| 19 | + private final String privateKeys; |
| 20 | + private final String setupCode; |
| 21 | + |
| 22 | + @JsonCreator |
| 23 | + public UserDto( |
| 24 | + @JsonProperty("id") String id, |
| 25 | + @JsonProperty("name") String name, |
| 26 | + @JsonProperty("pictureUrl") String pictureUrl, |
| 27 | + @JsonProperty("email") String email, |
| 28 | + @JsonProperty("language") String language, |
| 29 | + @JsonProperty("devices") Set<DeviceResource.DeviceDto> devices, |
| 30 | + // Accept either "ecdhPublicKey" or the legacy "publicKey" on input |
| 31 | + @Nullable @JsonProperty("ecdhPublicKey") @OnlyBase64Chars String ecdhPublicKey, |
| 32 | + @Nullable @JsonProperty("publicKey") @OnlyBase64Chars String publicKey, |
| 33 | + @Nullable @JsonProperty("ecdsaPublicKey") @OnlyBase64Chars String ecdsaPublicKey, |
| 34 | + // Accept either "privateKeys" or the legacy "privateKey" on input |
| 35 | + @Nullable @JsonProperty("privateKeys") @ValidJWE String privateKeys, |
| 36 | + @Nullable @JsonProperty("privateKey") @ValidJWE String privateKey, |
| 37 | + @Nullable @JsonProperty("setupCode") @ValidJWE String setupCode) { |
| 38 | + super(id, Type.USER, name, pictureUrl); |
| 39 | + this.email = email; |
| 40 | + this.language = language; |
| 41 | + this.devices = devices; |
| 42 | + this.ecdhPublicKey = ecdhPublicKey != null ? ecdhPublicKey : publicKey; |
| 43 | + this.ecdsaPublicKey = ecdsaPublicKey; |
| 44 | + this.privateKeys = privateKeys != null ? privateKeys : privateKey; |
| 45 | + this.setupCode = setupCode; |
| 46 | + } |
| 47 | + |
| 48 | + public UserDto( |
| 49 | + String id, |
| 50 | + String name, |
| 51 | + String pictureUrl, |
| 52 | + String email, |
| 53 | + String language, |
| 54 | + Set<DeviceResource.DeviceDto> devices, |
| 55 | + String ecdhPublicKey, |
| 56 | + String ecdsaPublicKey, |
| 57 | + String privateKeys, |
| 58 | + String setupCode) { |
| 59 | + this(id, name, pictureUrl, email, language, devices, ecdhPublicKey, ecdhPublicKey, ecdsaPublicKey, privateKeys, privateKeys, setupCode); |
| 60 | + } |
| 61 | + |
13 | 62 | @JsonProperty("email")
|
14 |
| - public final String email; |
| 63 | + public String getEmail() { |
| 64 | + return email; |
| 65 | + } |
| 66 | + |
15 | 67 | @JsonProperty("language")
|
16 |
| - public final String language; |
| 68 | + public String getLanguage() { |
| 69 | + return language; |
| 70 | + } |
| 71 | + |
17 | 72 | @JsonProperty("devices")
|
18 |
| - public final Set<DeviceResource.DeviceDto> devices; |
| 73 | + public Set<DeviceResource.DeviceDto> getDevices() { |
| 74 | + return devices; |
| 75 | + } |
| 76 | + |
19 | 77 | @JsonProperty("ecdhPublicKey")
|
20 |
| - public final String ecdhPublicKey; |
21 |
| - @JsonProperty("ecdsaPublicKey") |
22 |
| - public final String ecdsaPublicKey; |
23 |
| - @JsonProperty("privateKey") // singular name for history reasons (don't break client compatibility) |
24 |
| - public final String privateKeys; |
25 |
| - @JsonProperty("setupCode") |
26 |
| - public final String setupCode; |
| 78 | + public String getEcdhPublicKey() { |
| 79 | + return ecdhPublicKey; |
| 80 | + } |
27 | 81 |
|
28 | 82 | /**
|
29 | 83 | * Same as {@link #ecdhPublicKey}, kept for compatibility purposes
|
30 |
| - * @deprecated to be removed when all clients moved to the new DTO field names |
| 84 | + * @deprecated to be removed in Hub 2.0.0, tracked in <a href="https://github.com/cryptomator/hub/issues/316">#316</a> |
31 | 85 | */
|
32 | 86 | @Deprecated(forRemoval = true)
|
33 | 87 | @JsonProperty("publicKey")
|
34 |
| - public final String legacyEcdhPublicKey; |
| 88 | + public String getPublicKey() { |
| 89 | + return ecdhPublicKey; |
| 90 | + } |
35 | 91 |
|
36 |
| - UserDto(@JsonProperty("id") String id, @JsonProperty("name") String name, @JsonProperty("pictureUrl") String pictureUrl, @JsonProperty("email") String email, @JsonProperty("language") String language, @JsonProperty("devices") Set<DeviceResource.DeviceDto> devices, |
37 |
| - @Nullable @JsonProperty("ecdhPublicKey") @OnlyBase64Chars String ecdhPublicKey, @Nullable @JsonProperty("ecdsaPublicKey") @OnlyBase64Chars String ecdsaPublicKey, @Nullable @JsonProperty("privateKeys") @ValidJWE String privateKeys, @Nullable @JsonProperty("setupCode") @ValidJWE String setupCode) { |
38 |
| - super(id, Type.USER, name, pictureUrl); |
39 |
| - this.email = email; |
40 |
| - this.language = language; |
41 |
| - this.devices = devices; |
42 |
| - this.ecdhPublicKey = ecdhPublicKey; |
43 |
| - this.ecdsaPublicKey = ecdsaPublicKey; |
44 |
| - this.privateKeys = privateKeys; |
45 |
| - this.setupCode = setupCode; |
| 92 | + @JsonProperty("ecdsaPublicKey") |
| 93 | + public String getEcdsaPublicKey() { |
| 94 | + return ecdsaPublicKey; |
| 95 | + } |
| 96 | + |
| 97 | + @JsonProperty("privateKeys") |
| 98 | + public String getPrivateKeys() { |
| 99 | + return privateKeys; |
| 100 | + } |
46 | 101 |
|
47 |
| - // duplicate fields to maintain backwards compatibility: |
48 |
| - this.legacyEcdhPublicKey = ecdhPublicKey; |
| 102 | + /** |
| 103 | + * Same as {@link #privateKeys}, kept for compatibility purposes |
| 104 | + * @deprecated to be removed in Hub 2.0.0, tracked in <a href="https://github.com/cryptomator/hub/issues/316">#316</a> |
| 105 | + */ |
| 106 | + @Deprecated(forRemoval = true) |
| 107 | + @JsonProperty("privateKey") |
| 108 | + public String getPrivateKey() { |
| 109 | + return privateKeys; |
| 110 | + } |
| 111 | + |
| 112 | + @JsonProperty("setupCode") |
| 113 | + public String getSetupCode() { |
| 114 | + return setupCode; |
49 | 115 | }
|
50 | 116 |
|
51 | 117 | public static UserDto justPublicInfo(User user) {
|
52 |
| - return new UserDto(user.getId(), user.getName(), user.getPictureUrl(), user.getEmail(), user.getLanguage(), Set.of(), user.getEcdhPublicKey(), user.getEcdsaPublicKey(),null, null); |
| 118 | + return new UserDto( |
| 119 | + user.getId(), |
| 120 | + user.getName(), |
| 121 | + user.getPictureUrl(), |
| 122 | + user.getEmail(), |
| 123 | + user.getLanguage(), |
| 124 | + Set.of(), |
| 125 | + user.getEcdhPublicKey(), |
| 126 | + user.getEcdsaPublicKey(), |
| 127 | + null, |
| 128 | + null); |
53 | 129 | }
|
54 | 130 | }
|
0 commit comments