This is an automated email from the ASF dual-hosted git repository.
andreapatricelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new 6c2a994f36 [SYNCOPE-1847] added PropagationTaskInfoSerializer to avoid
serialization errors, especially on audit (#929)
6c2a994f36 is described below
commit 6c2a994f36caa50f76d5038bf8ea5949d279f881
Author: Andrea Patricelli <[email protected]>
AuthorDate: Thu Dec 5 09:32:21 2024 +0100
[SYNCOPE-1847] added PropagationTaskInfoSerializer to avoid serialization
errors, especially on audit (#929)
---
.../provisioning/api/serialization/POJOHelper.java | 2 +
.../PropagationTaskInfoSerializer.java | 61 +++++++++++++++++
.../PropagationTaskInfoSerializerTest.java | 77 ++++++++++++++++++++++
3 files changed, 140 insertions(+)
diff --git
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
index 7b1bc79165..ba65dffa00 100644
---
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
+++
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/POJOHelper.java
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import
org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeDelta;
@@ -46,6 +47,7 @@ public final class POJOHelper {
pojoModule.addSerializer(Attribute.class, new AttributeSerializer());
pojoModule.addSerializer(AttributeDelta.class, new
AttributeDeltaSerializer());
pojoModule.addSerializer(SyncToken.class, new SyncTokenSerializer());
+ pojoModule.addSerializer(PropagationTaskInfo.class, new
PropagationTaskInfoSerializer());
pojoModule.addDeserializer(GuardedString.class, new
GuardedStringDeserializer());
pojoModule.addDeserializer(Attribute.class, new
AttributeDeserializer());
pojoModule.addDeserializer(AttributeDelta.class, new
AttributeDeltaDeserializer());
diff --git
a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializer.java
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializer.java
new file mode 100644
index 0000000000..215a4546fb
--- /dev/null
+++
b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializer.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import
org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
+
+class PropagationTaskInfoSerializer extends
JsonSerializer<PropagationTaskInfo> {
+
+ @Override
+ public void serialize(final PropagationTaskInfo propagationTaskInfo, final
JsonGenerator jgen,
+ final SerializerProvider serializerProvider) throws IOException {
+
+ jgen.writeStartObject();
+
+ jgen.writeStringField("key", propagationTaskInfo.getKey());
+
+ if (propagationTaskInfo.getResource() != null) {
+ jgen.writeStringField("resource",
propagationTaskInfo.getResource().getKey());
+ }
+ if (propagationTaskInfo.getOperation() != null) {
+ jgen.writeStringField("operation",
propagationTaskInfo.getOperation().name());
+ }
+ if (propagationTaskInfo.getObjectClass() != null) {
+ jgen.writeStringField("objectClass",
propagationTaskInfo.getObjectClass().getObjectClassValue());
+ }
+ if (propagationTaskInfo.getAnyTypeKind() != null) {
+ jgen.writeStringField("anyTypeKind",
propagationTaskInfo.getAnyTypeKind().name());
+ }
+ jgen.writeStringField("anyType", propagationTaskInfo.getAnyType());
+ jgen.writeStringField("entityKey", propagationTaskInfo.getEntityKey());
+ jgen.writeStringField("connObjectKey",
propagationTaskInfo.getConnObjectKey());
+ jgen.writeStringField("oldConnObjectKey",
propagationTaskInfo.getOldConnObjectKey());
+ jgen.writeObjectField("propagationData",
propagationTaskInfo.getPropagationData());
+ if (propagationTaskInfo.getConnector() != null) {
+ jgen.writeObjectField("connector",
propagationTaskInfo.getConnector().getConnInstance().getKey());
+ }
+ jgen.writeObjectField("beforeObj", propagationTaskInfo.getBeforeObj());
+
+ jgen.writeEndObject();
+ }
+}
diff --git
a/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializerTest.java
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializerTest.java
new file mode 100644
index 0000000000..e77762cb04
--- /dev/null
+++
b/core/provisioning-api/src/test/java/org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializerTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.api.serialization;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import java.util.UUID;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.ResourceOperation;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.persistence.api.entity.ExternalResource;
+import org.apache.syncope.core.persistence.api.entity.task.PropagationData;
+import org.apache.syncope.core.provisioning.api.AbstractTest;
+import org.apache.syncope.core.provisioning.api.Connector;
+import
org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+
+public class PropagationTaskInfoSerializerTest extends AbstractTest {
+
+ @Test
+ public void propagationTaskInfoSerializer(final @Mock JsonGenerator jgen,
final @Mock SerializerProvider sp)
+ throws IOException {
+
+ PropagationTaskInfoSerializer serializer = new
PropagationTaskInfoSerializer();
+ ExternalResource resource = mock(ExternalResource.class);
+ when(resource.getKey()).thenReturn("resource-ldap");
+ PropagationData propagationData = mock(PropagationData.class);
+ PropagationTaskInfo source =
+ new PropagationTaskInfo(resource,
+ ResourceOperation.UPDATE,
+ ObjectClass.ACCOUNT,
+ AnyTypeKind.USER,
+ AnyTypeKind.USER.name(),
+ UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(),
+ propagationData);
+ source.setKey(UUID.randomUUID().toString());
+ Connector connector = mock(Connector.class);
+ ConnInstance connInstance = mock(ConnInstance.class);
+ when(connInstance.getKey()).thenReturn(UUID.randomUUID().toString());
+ when(connector.getConnInstance()).thenReturn(connInstance);
+ source.setConnector(connector);
+ serializer.serialize(source, jgen, sp);
+ verify(jgen).writeStartObject();
+ verify(jgen).writeStringField("key", source.getKey());
+ verify(jgen).writeStringField("anyType", source.getAnyType());
+ verify(jgen).writeStringField("entityKey", source.getEntityKey());
+ verify(jgen).writeStringField("connObjectKey",
source.getConnObjectKey());
+ verify(jgen).writeStringField("oldConnObjectKey",
source.getOldConnObjectKey());
+ verify(jgen).writeObjectField("propagationData",
source.getPropagationData());
+ verify(jgen).writeObjectField("connector",
source.getConnector().getConnInstance().getKey());
+ verify(jgen).writeEndObject();
+ }
+}