|
8 | 8 | package org.dspace.app.rest; |
9 | 9 |
|
10 | 10 | import static java.lang.Thread.sleep; |
| 11 | +import static org.dspace.app.rest.matcher.GroupMatcher.matchGroupWithName; |
11 | 12 | import static org.dspace.app.rest.utils.RegexUtils.REGEX_UUID; |
12 | 13 | import static org.hamcrest.Matchers.containsString; |
13 | 14 | import static org.hamcrest.Matchers.endsWith; |
@@ -1641,6 +1642,71 @@ public void testOrcidLoginURL() throws Exception { |
1641 | 1642 | } |
1642 | 1643 | } |
1643 | 1644 |
|
| 1645 | + @Test |
| 1646 | + public void testAreSpecialGroupsApplicable() throws Exception { |
| 1647 | + context.turnOffAuthorisationSystem(); |
| 1648 | + |
| 1649 | + GroupBuilder.createGroup(context) |
| 1650 | + .withName("specialGroupPwd") |
| 1651 | + .build(); |
| 1652 | + GroupBuilder.createGroup(context) |
| 1653 | + .withName("specialGroupShib") |
| 1654 | + .build(); |
| 1655 | + |
| 1656 | + configurationService.setProperty("plugin.sequence.org.dspace.authenticate.AuthenticationMethod", SHIB_AND_PASS); |
| 1657 | + configurationService.setProperty("authentication-password.login.specialgroup", "specialGroupPwd"); |
| 1658 | + configurationService.setProperty("authentication-shibboleth.role.faculty", "specialGroupShib"); |
| 1659 | + configurationService.setProperty("authentication-shibboleth.default-roles", "faculty"); |
| 1660 | + |
| 1661 | + context.restoreAuthSystemState(); |
| 1662 | + |
| 1663 | + String passwordToken = getAuthToken(eperson.getEmail(), password); |
| 1664 | + |
| 1665 | + getClient(passwordToken).perform(get("/api/authn/status").param("projection", "full")) |
| 1666 | + .andExpect(status().isOk()) |
| 1667 | + .andExpect(jsonPath("$", AuthenticationStatusMatcher.matchFullEmbeds())) |
| 1668 | + .andExpect(jsonPath("$", AuthenticationStatusMatcher.matchLinks())) |
| 1669 | + .andExpect(content().contentType(contentType)) |
| 1670 | + .andExpect(jsonPath("$.okay", is(true))) |
| 1671 | + .andExpect(jsonPath("$.authenticated", is(true))) |
| 1672 | + .andExpect(jsonPath("$.authenticationMethod", is("password"))) |
| 1673 | + .andExpect(jsonPath("$.type", is("status"))) |
| 1674 | + .andExpect(jsonPath("$._links.specialGroups.href", startsWith(REST_SERVER_URL))) |
| 1675 | + .andExpect(jsonPath("$._embedded.specialGroups._embedded.specialGroups", |
| 1676 | + Matchers.containsInAnyOrder(matchGroupWithName("specialGroupPwd")))); |
| 1677 | + |
| 1678 | + getClient(passwordToken).perform(get("/api/authn/status/specialGroups").param("projection", "full")) |
| 1679 | + .andExpect(status().isOk()) |
| 1680 | + .andExpect(content().contentType(contentType)) |
| 1681 | + .andExpect(jsonPath("$._embedded.specialGroups", |
| 1682 | + Matchers.containsInAnyOrder(matchGroupWithName("specialGroupPwd")))); |
| 1683 | + |
| 1684 | + String shibToken = getClient().perform(post("/api/authn/login") |
| 1685 | + .requestAttr("SHIB-MAIL", eperson.getEmail()) |
| 1686 | + .requestAttr("SHIB-SCOPED-AFFILIATION", "faculty;staff")) |
| 1687 | + .andExpect(status().isOk()) |
| 1688 | + .andReturn().getResponse().getHeader(AUTHORIZATION_HEADER).replace(AUTHORIZATION_TYPE, ""); |
| 1689 | + |
| 1690 | + getClient(shibToken).perform(get("/api/authn/status").param("projection", "full")) |
| 1691 | + .andExpect(status().isOk()) |
| 1692 | + .andExpect(jsonPath("$", AuthenticationStatusMatcher.matchFullEmbeds())) |
| 1693 | + .andExpect(jsonPath("$", AuthenticationStatusMatcher.matchLinks())) |
| 1694 | + .andExpect(content().contentType(contentType)) |
| 1695 | + .andExpect(jsonPath("$.okay", is(true))) |
| 1696 | + .andExpect(jsonPath("$.authenticated", is(true))) |
| 1697 | + .andExpect(jsonPath("$.authenticationMethod", is("shibboleth"))) |
| 1698 | + .andExpect(jsonPath("$.type", is("status"))) |
| 1699 | + .andExpect(jsonPath("$._links.specialGroups.href", startsWith(REST_SERVER_URL))) |
| 1700 | + .andExpect(jsonPath("$._embedded.specialGroups._embedded.specialGroups", |
| 1701 | + Matchers.containsInAnyOrder(matchGroupWithName("specialGroupShib")))); |
| 1702 | + |
| 1703 | + getClient(shibToken).perform(get("/api/authn/status/specialGroups").param("projection", "full")) |
| 1704 | + .andExpect(status().isOk()) |
| 1705 | + .andExpect(content().contentType(contentType)) |
| 1706 | + .andExpect(jsonPath("$._embedded.specialGroups", |
| 1707 | + Matchers.containsInAnyOrder(matchGroupWithName("specialGroupShib")))); |
| 1708 | + } |
| 1709 | + |
1644 | 1710 | // Get a short-lived token based on an active login token |
1645 | 1711 | private String getShortLivedToken(String loginToken) throws Exception { |
1646 | 1712 | ObjectMapper mapper = new ObjectMapper(); |
|
0 commit comments