Skip to content

Commit

Permalink
add logging for users without permission to access tool
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-nowak committed Oct 30, 2024
1 parent a532d59 commit 7f7bff6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/conf/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.amazonaws.regions.{Region, RegionUtils}
import com.amazonaws.services.cloudwatch.AmazonCloudWatch
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import com.gu.permissions.PermissionsConfig
import org.apache.commons.io.IOUtils
import play.api.Mode
import play.api.{Configuration => PlayConfiguration}
Expand Down Expand Up @@ -170,6 +171,12 @@ class ApplicationConfiguration(val playConfiguration: PlayConfiguration, val env
object latest {
lazy val pageSize = 20
}

val permissions = PermissionsConfig(
stage = environment.stage,
region = aws.region,
awsCredentials = aws.mandatoryCredentials,
)
}

object Properties extends AutomaticResourceManagement {
Expand Down
8 changes: 8 additions & 0 deletions app/story_packages/auth/PanDomainAuthActions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ package story_packages.auth
import com.gu.pandomainauth.action.AuthActions
import com.gu.pandomainauth.model.AuthenticatedUser
import com.gu.pandomainauth.PanDomain
import com.gu.permissions.{PermissionDefinition, PermissionsProvider}
import play.api.mvc._
import conf.ApplicationConfiguration
import story_packages.services.Logging

trait PanDomainAuthActions extends AuthActions with Results with Logging {
def config: ApplicationConfiguration

val permissions = PermissionsProvider(config.permissions)

val StoryPackagesAccess = PermissionDefinition("story-packages-access", "story-packages")

override def validateUser(authedUser: AuthenticatedUser): Boolean = {
if (!permissions.hasPermission(StoryPackagesAccess, authedUser.user.email)) {
Logger.warn(s"User ${authedUser.user.email} does not have ${StoryPackagesAccess.name} permission")
}
PanDomain.guardianValidation(authedUser)
}

Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ libraryDependencies ++= jacksonOverrides ++ Seq(
"com.gu" %% "content-api-client-aws" % "0.7.5",
"com.gu" %% "fapi-client-play30" % "12.0.0",
"com.gu" %% "pan-domain-auth-play_3-0" % "4.0.0",
"com.gu" %% "editorial-permissions-client" % "2.15",
"com.gu" %% "story-packages-model" % "2.2.0",
"com.gu" %% "thrift-serializer" % "4.0.2",
"org.json4s" %% "json4s-native" % json4sVersion,
Expand Down

0 comments on commit 7f7bff6

Please sign in to comment.