|
11 | 11 | import lombok.*;
|
12 | 12 | import lombok.experimental.SuperBuilder;
|
13 | 13 | import lombok.extern.jackson.Jacksonized;
|
| 14 | +import org.apache.commons.collections4.CollectionUtils; |
| 15 | +import org.apache.commons.collections4.ListUtils; |
14 | 16 | import org.apache.commons.collections4.SetUtils;
|
15 | 17 | import org.apache.commons.lang3.StringUtils;
|
16 | 18 | import org.lowcoder.domain.mongodb.AfterMongodbRead;
|
@@ -79,8 +81,7 @@ public class User extends HasIdAndAuditing implements BeforeMongodbWrite, AfterM
|
79 | 81 | /**
|
80 | 82 | * Only used for mongodb (de)serialization
|
81 | 83 | */
|
82 |
| - @Builder.Default |
83 |
| - private List<Object> apiKeys = new ArrayList<>(); |
| 84 | + private List<Object> apiKeys; |
84 | 85 |
|
85 | 86 | @Transient
|
86 | 87 | @JsonIgnore
|
@@ -143,15 +144,20 @@ public void markAsDeleted() {
|
143 | 144 |
|
144 | 145 | @Override
|
145 | 146 | public void beforeMongodbWrite(MongodbInterceptorContext context) {
|
146 |
| - this.apiKeysList.forEach(apiKey -> apiKey.doEncrypt(s -> context.encryptionService().encryptString(s))); |
147 |
| - apiKeys = JsonUtils.fromJsonSafely(JsonUtils.toJsonSafely(apiKeysList, SerializeConfig.JsonViews.Internal.class), new TypeReference<>() { |
148 |
| - }, new ArrayList<>()); |
| 147 | + if (CollectionUtils.isNotEmpty(this.apiKeysList)) { |
| 148 | + this.apiKeysList.forEach(apiKey -> apiKey.doEncrypt(s -> context.encryptionService().encryptString(s))); |
| 149 | + apiKeys = JsonUtils.fromJsonSafely(JsonUtils.toJsonSafely(apiKeysList, SerializeConfig.JsonViews.Internal.class), new TypeReference<>() { |
| 150 | + }, new ArrayList<>()); |
| 151 | + } |
149 | 152 | }
|
150 | 153 |
|
151 | 154 | @Override
|
152 | 155 | public void afterMongodbRead(MongodbInterceptorContext context) {
|
153 |
| - this.apiKeysList = JsonUtils.fromJsonSafely(JsonUtils.toJson(apiKeys), new TypeReference<>() { |
154 |
| - }, new ArrayList<>()); |
155 |
| - this.apiKeysList.forEach(authConfig -> authConfig.doDecrypt(s -> context.encryptionService().decryptString(s))); |
| 156 | + if (CollectionUtils.isNotEmpty(apiKeys)) |
| 157 | + { |
| 158 | + this.apiKeysList = JsonUtils.fromJsonSafely(JsonUtils.toJson(apiKeys), new TypeReference<>() { |
| 159 | + }, new ArrayList<>()); |
| 160 | + this.apiKeysList.forEach(authConfig -> authConfig.doDecrypt(s -> context.encryptionService().decryptString(s))); |
| 161 | + } |
156 | 162 | }
|
157 | 163 | }
|
0 commit comments