Skip to content

Commit

Permalink
Näytä kansalaiselle myös OAuth2-rajapinnan kautta katselut
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksiAhtiainen committed Jan 2, 2025
1 parent 59895ac commit b31a9f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ mydata = {
purpose = "Tietoja käytetään opiskelijahintaisten matkalippujen myöntämiseen."
membercodes = ["2769790-1"] # Identify API caller
subsystemcodes = ["koski"] # Unused
orgOid = "1.2.246.562.10.77876988401" # Mydata use is interpreted based on this from auditlogs
},
{
id = "frank"
name = "Frank"
purpose = ""
membercodes = ["2769790-2"]
subsystemcodes = ["koski"]
orgOid = "1.2.246.562.10.46399742280"
},
]
callbackURLs = [
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/fi/oph/koski/mydata/MyDataConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ trait MyDataConfig extends Logging {
)
}

def isMyDataOrg(orgOid: String): Boolean = {
conf.getConfigList("members").asScala.exists(member =>
member.getString("orgOid") == orgOid
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import fi.oph.koski.organisaatio.Opetushallitus
import fi.oph.koski.http.{HttpStatus, KoskiErrorCategory}
import fi.oph.koski.json.JsonSerializer
import fi.oph.koski.log.Logging
import fi.oph.koski.mydata.MyDataConfig
import fi.oph.koski.schema.LocalizedString
import fi.oph.koski.omaopintopolkuloki.AuditLogDynamoDB.AuditLogTableName
import software.amazon.awssdk.services.dynamodb.model.{AttributeValue, QueryRequest}

import scala.collection.JavaConverters._

class AuditLogService(app: KoskiApplication) extends Logging {
private val organisaatioRepository = app.organisaatioRepository
private val dynamoDB = AuditLogDynamoDB.buildDb(app.config)
class AuditLogService(val application: KoskiApplication) extends Logging with MyDataConfig {
private val organisaatioRepository = application.organisaatioRepository
private val dynamoDB = AuditLogDynamoDB.buildDb(application.config)

def queryLogsFromDynamo(oppijaOid: String): Either[HttpStatus, Seq[OrganisaationAuditLogit]] = {
runQuery(oppijaOid).flatMap(results => HttpStatus.foldEithers(buildLogs(results).toSeq))
Expand All @@ -25,13 +26,33 @@ class AuditLogService(app: KoskiApplication) extends Logging {
val querySpec = QueryRequest.builder
.tableName(AuditLogTableName)
.keyConditionExpression("studentOid = :oid")
.filterExpression("not contains (organizationOid, :self) and (contains (#rawEntry, :katsominen) or contains(#rawEntry, :varda_service))")
.filterExpression(
"""not contains (organizationOid, :self) and
| (contains (#rawEntry, :katsominen) or
| contains (#rawEntry, :muutoshistoria_katsominen) or
| contains (#rawEntry, :ytr_katsominen) or
| contains (#rawEntry, :oauth2_katsominen_kaikki_tiedot) or
| contains (#rawEntry, :oauth2_katsominen_suoritetut_tutkinnot) or
| contains (#rawEntry, :oauth2_katsominen_aktiiviset_ja_paattyneet_opinnot) or
| contains (#rawEntry, :suoritusjako_katsominen) or
| contains (#rawEntry, :suoritusjako_katsominen_suoritetut_tutkinnot) or
| contains (#rawEntry, :suoritusjako_katsominen_aktiiviset_ja_paattyneet_opinnot) or
| contains(#rawEntry, :varda_service))
| """.stripMargin)
.expressionAttributeNames(Map("#rawEntry" -> "raw").asJava)
.expressionAttributeValues({
val valueMap = new util.HashMap[String, AttributeValue]()
valueMap.put(":oid", AttributeValue.builder.s(oppijaOid).build)
valueMap.put(":self", AttributeValue.builder.s("self").build)
valueMap.put(":katsominen", AttributeValue.builder.s("\"OPISKELUOIKEUS_KATSOMINEN\"").build)
valueMap.put(":muutoshistoria_katsominen", AttributeValue.builder.s("\"MUUTOSHISTORIA_KATSOMINEN\"").build)
valueMap.put(":ytr_katsominen", AttributeValue.builder.s("\"YTR_OPISKELUOIKEUS_KATSOMINEN\"").build)
valueMap.put(":suoritusjako_katsominen", AttributeValue.builder.s("\"KANSALAINEN_SUORITUSJAKO_KATSOMINEN\"").build)
valueMap.put(":suoritusjako_katsominen_suoritetut_tutkinnot", AttributeValue.builder.s("\"KANSALAINEN_SUORITUSJAKO_KATSOMINEN_SUORITETUT_TUTKINNOT\"").build)
valueMap.put(":suoritusjako_katsominen_aktiiviset_ja_paattyneet_opinnot", AttributeValue.builder.s("\"KANSALAINEN_SUORITUSJAKO_KATSOMINEN_AKTIIVISET_JA_PAATTYNEET_OPINNOT\"").build)
valueMap.put(":oauth2_katsominen_kaikki_tiedot", AttributeValue.builder.s("\"OAUTH2_KATSOMINEN_KAIKKI_TIEDOT\"").build)
valueMap.put(":oauth2_katsominen_suoritetut_tutkinnot", AttributeValue.builder.s("\"OAUTH2_KATSOMINEN_SUORITETUT_TUTKINNOT\"").build)
valueMap.put(":oauth2_katsominen_aktiiviset_ja_paattyneet_opinnot", AttributeValue.builder.s("\"OAUTH2_KATSOMINEN_AKTIIVISET_JA_PAATTYNEET_OPINNOT\"").build)
valueMap.put(":varda_service", AttributeValue.builder.s("\"varda\"").build)
valueMap
})
Expand Down Expand Up @@ -71,12 +92,14 @@ class AuditLogService(app: KoskiApplication) extends Logging {
val organisaatioOidit = parsedRow.organizationOid.sorted
val timestampString = parsedRow.time
val serviceName = parsedRaw.serviceName
(organisaatioOidit, serviceName, timestampString)
}).groupBy(x => (x._1, x._2)).mapValues(_.map(_._3))
val isMyDataUse = parsedRaw.operation.startsWith("OAUTH2_KATSOMINEN") || parsedRow.organizationOid.headOption.exists(isMyDataOrg)
val isJakolinkkiUse = parsedRaw.operation.startsWith("KANSALAINEN_SUORITUSJAKO_KATSOMINEN")
(organisaatioOidit, serviceName, isMyDataUse, isJakolinkkiUse, timestampString)
}).groupBy(x => (x._1, x._2, x._3, x._4)).mapValues(_.map(_._5))

timestampsGroupedByListOfOidsAndServiceName.map { case ((orgs, serviceName), timestamps) =>
timestampsGroupedByListOfOidsAndServiceName.map { case ((orgs, serviceName, isMyDataUse, isJakolinkkiUse), timestamps) =>
HttpStatus.foldEithers(orgs.map(toOrganisaatio))
.map(orgs => OrganisaationAuditLogit(orgs, serviceName, timestamps))
.map(orgs => OrganisaationAuditLogit(orgs, serviceName, isMyDataUse, isJakolinkkiUse, timestamps))
}
}

Expand Down Expand Up @@ -105,16 +128,20 @@ case class AuditlogRow (
time: String
)
case class AuditlogRaw (
serviceName: String
serviceName: String,
operation: String
)

case class OrganisaationAuditLogit(
organizations: Seq[Organisaatio],
serviceName: String,
isMyDataUse: Boolean,
isJakolinkkiUse: Boolean,
timestamps: Seq[String]
)

case class Organisaatio(
oid: String,
name: LocalizedString
)

0 comments on commit b31a9f1

Please sign in to comment.