server settings nuget tab + security + mock content
authorEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 10 Aug 2011 16:56:18 +0000 (20:56 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 10 Aug 2011 16:56:18 +0000 (20:56 +0400)
nuget-server/nuget-server.iml
nuget-server/src/META-INF/build-server-plugin-nuget.xml
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/PermissionChecker.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsController.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsTab.java [new file with mode: 0644]

index 0eff86e9fa55d18d4a77008ed3f00e7b79a57600..36c800563f2f7658d4a02937f9a4b200af7e457b 100644 (file)
@@ -38,6 +38,7 @@
     <orderEntry type="library" name="Servlet Api" level="project" />\r
     <orderEntry type="module" module-name="nuget-common" />\r
     <orderEntry type="library" name="Common-Impl" level="project" />\r
+    <orderEntry type="library" name="TeamCity server runtime" level="project" />\r
   </component>\r
 </module>\r
 \r
index 603fd6f08a5dc72c626a3e15e5c08dca43519c96..55053c94901460975e58a65d647c7d953228a810 100644 (file)
@@ -30,4 +30,9 @@
 \r
   <bean class="jetbrains.buildServer.nuget.server.publish.PublishRunTypeRegistrar"/>\r
   <bean class="jetbrains.buildServer.nuget.server.publish.PublishRunType"/>\r
+\r
+\r
+  <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.PermissionChecker"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.ServerSettingsTab"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.ServerSettingsController"/>\r
 </beans>
\ No newline at end of file
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/PermissionChecker.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/PermissionChecker.java
new file mode 100644 (file)
index 0000000..5b03305
--- /dev/null
@@ -0,0 +1,46 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.toolRegistry.tab;\r
+\r
+import jetbrains.buildServer.serverSide.auth.*;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 10.08.11 20:51\r
+ */\r
+public class PermissionChecker {\r
+  private final SecurityContext myContext;\r
+\r
+  public PermissionChecker(@NotNull final SecurityContext context) {\r
+    myContext = context;\r
+  }\r
+\r
+  public boolean hasAccess(@NotNull AuthorityHolder authorityHolder) {\r
+    return AuthUtil.hasGlobalPermission(authorityHolder, Permission.CHANGE_SERVER_SETTINGS);\r
+  }\r
+\r
+  public boolean hasAccess() {\r
+    return hasAccess(myContext.getAuthorityHolder());\r
+  }\r
+\r
+  public void assertAccess(AuthorityHolder holder) {\r
+    if (!hasAccess(holder)) {\r
+      throw new AccessDeniedException(holder, "You do not have access to view or update nuget server settings.");\r
+    }\r
+  }\r
+}\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsController.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsController.java
new file mode 100644 (file)
index 0000000..19bd79b
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.toolRegistry.tab;\r
+\r
+import jetbrains.buildServer.controllers.AuthorizationInterceptor;\r
+import jetbrains.buildServer.controllers.BaseController;\r
+import jetbrains.buildServer.controllers.RequestPermissionsChecker;\r
+import jetbrains.buildServer.serverSide.SBuildServer;\r
+import jetbrains.buildServer.serverSide.auth.AccessDeniedException;\r
+import jetbrains.buildServer.serverSide.auth.AuthorityHolder;\r
+import jetbrains.buildServer.web.openapi.PluginDescriptor;\r
+import jetbrains.buildServer.web.openapi.WebControllerManager;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 10.08.11 20:38\r
+ */\r
+public class ServerSettingsController extends BaseController {\r
+  private final String myPath;\r
+\r
+  public ServerSettingsController(@NotNull final SBuildServer server,\r
+                                  @NotNull final AuthorizationInterceptor auth,\r
+                                  @NotNull final PermissionChecker checker,\r
+                                  @NotNull final WebControllerManager web,\r
+                                  @NotNull final PluginDescriptor descriptor) {\r
+    super(server);\r
+    myPath = descriptor.getPluginResourcesPath("tool/nuget-server-tab.html");\r
+    auth.addPathBasedPermissionsChecker(myPath, new RequestPermissionsChecker() {\r
+      public void checkPermissions(@NotNull AuthorityHolder authorityHolder, @NotNull HttpServletRequest request) throws AccessDeniedException {\r
+       checker.assertAccess(authorityHolder);\r
+      }\r
+    });\r
+    web.registerController(myPath, this);\r
+  }\r
+\r
+  @NotNull\r
+  public String getPath() {\r
+    return myPath;\r
+  }\r
+\r
+  @Override\r
+  protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {\r
+    return simpleView("Empty nuget tab content");\r
+  }\r
+}\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsTab.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsTab.java
new file mode 100644 (file)
index 0000000..89236e7
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.toolRegistry.tab;\r
+\r
+import jetbrains.buildServer.web.openapi.PagePlaces;\r
+import jetbrains.buildServer.web.openapi.PlaceId;\r
+import jetbrains.buildServer.web.openapi.PositionConstraint;\r
+import jetbrains.buildServer.web.openapi.SimpleCustomTab;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 10.08.11 20:35\r
+ */\r
+public class ServerSettingsTab extends SimpleCustomTab {\r
+  private final PermissionChecker myChecker;\r
+\r
+  public ServerSettingsTab(@NotNull final PagePlaces pagePlaces,\r
+                           @NotNull final ServerSettingsController controller,\r
+                           @NotNull final PermissionChecker checker) {\r
+    super(pagePlaces,\r
+            PlaceId.ADMIN_SERVER_CONFIGURATION_TAB,\r
+            "toolLoadTab",\r
+            controller.getPath(),\r
+            "NuGet");\r
+    myChecker = checker;\r
+    setPosition(PositionConstraint.last());\r
+    register();\r
+  }\r
+\r
+  @Override\r
+  public boolean isVisible() {\r
+    return super.isVisible() && myChecker.hasAccess();\r
+  }\r
+}\r