aboutsummaryrefslogtreecommitdiffstats
path: root/tests/plugins/fake-governance-plugin/src/main/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-23 17:22:12 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-09-13 15:50:49 +0200
commit564c915cec585008f1f16951e42a20a30c72c929 (patch)
tree77bf8527eb58868f026c9467d5c74ccf99923670 /tests/plugins/fake-governance-plugin/src/main/java
parent9d5fc95ed97f0dc0e1a797065b5a3870449a9ded (diff)
downloadsonarqube-564c915cec585008f1f16951e42a20a30c72c929.tar.gz
sonarqube-564c915cec585008f1f16951e42a20a30c72c929.zip
SONAR-9740 support system passcode in WS
Diffstat (limited to 'tests/plugins/fake-governance-plugin/src/main/java')
-rw-r--r--tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java3
-rw-r--r--tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java49
2 files changed, 51 insertions, 1 deletions
diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
index 9460af58547..19f6fdf68c3 100644
--- a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
+++ b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java
@@ -1,4 +1,3 @@
-
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
@@ -20,6 +19,7 @@
*/
import org.sonar.api.Plugin;
+import systemPasscode.SystemPasscodeWebService;
import workerCount.FakeWorkerCountProviderImpl;
import workerCount.RefreshWorkerCountAction;
import workerlatch.LatchControllerWorkerMeasureComputer;
@@ -35,6 +35,7 @@ public class FakeGovernancePlugin implements Plugin {
context.addExtension(WorkerLatchMetrics.class);
context.addExtension(LatchControllerWorkerMeasureComputer.class);
context.addExtension(RefreshWorkerCountAction.class);
+ context.addExtension(SystemPasscodeWebService.class);
}
}
diff --git a/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java b/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java
new file mode 100644
index 00000000000..cdeadf75de0
--- /dev/null
+++ b/tests/plugins/fake-governance-plugin/src/main/java/systemPasscode/SystemPasscodeWebService.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package systemPasscode;
+
+import java.net.HttpURLConnection;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.user.SystemPasscode;
+
+public class SystemPasscodeWebService implements WebService, RequestHandler {
+ private final SystemPasscode passcode;
+
+ public SystemPasscodeWebService(SystemPasscode passcode) {
+ this.passcode = passcode;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewController controller = context.createController("api/system_passcode");
+ controller.createAction("check").setHandler(this);
+ controller.done();
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ if (!passcode.isValid(request)) {
+ response.stream().setStatus(HttpURLConnection.HTTP_UNAUTHORIZED);
+ }
+ }
+}