Browse Source

fixup! SONAR-7590 Redirect to requested page with identity provider

tags/6.7-RC1
Julien Lancelot 6 years ago
parent
commit
5c3ae07af1

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/authentication/OAuth2ContextFactory.java View File

@@ -115,7 +115,7 @@ public class OAuth2ContextFactory {
public void redirectToRequestedPage() {
try {
Optional<String> redirectTo = oAuthRedirection.getAndDelete(request, response);
getResponse().sendRedirect(server.getContextPath() + redirectTo.orElse("/"));
getResponse().sendRedirect(redirectTo.orElse(server.getContextPath() + "/"));
} catch (IOException e) {
throw new IllegalStateException("Fail to redirect to home", e);
}

+ 5
- 0
server/sonar-server/src/main/java/org/sonar/server/authentication/OAuth2Redirection.java View File

@@ -31,6 +31,11 @@ import static org.sonar.server.authentication.Cookies.newCookieBuilder;
public class OAuth2Redirection {

private static final String REDIRECT_TO_COOKIE = "REDIRECT_TO";

/**
* The HTTP parameter that contains the path where the user should be redirect to.
* Please note that the web context is included.
*/
private static final String RETURN_TO_PARAMETER = "return_to";

public void create(HttpServletRequest request, HttpServletResponse response) {

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java View File

@@ -179,9 +179,9 @@ public class OAuth2ContextFactoryTest {
}

@Test
public void redirect_to_requested_page_context() throws Exception {
when(oAuthRedirection.getAndDelete(request, response)).thenReturn(Optional.of("/settings"));
when(server.getContextPath()).thenReturn("/sonarqube");
public void redirect_to_requested_page_doesnt_need_context() throws Exception {
when(oAuthRedirection.getAndDelete(request, response)).thenReturn(Optional.of("/sonarqube/settings"));
when(server.getContextPath()).thenReturn("/other");
OAuth2IdentityProvider.CallbackContext callback = newCallbackContext();

callback.redirectToRequestedPage();

Loading…
Cancel
Save