From 57d8ed04d231b89374f1cf9a51274900317f696e Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Fri, 24 Jul 2026 11:33:18 +0200 Subject: [PATCH] PLUGINAPI-203 Add supportsScopedOrganizationTokens flag to WebService Adds a new per-action boolean flag to NewAction/Action, following the existing internal/post pattern, so SonarQube Cloud can declare which WS actions accept authentication via a scoped organization token. --- .../org/sonar/api/server/ws/WebService.java | 23 +++++++++++++++++++ .../sonar/api/server/ws/WebServiceTest.java | 3 +++ 2 files changed, 26 insertions(+) diff --git a/plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index f7a2efb8..307a4b61 100644 --- a/plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -251,6 +251,7 @@ class NewAction { private String deprecatedSince; private boolean post = false; private boolean isInternal = false; + private boolean supportsScopedOrganizationTokens = false; private RequestHandler handler; private Map newParams = new HashMap<>(); private URL responseExample = null; @@ -309,6 +310,18 @@ public NewAction setInternal(boolean b) { return this; } + /** + * Indicates that the action can be authenticated using a SonarQube Cloud scoped + * organization token, in addition to any other supported authentication mechanism. + * This is only relevant to SonarQube Cloud. By default an action does not support it. + * + * @since 13.9 + */ + public NewAction setSupportsScopedOrganizationTokens(boolean b) { + this.supportsScopedOrganizationTokens = b; + return this; + } + public NewAction setHandler(RequestHandler h) { this.handler = h; return this; @@ -511,6 +524,7 @@ class Action { private final String deprecatedSince; private final boolean post; private final boolean isInternal; + private final boolean supportsScopedOrganizationTokens; private final RequestHandler handler; private final Map params; private final URL responseExample; @@ -526,6 +540,7 @@ private Action(Controller controller, NewAction newAction) { this.deprecatedSince = newAction.deprecatedSince; this.post = newAction.post; this.isInternal = newAction.isInternal; + this.supportsScopedOrganizationTokens = newAction.supportsScopedOrganizationTokens; this.responseExample = newAction.responseExample; this.handler = newAction.handler; this.changelog = newAction.changelog; @@ -602,6 +617,14 @@ public boolean isInternal() { return isInternal; } + /** + * @see NewAction#setSupportsScopedOrganizationTokens(boolean) + * @since 13.9 + */ + public boolean isSupportsScopedOrganizationTokens() { + return supportsScopedOrganizationTokens; + } + public RequestHandler handler() { return handler; } diff --git a/plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java index 35c5e16c..20adce2b 100644 --- a/plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java +++ b/plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java @@ -79,6 +79,7 @@ public void define_web_service() { assertThat(showAction.since()).isEqualTo("4.2"); assertThat(showAction.isPost()).isFalse(); assertThat(showAction.isInternal()).isFalse(); + assertThat(showAction.isSupportsScopedOrganizationTokens()).isFalse(); assertThat(showAction.path()).isEqualTo("api/metric/show"); WebService.Action createAction = controller.action("create"); assertThat(createAction).isNotNull(); @@ -89,6 +90,7 @@ public void define_web_service() { assertThat(createAction.since()).isEqualTo("4.1"); assertThat(createAction.isPost()).isTrue(); assertThat(createAction.isInternal()).isTrue(); + assertThat(createAction.isSupportsScopedOrganizationTokens()).isTrue(); assertThat(createAction.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly( tuple("6.4", "Last event"), tuple("6.0", "Old event"), tuple("4.5.6", "Very old event")); } @@ -539,6 +541,7 @@ public void define(Context context) { .setDeprecatedSince("5.3") .setPost(true) .setInternal(true) + .setSupportsScopedOrganizationTokens(true) .setResponseExample(getClass().getResource("WebServiceTest/response-example.txt")) .setChangelog( new Change("6.4", "Last event"),