diff --git a/core/src/main/java/org/keycloak/representations/idm/authorization/ResourceRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/authorization/ResourceRepresentation.java index 24a1be728c..b6758cd66b 100644 --- a/core/src/main/java/org/keycloak/representations/idm/authorization/ResourceRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/authorization/ResourceRepresentation.java @@ -182,6 +182,7 @@ public class ResourceRepresentation { } @Deprecated + @JsonSetter("uri") public void setUri(String uri) { if (uri != null && !"".equalsIgnoreCase(uri.trim())) { this.uris = Collections.singleton(uri); @@ -201,15 +202,6 @@ public class ResourceRepresentation { } } - @JsonProperty("uri") - public void addUri(String uri) { - if (this.uris == null) { - this.uris = new HashSet<>(); - } - - uris.add(uri); - } - public void setType(String type) { if (type != null && !"".equalsIgnoreCase(type.trim())) { this.type = type; diff --git a/core/src/test/java/org/keycloak/JsonParserTest.java b/core/src/test/java/org/keycloak/JsonParserTest.java index 965a13c863..3588b48850 100755 --- a/core/src/test/java/org/keycloak/JsonParserTest.java +++ b/core/src/test/java/org/keycloak/JsonParserTest.java @@ -22,11 +22,13 @@ import org.junit.Test; import org.keycloak.representations.IDToken; import org.keycloak.representations.JsonWebToken; import org.keycloak.representations.adapters.config.AdapterConfig; +import org.keycloak.representations.idm.authorization.ResourceRepresentation; import org.keycloak.representations.oidc.OIDCClientRepresentation; import org.keycloak.util.JsonSerialization; import java.io.IOException; import java.io.InputStream; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -153,4 +155,35 @@ public class JsonParserTest { Assert.assertNotNull(clientRep.getJwks()); } + + @Test + public void testResourceRepresentationParsing() throws Exception { + Map resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\" }"); + Assert.assertFalse(resource.containsKey("uri")); + Assert.assertFalse(resource.containsKey("uris")); + + resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uris\": [ \"uri1\", \"uri2\" ] }"); + Assert.assertFalse(resource.containsKey("uri")); + Assert.assertTrue(resource.containsKey("uris")); + Collection uris = (Collection) resource.get("uris"); + Assert.assertEquals(2, uris.size()); + Assert.assertTrue(uris.contains("uri1")); + Assert.assertTrue(uris.contains("uri2")); + + // Backwards compatibility (using old property "uri") + resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uri\": \"uri1\" }"); + Assert.assertFalse(resource.containsKey("uri")); + Assert.assertTrue(resource.containsKey("uris")); + uris = (Collection) resource.get("uris"); + Assert.assertEquals(1, uris.size()); + Assert.assertTrue(uris.contains("uri1")); + } + + private Map parseResourceRepresentation(String resourceJson) throws Exception { + ResourceRepresentation rep = JsonSerialization.readValue(resourceJson, ResourceRepresentation.class); + String repp = JsonSerialization.writeValueAsString(rep); + return JsonSerialization.readValue(repp, Map.class); + } + + } diff --git a/travis-run-tests.sh b/travis-run-tests.sh index a43c456f7d..c731f84710 100755 --- a/travis-run-tests.sh +++ b/travis-run-tests.sh @@ -60,6 +60,8 @@ fi if [ $1 == "unit" ]; then mvn -B test -DskipTestsuite + # Generate documentation to catch potential issues earlier than during the release + mvn test -B -nsu -f services -Pjboss-release fi if [ $1 == "server-group1" ]; then