From 4ae981f484c87a7566b77861782a34d0a45a4dae Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Wed, 18 Feb 2015 09:23:09 -0500 Subject: [PATCH] updated data layer and unit tests --- .../service/impl/MITREidDataService_1_0.java | 3 +- .../service/impl/MITREidDataService_1_1.java | 7 +++- .../service/impl/MITREidDataService_1_2.java | 12 +++++-- .../impl/TestMITREidDataService_1_0.java | 12 +++---- .../impl/TestMITREidDataService_1_1.java | 23 ++++++++---- .../impl/TestMITREidDataService_1_2.java | 35 ++++++++++++------- 6 files changed, 61 insertions(+), 31 deletions(-) diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_0.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_0.java index 8222663b2..180025c3f 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_0.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_0.java @@ -732,7 +732,8 @@ public class MITREidDataService_1_0 extends AbstractMITREidDataService { } else if (name.equals("description")) { scope.setDescription(reader.nextString()); } else if (name.equals("allowDynReg")) { - scope.setAllowDynReg(reader.nextBoolean()); + // previously "allowDynReg" scopes are now tagged as "not restricted" and vice versa + scope.setRestricted(!reader.nextBoolean()); } else if (name.equals("defaultScope")) { scope.setDefaultScope(reader.nextBoolean()); } else if (name.equals("icon")) { diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_1.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_1.java index d835deb93..098a98188 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_1.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_1.java @@ -742,9 +742,14 @@ public class MITREidDataService_1_1 extends AbstractMITREidDataService { } else if (name.equals("description")) { scope.setDescription(reader.nextString()); } else if (name.equals("allowDynReg")) { - scope.setAllowDynReg(reader.nextBoolean()); + // previously "allowDynReg" scopes are now tagged as "not restricted" and vice versa + scope.setRestricted(!reader.nextBoolean()); } else if (name.equals("defaultScope")) { scope.setDefaultScope(reader.nextBoolean()); + } else if (name.equals("structured")) { + scope.setStructured(reader.nextBoolean()); + } else if (name.equals("structuredParameter")) { + scope.setStructuredParamDescription(reader.nextString()); } else if (name.equals("icon")) { scope.setIcon(reader.nextString()); } else { diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_2.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_2.java index 0f33a7c7f..ea37a1543 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_2.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_2.java @@ -425,7 +425,9 @@ public class MITREidDataService_1_2 extends AbstractMITREidDataService { writer.name("description").value(sysScope.getDescription()); writer.name("icon").value(sysScope.getIcon()); writer.name("value").value(sysScope.getValue()); - writer.name("allowDynReg").value(sysScope.isAllowDynReg()); + writer.name("restricted").value(sysScope.isRestricted()); + writer.name("structured").value(sysScope.isStructured()); + writer.name("structuredParameter").value(sysScope.getStructuredParamDescription()); writer.name("defaultScope").value(sysScope.isDefaultScope()); writer.endObject(); logger.debug("Wrote system scope {}", sysScope.getId()); @@ -1077,12 +1079,16 @@ public class MITREidDataService_1_2 extends AbstractMITREidDataService { scope.setValue(reader.nextString()); } else if (name.equals("description")) { scope.setDescription(reader.nextString()); - } else if (name.equals("allowDynReg")) { - scope.setAllowDynReg(reader.nextBoolean()); + } else if (name.equals("restricted")) { + scope.setRestricted(reader.nextBoolean()); } else if (name.equals("defaultScope")) { scope.setDefaultScope(reader.nextBoolean()); } else if (name.equals("icon")) { scope.setIcon(reader.nextString()); + } else if (name.equals("structured")) { + scope.setStructured(reader.nextBoolean()); + } else if (name.equals("structuredParameter")) { + scope.setStructuredParamDescription(reader.nextString()); } else { logger.debug("found unexpected entry"); reader.skipValue(); diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_0.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_0.java index 7c8967bcf..6a1a0a90b 100644 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_0.java +++ b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_0.java @@ -761,7 +761,7 @@ public class TestMITREidDataService_1_0 { scope1.setId(1L); scope1.setValue("scope1"); scope1.setDescription("Scope 1"); - scope1.setAllowDynReg(false); + scope1.setRestricted(true); scope1.setDefaultScope(false); scope1.setIcon("glass"); @@ -769,7 +769,7 @@ public class TestMITREidDataService_1_0 { scope2.setId(2L); scope2.setValue("scope2"); scope2.setDescription("Scope 2"); - scope2.setAllowDynReg(true); + scope2.setRestricted(false); scope2.setDefaultScope(false); scope2.setIcon("ball"); @@ -777,7 +777,7 @@ public class TestMITREidDataService_1_0 { scope3.setId(3L); scope3.setValue("scope3"); scope3.setDescription("Scope 3"); - scope3.setAllowDynReg(true); + scope3.setRestricted(false); scope3.setDefaultScope(true); scope3.setIcon("road"); @@ -812,19 +812,19 @@ public class TestMITREidDataService_1_0 { assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription())); assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon())); assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope())); - assertThat(savedScopes.get(0).isAllowDynReg(), equalTo(scope1.isAllowDynReg())); + assertThat(savedScopes.get(0).isRestricted(), equalTo(scope1.isRestricted())); assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue())); assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription())); assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon())); assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope())); - assertThat(savedScopes.get(1).isAllowDynReg(), equalTo(scope2.isAllowDynReg())); + assertThat(savedScopes.get(1).isRestricted(), equalTo(scope2.isRestricted())); assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue())); assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription())); assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon())); assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope())); - assertThat(savedScopes.get(2).isAllowDynReg(), equalTo(scope3.isAllowDynReg())); + assertThat(savedScopes.get(2).isRestricted(), equalTo(scope3.isRestricted())); } diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_1.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_1.java index 9f3cef581..190c426e7 100644 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_1.java +++ b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_1.java @@ -80,6 +80,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; @RunWith(MockitoJUnitRunner.class) +@SuppressWarnings(value = {"rawtypes", "unchecked"}) public class TestMITREidDataService_1_1 { @Mock @@ -761,7 +762,7 @@ public class TestMITREidDataService_1_1 { scope1.setId(1L); scope1.setValue("scope1"); scope1.setDescription("Scope 1"); - scope1.setAllowDynReg(false); + scope1.setRestricted(true); scope1.setDefaultScope(false); scope1.setIcon("glass"); @@ -769,7 +770,7 @@ public class TestMITREidDataService_1_1 { scope2.setId(2L); scope2.setValue("scope2"); scope2.setDescription("Scope 2"); - scope2.setAllowDynReg(true); + scope2.setRestricted(false); scope2.setDefaultScope(false); scope2.setIcon("ball"); @@ -777,9 +778,11 @@ public class TestMITREidDataService_1_1 { scope3.setId(3L); scope3.setValue("scope3"); scope3.setDescription("Scope 3"); - scope3.setAllowDynReg(true); + scope3.setRestricted(false); scope3.setDefaultScope(true); scope3.setIcon("road"); + scope3.setStructured(true); + scope3.setStructuredParamDescription("Structured Parameter"); String configJson = "{" + "\"" + MITREidDataService.CLIENTS + "\": [], " + @@ -793,7 +796,7 @@ public class TestMITREidDataService_1_1 { "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"allowDynReg\":false,\"defaultScope\":false}," + "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"allowDynReg\":true,\"defaultScope\":false}," + - "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true}" + + "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true,\"structured\":true,\"structuredParameter\":\"Structured Parameter\"}" + " ]" + "}"; @@ -812,19 +815,25 @@ public class TestMITREidDataService_1_1 { assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription())); assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon())); assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope())); - assertThat(savedScopes.get(0).isAllowDynReg(), equalTo(scope1.isAllowDynReg())); + assertThat(savedScopes.get(0).isRestricted(), equalTo(scope1.isRestricted())); + assertThat(savedScopes.get(0).isStructured(), equalTo(scope1.isStructured())); + assertThat(savedScopes.get(0).getStructuredParamDescription(), equalTo(scope1.getStructuredParamDescription())); assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue())); assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription())); assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon())); assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope())); - assertThat(savedScopes.get(1).isAllowDynReg(), equalTo(scope2.isAllowDynReg())); + assertThat(savedScopes.get(1).isRestricted(), equalTo(scope2.isRestricted())); + assertThat(savedScopes.get(1).isStructured(), equalTo(scope2.isStructured())); + assertThat(savedScopes.get(1).getStructuredParamDescription(), equalTo(scope2.getStructuredParamDescription())); assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue())); assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription())); assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon())); assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope())); - assertThat(savedScopes.get(2).isAllowDynReg(), equalTo(scope3.isAllowDynReg())); + assertThat(savedScopes.get(2).isRestricted(), equalTo(scope3.isRestricted())); + assertThat(savedScopes.get(2).isStructured(), equalTo(scope3.isStructured())); + assertThat(savedScopes.get(2).getStructuredParamDescription(), equalTo(scope3.getStructuredParamDescription())); } diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java index 6e4651f5c..e899fa644 100644 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java +++ b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestMITREidDataService_1_2.java @@ -90,6 +90,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; @RunWith(MockitoJUnitRunner.class) +@SuppressWarnings(value = {"rawtypes", "unchecked"}) public class TestMITREidDataService_1_2 { @Mock @@ -1546,7 +1547,7 @@ public class TestMITREidDataService_1_2 { scope1.setId(1L); scope1.setValue("scope1"); scope1.setDescription("Scope 1"); - scope1.setAllowDynReg(false); + scope1.setRestricted(true); scope1.setDefaultScope(false); scope1.setIcon("glass"); @@ -1554,7 +1555,7 @@ public class TestMITREidDataService_1_2 { scope2.setId(2L); scope2.setValue("scope2"); scope2.setDescription("Scope 2"); - scope2.setAllowDynReg(true); + scope2.setRestricted(false); scope2.setDefaultScope(false); scope2.setIcon("ball"); @@ -1562,7 +1563,7 @@ public class TestMITREidDataService_1_2 { scope3.setId(3L); scope3.setValue("scope3"); scope3.setDescription("Scope 3"); - scope3.setAllowDynReg(true); + scope3.setRestricted(false); scope3.setDefaultScope(true); scope3.setIcon("road"); @@ -1640,7 +1641,7 @@ public class TestMITREidDataService_1_2 { assertThat(scope.get("value").getAsString(), equalTo(compare.getValue())); assertThat(scope.get("description").getAsString(), equalTo(compare.getDescription())); assertThat(scope.get("icon").getAsString(), equalTo(compare.getIcon())); - assertThat(scope.get("allowDynReg").getAsBoolean(), equalTo(compare.isAllowDynReg())); + assertThat(scope.get("restricted").getAsBoolean(), equalTo(compare.isRestricted())); assertThat(scope.get("defaultScope").getAsBoolean(), equalTo(compare.isDefaultScope())); checked.add(compare); } @@ -1656,7 +1657,7 @@ public class TestMITREidDataService_1_2 { scope1.setId(1L); scope1.setValue("scope1"); scope1.setDescription("Scope 1"); - scope1.setAllowDynReg(false); + scope1.setRestricted(true); scope1.setDefaultScope(false); scope1.setIcon("glass"); @@ -1664,7 +1665,7 @@ public class TestMITREidDataService_1_2 { scope2.setId(2L); scope2.setValue("scope2"); scope2.setDescription("Scope 2"); - scope2.setAllowDynReg(true); + scope2.setRestricted(false); scope2.setDefaultScope(false); scope2.setIcon("ball"); @@ -1672,9 +1673,11 @@ public class TestMITREidDataService_1_2 { scope3.setId(3L); scope3.setValue("scope3"); scope3.setDescription("Scope 3"); - scope3.setAllowDynReg(true); + scope3.setRestricted(false); scope3.setDefaultScope(true); scope3.setIcon("road"); + scope3.setStructured(true); + scope3.setStructuredParamDescription("Structured Parameter"); String configJson = "{" + "\"" + MITREidDataService.CLIENTS + "\": [], " + @@ -1686,9 +1689,9 @@ public class TestMITREidDataService_1_2 { "\"" + MITREidDataService.AUTHENTICATIONHOLDERS + "\": [], " + "\"" + MITREidDataService.SYSTEMSCOPES + "\": [" + - "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"allowDynReg\":false,\"defaultScope\":false}," + - "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"allowDynReg\":true,\"defaultScope\":false}," + - "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"allowDynReg\":true,\"defaultScope\":true}" + + "{\"id\":1,\"description\":\"Scope 1\",\"icon\":\"glass\",\"value\":\"scope1\",\"restricted\":true,\"defaultScope\":false}," + + "{\"id\":2,\"description\":\"Scope 2\",\"icon\":\"ball\",\"value\":\"scope2\",\"restricted\":false,\"defaultScope\":false}," + + "{\"id\":3,\"description\":\"Scope 3\",\"icon\":\"road\",\"value\":\"scope3\",\"restricted\":false,\"defaultScope\":true,\"structured\":true,\"structuredParameter\":\"Structured Parameter\"}" + " ]" + "}"; @@ -1707,19 +1710,25 @@ public class TestMITREidDataService_1_2 { assertThat(savedScopes.get(0).getDescription(), equalTo(scope1.getDescription())); assertThat(savedScopes.get(0).getIcon(), equalTo(scope1.getIcon())); assertThat(savedScopes.get(0).isDefaultScope(), equalTo(scope1.isDefaultScope())); - assertThat(savedScopes.get(0).isAllowDynReg(), equalTo(scope1.isAllowDynReg())); + assertThat(savedScopes.get(0).isRestricted(), equalTo(scope1.isRestricted())); + assertThat(savedScopes.get(0).isStructured(), equalTo(scope1.isStructured())); + assertThat(savedScopes.get(0).getStructuredParamDescription(), equalTo(scope1.getStructuredParamDescription())); assertThat(savedScopes.get(1).getValue(), equalTo(scope2.getValue())); assertThat(savedScopes.get(1).getDescription(), equalTo(scope2.getDescription())); assertThat(savedScopes.get(1).getIcon(), equalTo(scope2.getIcon())); assertThat(savedScopes.get(1).isDefaultScope(), equalTo(scope2.isDefaultScope())); - assertThat(savedScopes.get(1).isAllowDynReg(), equalTo(scope2.isAllowDynReg())); + assertThat(savedScopes.get(1).isRestricted(), equalTo(scope2.isRestricted())); + assertThat(savedScopes.get(1).isStructured(), equalTo(scope2.isStructured())); + assertThat(savedScopes.get(1).getStructuredParamDescription(), equalTo(scope2.getStructuredParamDescription())); assertThat(savedScopes.get(2).getValue(), equalTo(scope3.getValue())); assertThat(savedScopes.get(2).getDescription(), equalTo(scope3.getDescription())); assertThat(savedScopes.get(2).getIcon(), equalTo(scope3.getIcon())); assertThat(savedScopes.get(2).isDefaultScope(), equalTo(scope3.isDefaultScope())); - assertThat(savedScopes.get(2).isAllowDynReg(), equalTo(scope3.isAllowDynReg())); + assertThat(savedScopes.get(2).isRestricted(), equalTo(scope3.isRestricted())); + assertThat(savedScopes.get(2).isStructured(), equalTo(scope3.isStructured())); + assertThat(savedScopes.get(2).getStructuredParamDescription(), equalTo(scope3.getStructuredParamDescription())); }