Skip to content

Commit

Permalink
add jwt token
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbai00 committed Sep 3, 2024
1 parent ea6e7c0 commit 730561a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package edu.uci.ics.texera.web

import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.github.toastshaman.dropwizard.auth.jwt.JwtAuthFilter
import com.typesafe.scalalogging.LazyLogging
import edu.uci.ics.amber.engine.architecture.deploysemantics.PhysicalOp
import edu.uci.ics.amber.engine.common.AmberConfig
import edu.uci.ics.texera.Utils
import edu.uci.ics.texera.web.TexeraWebApplication.parseArgs
Expand All @@ -15,11 +13,9 @@ import edu.uci.ics.texera.web.auth.{
UserAuthenticator,
UserRoleAuthorizer
}
import edu.uci.ics.texera.web.model.serializer.PhysicalOpSerializer
import edu.uci.ics.texera.web.resource.WorkflowCompilationResource
import io.dropwizard.auth.{AuthDynamicFeature, AuthValueFactoryProvider}
import io.dropwizard.setup.{Bootstrap, Environment}
import org.eclipse.jetty.server.session.SessionHandler
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature

object TexeraWorkflowCompilingService {
Expand Down Expand Up @@ -57,5 +53,32 @@ class TexeraWorkflowCompilingService

// register the compilation endpoint
environment.jersey.register(classOf[WorkflowCompilationResource])

// Add JWT Auth layer (without session)
if (AmberConfig.isUserSystemEnabled) {
environment.jersey.register(
new AuthDynamicFeature(
new JwtAuthFilter.Builder[SessionUser]() // Renamed from SessionUser to AuthenticatedUser
.setJwtConsumer(jwtConsumer)
.setRealm("realm")
.setPrefix("Bearer")
.setAuthenticator(UserAuthenticator)
.setAuthorizer(UserRoleAuthorizer)
.buildAuthFilter()
)
)
} else {
// register Guest Auth layer (if applicable)
environment.jersey.register(
new AuthDynamicFeature(
new GuestAuthFilter.Builder().setAuthorizer(UserRoleAuthorizer).buildAuthFilter()
)
)
}

environment.jersey.register(
new AuthValueFactoryProvider.Binder[SessionUser](classOf[SessionUser]) // Updated here as well
)
environment.jersey.register(classOf[RolesAllowedDynamicFeature])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import edu.uci.ics.texera.workflow.common.tuple.schema.Attribute
import edu.uci.ics.texera.workflow.common.workflow.{PhysicalPlan, WorkflowCompiler}
import org.jooq.types.UInteger

import javax.annotation.security.RolesAllowed
import javax.ws.rs.{Consumes, POST, Path, PathParam, Produces}
import javax.ws.rs.core.MediaType

Expand All @@ -20,6 +21,7 @@ case class WorkflowCompilationResponse(

@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
@RolesAllowed(Array("REGULAR", "ADMIN"))
@Path("/compilation")
class WorkflowCompilationResource extends LazyLogging {
@POST
Expand Down

0 comments on commit 730561a

Please sign in to comment.