mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
03.46.2016 a5809829e89ea42665396a628ea277d253ef9fa1
refs
author Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Thursday, November 3, 2016 09:46 +0100
committer Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Thursday, November 3, 2016 11:18 +0100
commita5809829e89ea42665396a628ea277d253ef9fa1
tree 2bf343e06723b69b6839c6d46c1f4d6dba17d200 tree | zip | gz
parent 2daf3a6626ef94d75790b1e3a118c7cb350e1018 view | diff
Do not put JsonValue inside JSON schemas

With COMMONS-133, OpenDJ is not able to start itself.

Running OpenDJ with the current PR applied results in the following exception:
```
(org.forgerock.opendj.rest2ldap.Rest2LdapJsonConfiguratorTest) Time elapsed: 0.085 sec <<< FAILURE!
java.lang.IllegalStateException: The given Schema name 'frapi:opendj:rest2ldap:object:1.0' already exists but the Schema objects are not equal
at org.forgerock.api.CrestApiProducer.merge(CrestApiProducer.java:129)
at org.forgerock.api.CrestApiProducer.merge(CrestApiProducer.java:45)
at org.forgerock.services.routing.AbstractRouter.buildApi(AbstractRouter.java:369)
at org.forgerock.services.routing.AbstractRouter.notifyDescriptorChange(AbstractRouter.java:342)
at org.forgerock.services.routing.AbstractRouter.api(AbstractRouter.java:290)
at org.forgerock.opendj.rest2ldap.Resource.subResourcesApi(Resource.java:652)
at org.forgerock.opendj.rest2ldap.SubResource$SubResourceHandler.api(SubResource.java:221)
at org.forgerock.opendj.rest2ldap.SubResource$SubResourceHandler.api(SubResource.java:141)
at org.forgerock.services.routing.AbstractRouter.buildApi(AbstractRouter.java:361)
at org.forgerock.services.routing.AbstractRouter.notifyDescriptorChange(AbstractRouter.java:342)
at org.forgerock.services.routing.AbstractRouter.api(AbstractRouter.java:290)
at org.forgerock.opendj.rest2ldap.DescribableRequestHandler.api(DescribableRequestHandler.java:109)
at org.forgerock.opendj.rest2ldap.DescribableRequestHandler.api(DescribableRequestHandler.java:40)
at org.forgerock.services.routing.AbstractRouter.buildApi(AbstractRouter.java:361)
at org.forgerock.services.routing.AbstractRouter.notifyDescriptorChange(AbstractRouter.java:342)
at org.forgerock.services.routing.AbstractRouter.api(AbstractRouter.java:290)
at org.forgerock.json.resource.FilterChain.api(FilterChain.java:272)
at org.forgerock.json.resource.FilterChain.api(FilterChain.java:38)
at org.forgerock.services.routing.AbstractRouter.buildApi(AbstractRouter.java:361)
at org.forgerock.services.routing.AbstractRouter.notifyDescriptorChange(AbstractRouter.java:342)
at org.forgerock.services.routing.AbstractRouter.api(AbstractRouter.java:290)
at org.forgerock.opendj.rest2ldap.DescribableRequestHandler.api(DescribableRequestHandler.java:109)
at org.forgerock.opendj.rest2ldap.Rest2LdapJsonConfiguratorTest.configureEndpoints(Rest2LdapJsonConfiguratorTest.java:81)
at org.forgerock.opendj.rest2ldap.Rest2LdapJsonConfiguratorTest.testConfigureEndpointsWithApiDescription(Rest2LdapJsonConfiguratorTest.java:61)
```

The problem arises in `CrestApiProducer.merge(List<ApiDescription> descriptions)` when it calls `Definitions.put(String, Schema)`.
Here are the lines throwing the exception:
```java
if (definitions.containsKey(name) && !definitions.get(name).equals(schema)) {
throw new IllegalStateException("The given Schema name"
+ " '" + name + "' already exists but the Schema objects are not equal");
}
```
In our case, we are generating the whole type hierarchy for the definition in use for each ApiDescription.
We do that because we cannot possibly know if a type has already been seen before or not.

In this case, this happens when trying to merge definitions for `frapi:opendj:rest2ldap:object:1.0`
which is our base type (think about `java.lang.Object`). They have the same textual json schema.

This happens because `JsonValue.equals(JsonValue)` is never equal.
This is caused by a lack of unwrapping in `JsonValue.put(String, Object)` and other such methods.
It may be fixed by COMMONS-135.

The fix in OpenDJ is to always unwrap the JsonValue before calling `JsonValue.put(String, Object)`.
6 files modified
29 ■■■■■ changed files
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/JsonConstantPropertyMapper.java 7 ●●●●● diff | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ObjectPropertyMapper.java 4 ●●●● diff | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/PropertyMapper.java 8 ●●●● diff | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReferencePropertyMapper.java 2 ●●● diff | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Resource.java 6 ●●●● diff | view | raw | blame | history
opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/SimplePropertyMapper.java 2 ●●● diff | view | raw | blame | history