add "Allow unsigned requests"
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 12 May 2016 16:42:45 +0000 (18:42 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 12 May 2016 16:42:45 +0000 (18:42 +0200)
platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInServerConfigurableUi.form
platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInServerConfigurableUi.java
platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInServerOptions.java
platform/built-in-server/src/org/jetbrains/builtInWebServer/BuiltInWebServer.kt
platform/platform-resources-en/src/messages/XmlBundle.properties

index 3aa78b3be81c6675c56c622c3ebbcee1f8014661..fc29de8d45d3416e93f0676abfaf9921bf08629c 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.builtInWebServer.BuiltInServerConfigurableUi">
-  <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
       <xy x="20" y="20" width="1077" height="321"/>
@@ -8,14 +8,6 @@
     <properties/>
     <border type="none"/>
     <children>
-      <component id="696ad" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text resource-bundle="messages/XmlBundle" key="setting.value.builtin.server.port.label"/>
-        </properties>
-      </component>
       <component id="e47e0" class="com.intellij.ui.PortField" binding="builtInServerPort">
         <constraints>
           <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
           <text resource-bundle="messages/XmlBundle" key="setting.value.can.accept.external.connections"/>
         </properties>
       </component>
-      <vspacer id="c36c4">
+      <component id="2c830" class="javax.swing.JLabel">
         <constraints>
-          <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text resource-bundle="messages/XmlBundle" key="setting.value.builtin.server.port.label"/>
+        </properties>
+      </component>
+      <vspacer id="70613">
+        <constraints>
+          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
       </vspacer>
+      <component id="15e76" class="javax.swing.JCheckBox" binding="allowUnsignedRequestsCheckBox">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text resource-bundle="messages/XmlBundle" key="setting.value.builtin.server.allow.unsigned.requests"/>
+        </properties>
+      </component>
     </children>
   </grid>
 </form>
index edbef65543af6005ae15da4e31a7775ceeab9b83..1747e0dbb2f39e1245ac8ac97ec998144fb9a7ab 100644 (file)
@@ -11,6 +11,7 @@ class BuiltInServerConfigurableUi implements ConfigurableUi<BuiltInServerOptions
 
   private PortField builtInServerPort;
   private JCheckBox builtInServerAvailableExternallyCheckBox;
+  private JCheckBox allowUnsignedRequestsCheckBox;
 
   public BuiltInServerConfigurableUi() {
     builtInServerPort.setMin(1024);
@@ -25,12 +26,14 @@ class BuiltInServerConfigurableUi implements ConfigurableUi<BuiltInServerOptions
   @Override
   public boolean isModified(@NotNull BuiltInServerOptions settings) {
     return builtInServerPort.getNumber() != settings.builtInServerPort ||
-           builtInServerAvailableExternallyCheckBox.isSelected() != settings.builtInServerAvailableExternally;
+           builtInServerAvailableExternallyCheckBox.isSelected() != settings.builtInServerAvailableExternally ||
+           allowUnsignedRequestsCheckBox.isSelected() != settings.allowUnsignedRequests;
   }
 
   @Override
   public void apply(@NotNull BuiltInServerOptions settings) {
     boolean builtInServerPortChanged = settings.builtInServerPort != builtInServerPort.getNumber() || settings.builtInServerAvailableExternally != builtInServerAvailableExternallyCheckBox.isSelected();
+    settings.allowUnsignedRequests = allowUnsignedRequestsCheckBox.isSelected();
     if (builtInServerPortChanged) {
       settings.builtInServerPort = builtInServerPort.getNumber();
       settings.builtInServerAvailableExternally = builtInServerAvailableExternallyCheckBox.isSelected();
index 7f3fcc7811ab144537220c517ba7e376727378e2..daad0df029cc114c16a62fdeaf5807a1ec95a495 100644 (file)
@@ -36,6 +36,9 @@ public class BuiltInServerOptions implements PersistentStateComponent<BuiltInSer
   @Attribute
   public boolean builtInServerAvailableExternally = false;
 
+  @Attribute
+  public boolean allowUnsignedRequests = false;
+
   public static BuiltInServerOptions getInstance() {
     return ServiceManager.getService(BuiltInServerOptions.class);
   }
index 9ba1e8652603f17e956e19368abb08bfad7f45f1..c07b496e5e3a30eea91c54406c25edbcb849305c 100644 (file)
@@ -249,6 +249,10 @@ private fun doProcess(urlDecoder: QueryStringDecoder, request: FullHttpRequest,
 }
 
 internal fun HttpRequest.isSignedRequest(): Boolean {
+  if (BuiltInServerOptions.getInstance().allowUnsignedRequests) {
+    return true
+  }
+
   // we must check referrer - if html cached, browser will send request without query
   val token = headers().get(TOKEN_HEADER_NAME)
       ?: QueryStringDecoder(uri()).parameters().get(TOKEN_PARAM_NAME)?.firstOrNull()
@@ -260,6 +264,10 @@ internal fun HttpRequest.isSignedRequest(): Boolean {
 
 @JvmOverloads
 internal fun validateToken(request: HttpRequest, channel: Channel, isSignedRequest: Boolean = request.isSignedRequest()): HttpHeaders? {
+  if (BuiltInServerOptions.getInstance().allowUnsignedRequests) {
+    return EmptyHttpHeaders.INSTANCE
+  }
+
   request.headers().get(HttpHeaderNames.COOKIE)?.let {
     for (cookie in ServerCookieDecoder.STRICT.decode(it)) {
       if (cookie.name() == STANDARD_COOKIE.name()) {
index 7e076c1923084fd2c6d331d66aa66fbac9834160..6e3c3046ca8a7cfe3bffd1629e2b0d58c3c1a6f9 100644 (file)
@@ -250,4 +250,5 @@ javascript.debugger.settings.choose.file.subtitle=Select file to debug JavaScrip
 
 setting.builtin.server.category.label=Built-in server
 setting.value.builtin.server.port.label=&Port\:
-setting.value.can.accept.external.connections=Can accept &external connections
\ No newline at end of file
+setting.value.can.accept.external.connections=Can accept &external connections
+setting.value.builtin.server.allow.unsigned.requests=&Allow unsigned requests