From 68977b2bedc95c738b58bc8be83a00d21e13c32e Mon Sep 17 00:00:00 2001 From: Antoine Vinot Date: Thu, 13 Apr 2023 16:57:56 +0200 Subject: SONAR-19045 Migrate from javaxi.servlet to framework agnostic plugin api classes Co-authored-by: Eric Giffon Co-authored-by: Alain Kermis Co-authored-by: Antoine Vinot Co-authored-by: Jacek Poreda --- server/sonar-auth-bitbucket/build.gradle | 1 + .../auth/bitbucket/BitbucketIdentityProvider.java | 4 ++-- .../org/sonar/auth/bitbucket/IntegrationTest.java | 27 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) (limited to 'server/sonar-auth-bitbucket') diff --git a/server/sonar-auth-bitbucket/build.gradle b/server/sonar-auth-bitbucket/build.gradle index 445a0c2be16..8329723c6e2 100644 --- a/server/sonar-auth-bitbucket/build.gradle +++ b/server/sonar-auth-bitbucket/build.gradle @@ -22,4 +22,5 @@ dependencies { testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.mockito:mockito-core' + testImplementation project(path: ':server:sonar-webserver-api') } diff --git a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketIdentityProvider.java b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketIdentityProvider.java index ad0a29ebda1..58dd889d670 100755 --- a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketIdentityProvider.java +++ b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketIdentityProvider.java @@ -33,12 +33,12 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import javax.annotation.CheckForNull; -import javax.servlet.http.HttpServletRequest; import org.sonar.api.server.ServerSide; import org.sonar.api.server.authentication.Display; import org.sonar.api.server.authentication.OAuth2IdentityProvider; import org.sonar.api.server.authentication.UnauthorizedException; import org.sonar.api.server.authentication.UserIdentity; +import org.sonar.api.server.http.HttpRequest; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -122,7 +122,7 @@ public class BitbucketIdentityProvider implements OAuth2IdentityProvider { } private void onCallback(CallbackContext context) throws InterruptedException, ExecutionException, IOException { - HttpServletRequest request = context.getRequest(); + HttpRequest request = context.getHttpRequest(); OAuth20Service scribe = newScribeBuilder(context).build(scribeApi); String code = request.getParameter(OAuthConstants.CODE); OAuth2AccessToken accessToken = scribe.getAccessToken(code); diff --git a/server/sonar-auth-bitbucket/src/test/java/org/sonar/auth/bitbucket/IntegrationTest.java b/server/sonar-auth-bitbucket/src/test/java/org/sonar/auth/bitbucket/IntegrationTest.java index cce09beccf3..9b47ec7abc3 100644 --- a/server/sonar-auth-bitbucket/src/test/java/org/sonar/auth/bitbucket/IntegrationTest.java +++ b/server/sonar-auth-bitbucket/src/test/java/org/sonar/auth/bitbucket/IntegrationTest.java @@ -36,7 +36,10 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.server.authentication.OAuth2IdentityProvider; import org.sonar.api.server.authentication.UnauthorizedException; import org.sonar.api.server.authentication.UserIdentity; +import org.sonar.api.server.http.HttpRequest; +import org.sonar.api.server.http.HttpResponse; import org.sonar.api.utils.System2; +import org.sonar.server.http.JavaxHttpRequest; import static java.lang.String.format; import static java.net.URLEncoder.encode; @@ -253,14 +256,24 @@ public class IntegrationTest { return CALLBACK_URL; } + @Override + public HttpRequest getHttpRequest() { + return new JavaxHttpRequest(request); + } + + @Override + public HttpResponse getHttpResponse() { + throw new UnsupportedOperationException("not used"); + } + @Override public HttpServletRequest getRequest() { - return request; + throw new UnsupportedOperationException("deprecated"); } @Override public HttpServletResponse getResponse() { - throw new UnsupportedOperationException("not used"); + throw new UnsupportedOperationException("deprecated"); } } @@ -287,6 +300,16 @@ public class IntegrationTest { return CALLBACK_URL; } + @Override + public HttpRequest getHttpRequest() { + return null; + } + + @Override + public HttpResponse getHttpResponse() { + return null; + } + @Override public HttpServletRequest getRequest() { return null; -- cgit v1.2.3