bobbai00 commented on code in PR #3767:
URL: https://github.com/apache/texera/pull/3767#discussion_r2380396887


##########
core/access-control-service/src/main/scala/edu/uci/ics/texera/service/resource/AccessControlResource.scala:
##########
@@ -0,0 +1,126 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package edu.uci.ics.texera.service.resource
+
+import com.typesafe.scalalogging.LazyLogging
+import edu.uci.ics.texera.auth.JwtParser.parseToken
+import edu.uci.ics.texera.auth.SessionUser
+import edu.uci.ics.texera.auth.util.{ComputingUnitAccess, HeaderField}
+import edu.uci.ics.texera.dao.jooq.generated.enums.PrivilegeEnum
+import jakarta.ws.rs.core._
+import jakarta.ws.rs.{GET, POST, Path, Produces}
+
+import java.util.Optional
+import scala.jdk.CollectionConverters.{CollectionHasAsScala, MapHasAsScala}
+import scala.util.matching.Regex
+
+@Produces(Array(MediaType.APPLICATION_JSON))
+@Path("/auth")
+class AccessControlResource extends LazyLogging {
+
+  @GET
+  @Path("/{path:.*}")
+  def authorizeGet(
+                    @Context uriInfo: UriInfo,
+                    @Context headers: HttpHeaders
+                  ): Response = {
+    AccessControlResource.authorize(uriInfo, headers)
+  }
+
+  @POST
+  @Path("/{path:.*}")
+  def authorizePost(
+                     @Context uriInfo: UriInfo,
+                     @Context headers: HttpHeaders
+                   ): Response = {
+    AccessControlResource.authorize(uriInfo, headers)
+  }
+}
+
+object AccessControlResource extends LazyLogging {
+
+  // Regex for the paths that require authorization
+  private val wsapiWorkflowWebsocket: Regex = 
""".*/wsapi/workflow-websocket.*""".r
+  private val apiExecutionsStats: Regex = 
""".*/api/executions/[0-9]+/stats/[0-9]+.*""".r
+  private val apiExecutionsResultExport: Regex = 
""".*/api/executions/result/export.*""".r
+
+  def authorize(uriInfo: UriInfo, headers: HttpHeaders): Response = {

Review Comment:
   add brief comments explain the purpose of this function



##########
core/auth/src/main/scala/edu/uci/ics/texera/auth/util/ComputingUnitAccess.scala:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package edu.uci.ics.texera.auth.util
+
+import edu.uci.ics.texera.dao.SqlServer
+import edu.uci.ics.texera.dao.jooq.generated.enums.PrivilegeEnum
+import 
edu.uci.ics.texera.dao.jooq.generated.tables.daos.{ComputingUnitUserAccessDao, 
WorkflowComputingUnitDao}
+import ComputingUnitAccess._
+import org.jooq.DSLContext
+
+import scala.jdk.CollectionConverters._
+
+
+object ComputingUnitAccess {
+  private lazy val context: DSLContext = SqlServer
+    .getInstance()
+    .createDSLContext()
+
+    def getComputingUnitAccess(cuid: Integer, uid: Integer): PrivilegeEnum = {
+    val workflowComputingUnitDao = new 
WorkflowComputingUnitDao(context.configuration())
+    val unit = workflowComputingUnitDao.fetchOneByCuid(cuid)
+
+    if (unit.getUid.equals(uid)) {
+      return PrivilegeEnum.WRITE // owner has write access
+    }
+
+    val computingUnitUserAccessDao = new 
ComputingUnitUserAccessDao(context.configuration())
+    val accessOpt = computingUnitUserAccessDao
+      .fetchByUid(uid)
+      .asScala
+      .find(_.getCuid.equals(cuid))
+
+    accessOpt match {
+      case Some(access) => access.getPrivilege
+      case None => PrivilegeEnum.NONE
+    }
+  }
+}
+
+class ComputingUnitAccess {

Review Comment:
   Remove this



##########
core/access-control-service/src/main/scala/edu/uci/ics/texera/service/resource/AccessControlResource.scala:
##########
@@ -0,0 +1,126 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package edu.uci.ics.texera.service.resource
+
+import com.typesafe.scalalogging.LazyLogging
+import edu.uci.ics.texera.auth.JwtParser.parseToken
+import edu.uci.ics.texera.auth.SessionUser
+import edu.uci.ics.texera.auth.util.{ComputingUnitAccess, HeaderField}
+import edu.uci.ics.texera.dao.jooq.generated.enums.PrivilegeEnum
+import jakarta.ws.rs.core._
+import jakarta.ws.rs.{GET, POST, Path, Produces}
+
+import java.util.Optional
+import scala.jdk.CollectionConverters.{CollectionHasAsScala, MapHasAsScala}
+import scala.util.matching.Regex
+
+@Produces(Array(MediaType.APPLICATION_JSON))
+@Path("/auth")
+class AccessControlResource extends LazyLogging {
+
+  @GET
+  @Path("/{path:.*}")
+  def authorizeGet(
+                    @Context uriInfo: UriInfo,
+                    @Context headers: HttpHeaders
+                  ): Response = {
+    AccessControlResource.authorize(uriInfo, headers)
+  }
+
+  @POST
+  @Path("/{path:.*}")
+  def authorizePost(
+                     @Context uriInfo: UriInfo,
+                     @Context headers: HttpHeaders
+                   ): Response = {
+    AccessControlResource.authorize(uriInfo, headers)
+  }
+}
+
+object AccessControlResource extends LazyLogging {

Review Comment:
   Move the object to the top, before the class



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to