-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYNCOPE-1847] added PropagationTaskInfoSerializer to avoid serializa…
…tion errors, especially on audit (#929)
- Loading branch information
1 parent
4e02c64
commit 6c2a994
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...org/apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...apache/syncope/core/provisioning/api/serialization/PropagationTaskInfoSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |