From 8b04aafbf3a3076c83e612683442c7ba8b9bd8e9 Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Wed, 13 Mar 2024 15:34:40 +0100 Subject: [PATCH 1/4] New GroupProvider for the Invite app --- pom.xml | 2 +- src/main/java/voot/ExternalGroupsService.java | 3 +- .../java/voot/VootServiceApplication.java | 2 + src/main/java/voot/model/User.java | 6 +- .../java/voot/provider/GroupProviderType.java | 2 +- .../java/voot/provider/InviteProvider.java | 63 +++++++++++++++++++ .../java/voot/VootServiceApplicationTest.java | 4 +- .../voot/provider/InviteProviderTest.java | 57 +++++++++++++++++ .../json/invite/group_memberships.json | 10 +++ .../resources/testAllExternalProviders.yml | 11 ++++ 10 files changed, 152 insertions(+), 8 deletions(-) create mode 100644 src/main/java/voot/provider/InviteProvider.java create mode 100644 src/test/java/voot/provider/InviteProviderTest.java create mode 100644 src/test/resources/json/invite/group_memberships.json diff --git a/pom.xml b/pom.xml index 6991d94..5a5d8c5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openconext voot-service - 5.0.1 + 6.0.0-SNAPSHOT jar voot-service diff --git a/src/main/java/voot/ExternalGroupsService.java b/src/main/java/voot/ExternalGroupsService.java index ed797d0..932e3ed 100644 --- a/src/main/java/voot/ExternalGroupsService.java +++ b/src/main/java/voot/ExternalGroupsService.java @@ -117,7 +117,8 @@ public Set getAllGroups() { protected Set filterDuplicatesWithLowerImportance(List groups) { return groups.stream().collect(groupingBy(group -> group.id)).values().stream() - .map(groupList -> groupList.stream().max(Comparator.comparing(group -> group.membership)).get()).collect(toSet()); + .map(groupList -> groupList.stream().max(Comparator.comparing(group -> group.membership)).get()) + .collect(toSet()); } @SneakyThrows diff --git a/src/main/java/voot/VootServiceApplication.java b/src/main/java/voot/VootServiceApplication.java index 25e8875..99bff49 100644 --- a/src/main/java/voot/VootServiceApplication.java +++ b/src/main/java/voot/VootServiceApplication.java @@ -64,6 +64,8 @@ public ExternalGroupsService externalGroupsService( return new OpenSocialMembersClient(configuration); case GUESTS: return new EduIDGuestProvider(configuration); + case INVITE: + return new InviteProvider(configuration); default: throw new IllegalArgumentException("Unknown external provider-type: " + type); } diff --git a/src/main/java/voot/model/User.java b/src/main/java/voot/model/User.java index 8a51f07..d1e076d 100644 --- a/src/main/java/voot/model/User.java +++ b/src/main/java/voot/model/User.java @@ -8,9 +8,9 @@ @Getter public class User { - private String clientId; - private String unspecifiedId; - private String schacHomeOrganization; + private final String clientId; + private final String unspecifiedId; + private final String schacHomeOrganization; public User(BearerTokenAuthentication bearerTokenAuthentication) { Map tokenAttributes = bearerTokenAuthentication.getTokenAttributes(); diff --git a/src/main/java/voot/provider/GroupProviderType.java b/src/main/java/voot/provider/GroupProviderType.java index c0507ab..f89fc8d 100644 --- a/src/main/java/voot/provider/GroupProviderType.java +++ b/src/main/java/voot/provider/GroupProviderType.java @@ -2,6 +2,6 @@ public enum GroupProviderType { - TEAMS, OPEN_SOCIAL, OPEN_SOCIAL_MEMBERS, VOOT2, GUESTS + TEAMS, OPEN_SOCIAL, OPEN_SOCIAL_MEMBERS, VOOT2, GUESTS, INVITE } diff --git a/src/main/java/voot/provider/InviteProvider.java b/src/main/java/voot/provider/InviteProvider.java new file mode 100644 index 0000000..0dd1dda --- /dev/null +++ b/src/main/java/voot/provider/InviteProvider.java @@ -0,0 +1,63 @@ +package voot.provider; + +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import voot.model.Group; +import voot.model.Member; +import voot.model.Membership; + +import java.net.URI; +import java.util.*; +import java.util.stream.Collectors; + +public class InviteProvider extends AbstractProvider { + + private final String groupMembershipsUrlTemplate; + + public InviteProvider(Configuration configuration) { + super(configuration); + groupMembershipsUrlTemplate = "%s/api/voot/%s"; + } + + @Override + public boolean shouldBeQueriedForMemberships(String schacHomeOrganization) { + return true; + } + + @Override + public Set getGroupMemberships(String uid) { + String uri = String.format(groupMembershipsUrlTemplate, configuration.url, uid); + RequestEntity>> requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create(uri)); + return restTemplate.exchange(requestEntity, new ParameterizedTypeReference>>() { + }).getBody().stream() + .map(this::parseGroup) + .collect(Collectors.toSet()); + } + + private Group parseGroup(Map map) { + String name = map.get("name"); + return new Group(map.get("urn"), name, name, "Invite", Membership.MEMBER); + } + + @Override + public Set getAllGroups() { + return Collections.emptySet(); + } + + @Override + public Optional getGroupMembership(String uid, String groupId) { + return Optional.empty(); + } + + @Override + public Set getMembers(String groupId) { + return Collections.emptySet(); + } + + @Override + public Set getMembers(String personId, String groupId) { + return Collections.emptySet(); + } +} diff --git a/src/test/java/voot/VootServiceApplicationTest.java b/src/test/java/voot/VootServiceApplicationTest.java index 6a52967..4b2e1f9 100644 --- a/src/test/java/voot/VootServiceApplicationTest.java +++ b/src/test/java/voot/VootServiceApplicationTest.java @@ -23,12 +23,12 @@ void externalGroupsService() throws IOException { ExternalGroupsService externalGroupsService = app.externalGroupsService(new ClassPathResource("/testAllExternalProviders.yml")); Object providers = ReflectionTestUtils.getField(externalGroupsService, "providers"); - assertEquals(5, ((List) providers).size()); + assertEquals(6, ((List) providers).size()); } @Test - void externalGroupsServiceUnknown() throws IOException { + void externalGroupsServiceUnknown() { VootServiceApplication app = new VootServiceApplication(); Assertions.assertThrows(IllegalArgumentException.class, () -> app.externalGroupsService(new ClassPathResource("/testUnknownExternalProviders.yml"))); diff --git a/src/test/java/voot/provider/InviteProviderTest.java b/src/test/java/voot/provider/InviteProviderTest.java new file mode 100644 index 0000000..b70f9a4 --- /dev/null +++ b/src/test/java/voot/provider/InviteProviderTest.java @@ -0,0 +1,57 @@ +package voot.provider; + +import com.nimbusds.jose.util.IOUtils; +import org.junit.jupiter.api.Test; +import org.springframework.core.io.ClassPathResource; +import voot.AbstractTest; +import voot.model.Group; + +import java.io.IOException; +import java.util.Set; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + + +class InviteProviderTest extends AbstractTest { + + private final InviteProvider subject = new InviteProvider( + new Provider.Configuration(GroupProviderType.INVITE, "http://localhost:8889", + new Provider.Configuration.Credentials("user", "password"), + 2000, "N/A", "invite")); + + @Test + void getGroupMemberships() throws IOException { + String json = IOUtils.readInputStreamToString(new ClassPathResource("json/invite/group_memberships.json").getInputStream()); + String urn = "urn:collab:person:example.com:admin"; + stubFor(get(urlPathEqualTo("/api/voot/" + urn)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-type", "application/json"). + withBody(json))); + Set groupMemberships = subject.getGroupMemberships(urn); + assertEquals(2, groupMemberships.size()); + } + + @Test + void getAllGroups() { + assertEquals(0, subject.getAllGroups().size()); + } + + @Test + void getGroupMembership() { + assertFalse(subject.getGroupMembership("uid", "groupId").isPresent()); + + } + + @Test + void getMembers() { + assertEquals(0, subject.getMembers("groupId").size()); + } + + @Test + void getMembersByPersonId() { + assertEquals(0, subject.getMembers("personId", "groupId").size()); + } +} diff --git a/src/test/resources/json/invite/group_memberships.json b/src/test/resources/json/invite/group_memberships.json new file mode 100644 index 0000000..4e73e06 --- /dev/null +++ b/src/test/resources/json/invite/group_memberships.json @@ -0,0 +1,10 @@ +[ + { + "urn": "urn1", + "name": "administrator" + }, + { + "urn": "urn2", + "name": "guest" + } +] diff --git a/src/test/resources/testAllExternalProviders.yml b/src/test/resources/testAllExternalProviders.yml index 35d816b..9f42928 100644 --- a/src/test/resources/testAllExternalProviders.yml +++ b/src/test/resources/testAllExternalProviders.yml @@ -54,3 +54,14 @@ externalGroupProviders: name: "Bar", timeoutMillis: 5000 } + - { + type: "invite", + url: "http://localhost:8999/", + credentials: { + username: "foo", + secret: "bar" + }, + schacHomeOrganization: "N/A", + name: "Invite", + timeoutMillis: 5000 + } From 8ed94c0408536f90bc24cdfb7b507481b5e331bd Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Wed, 13 Mar 2024 16:00:34 +0100 Subject: [PATCH 2/4] Debug logging --- src/main/java/voot/provider/InviteProvider.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/voot/provider/InviteProvider.java b/src/main/java/voot/provider/InviteProvider.java index 0dd1dda..d8ad00a 100644 --- a/src/main/java/voot/provider/InviteProvider.java +++ b/src/main/java/voot/provider/InviteProvider.java @@ -1,9 +1,10 @@ package voot.provider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; import voot.model.Group; import voot.model.Member; import voot.model.Membership; @@ -14,6 +15,8 @@ public class InviteProvider extends AbstractProvider { + private static final Logger LOG = LoggerFactory.getLogger(InviteProvider.class); + private final String groupMembershipsUrlTemplate; public InviteProvider(Configuration configuration) { @@ -26,8 +29,16 @@ public boolean shouldBeQueriedForMemberships(String schacHomeOrganization) { return true; } + @Override + public boolean isExternalGroupProvider() { + return false; + } + + @Override public Set getGroupMemberships(String uid) { + LOG.debug("Calling getGroupMemberships for " + uid); + String uri = String.format(groupMembershipsUrlTemplate, configuration.url, uid); RequestEntity>> requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create(uri)); return restTemplate.exchange(requestEntity, new ParameterizedTypeReference>>() { From a8951f66385d46888ce53da03864b45322c243ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:27:08 +0000 Subject: [PATCH 3/4] Bump com.nimbusds:nimbus-jose-jwt from 9.16.1 to 9.37.2 Bumps [com.nimbusds:nimbus-jose-jwt](https://bitbucket.org/connect2id/nimbus-jose-jwt) from 9.16.1 to 9.37.2. - [Changelog](https://bitbucket.org/connect2id/nimbus-jose-jwt/src/master/CHANGELOG.txt) - [Commits](https://bitbucket.org/connect2id/nimbus-jose-jwt/branches/compare/9.37.2..9.16.1) --- updated-dependencies: - dependency-name: com.nimbusds:nimbus-jose-jwt dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5a5d8c5..8360008 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,7 @@ com.nimbusds nimbus-jose-jwt - 9.16.1 + 9.37.2 org.projectlombok From 50eb2b392b3b2787d7781cb1e67b89f6f57e893e Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Tue, 19 Mar 2024 13:29:35 +0100 Subject: [PATCH 4/4] 6.0.0 release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8360008..bcdbe3b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openconext voot-service - 6.0.0-SNAPSHOT + 6.0.0 jar voot-service