-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/docker_configs
- Loading branch information
Showing
10 changed files
with
164 additions
and
9 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
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
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
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
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
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,74 @@ | ||
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 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 static final Logger LOG = LoggerFactory.getLogger(InviteProvider.class); | ||
|
||
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 boolean isExternalGroupProvider() { | ||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public Set<Group> getGroupMemberships(String uid) { | ||
LOG.debug("Calling getGroupMemberships for " + uid); | ||
|
||
String uri = String.format(groupMembershipsUrlTemplate, configuration.url, uid); | ||
RequestEntity<List<Map<String, String>>> requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create(uri)); | ||
return restTemplate.exchange(requestEntity, new ParameterizedTypeReference<List<Map<String, String>>>() { | ||
}).getBody().stream() | ||
.map(this::parseGroup) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private Group parseGroup(Map<String, String> map) { | ||
String name = map.get("name"); | ||
return new Group(map.get("urn"), name, name, "Invite", Membership.MEMBER); | ||
} | ||
|
||
@Override | ||
public Set<Group> getAllGroups() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public Optional<Group> getGroupMembership(String uid, String groupId) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Set<Member> getMembers(String groupId) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public Set<Member> getMembers(String personId, String groupId) { | ||
return Collections.emptySet(); | ||
} | ||
} |
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
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,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<Group> 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()); | ||
} | ||
} |
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,10 @@ | ||
[ | ||
{ | ||
"urn": "urn1", | ||
"name": "administrator" | ||
}, | ||
{ | ||
"urn": "urn2", | ||
"name": "guest" | ||
} | ||
] |
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