mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 03:23:13 +00:00
[CST-5669] Added redirect on ORCID login error
This commit is contained in:
@@ -70,6 +70,16 @@ public class OrcidLoginFilter extends StatelessLoginFilter {
|
|||||||
redirectAfterSuccess(req, res);
|
redirectAfterSuccess(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
AuthenticationException failed) throws IOException, ServletException {
|
||||||
|
|
||||||
|
String baseRediredirectUrl = configurationService.getProperty("dspace.ui.url");
|
||||||
|
String redirectUrl = baseRediredirectUrl + "/error?status=401&code=orcid.generic-error";
|
||||||
|
response.sendRedirect(redirectUrl);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After successful login, redirect to the DSpace URL specified by this Orcid
|
* After successful login, redirect to the DSpace URL specified by this Orcid
|
||||||
* request (in the "redirectUrl" request parameter). If that 'redirectUrl' is
|
* request (in the "redirectUrl" request parameter). If that 'redirectUrl' is
|
||||||
|
@@ -10,7 +10,6 @@ package org.dspace.app.rest;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static org.dspace.app.matcher.MetadataValueMatcher.with;
|
import static org.dspace.app.matcher.MetadataValueMatcher.with;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.hasItem;
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
@@ -23,7 +22,6 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.cookie;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.cookie;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
@@ -133,7 +131,8 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -176,7 +175,8 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"));
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
||||||
@@ -191,16 +191,13 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
when(orcidClientMock.getAccessToken(CODE)).thenReturn(buildOrcidTokenResponse(ORCID, ACCESS_TOKEN));
|
when(orcidClientMock.getAccessToken(CODE)).thenReturn(buildOrcidTokenResponse(ORCID, ACCESS_TOKEN));
|
||||||
when(orcidClientMock.getPerson(ACCESS_TOKEN, ORCID)).thenReturn(buildPerson("Test", "User"));
|
when(orcidClientMock.getPerson(ACCESS_TOKEN, ORCID)).thenReturn(buildPerson("Test", "User"));
|
||||||
|
|
||||||
MvcResult mvcResult = getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"))
|
|
||||||
.andReturn();
|
.andReturn();
|
||||||
|
|
||||||
String authenticateHeader = mvcResult.getResponse().getHeader("WWW-Authenticate");
|
|
||||||
assertThat(authenticateHeader, containsString("orcid realm=\"DSpace REST API\""));
|
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
||||||
verifyNoMoreInteractions(orcidClientMock);
|
verifyNoMoreInteractions(orcidClientMock);
|
||||||
@@ -211,9 +208,9 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
public void testWithoutAuthorizationCode() throws Exception {
|
public void testWithoutAuthorizationCode() throws Exception {
|
||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid"))
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid"))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"));
|
.andExpect(cookie().doesNotExist("Authorization-cookie"));
|
||||||
|
|
||||||
verifyNoInteractions(orcidClientMock);
|
verifyNoInteractions(orcidClientMock);
|
||||||
|
|
||||||
@@ -269,9 +266,9 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"));
|
.andExpect(cookie().doesNotExist("Authorization-cookie"));
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verifyNoMoreInteractions(orcidClientMock);
|
verifyNoMoreInteractions(orcidClientMock);
|
||||||
@@ -329,9 +326,9 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"));
|
.andExpect(cookie().doesNotExist("Authorization-cookie"));
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
||||||
@@ -356,9 +353,9 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"));
|
.andExpect(cookie().doesNotExist("Authorization-cookie"));
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verifyNoMoreInteractions(orcidClientMock);
|
verifyNoMoreInteractions(orcidClientMock);
|
||||||
@@ -383,9 +380,9 @@ public class OrcidLoginFilterIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
getClient().perform(get("/api/" + AuthnRest.CATEGORY + "/orcid")
|
||||||
.param("code", CODE))
|
.param("code", CODE))
|
||||||
.andExpect(status().isUnauthorized())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(cookie().doesNotExist("Authorization-cookie"))
|
.andExpect(redirectedUrl("http://localhost:4000/error?status=401&code=orcid.generic-error"))
|
||||||
.andExpect(header().exists("WWW-Authenticate"));
|
.andExpect(cookie().doesNotExist("Authorization-cookie"));
|
||||||
|
|
||||||
verify(orcidClientMock).getAccessToken(CODE);
|
verify(orcidClientMock).getAccessToken(CODE);
|
||||||
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
verify(orcidClientMock).getPerson(ACCESS_TOKEN, ORCID);
|
||||||
|
Reference in New Issue
Block a user