Skip to content

Commit

Permalink
Move Ticket APIs to jmap-extensions-api
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri committed Nov 30, 2024
1 parent 4c4e644 commit 5b1d651
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.linagora.tmail.james.jmap.ticket

case class ForbiddenException() extends RuntimeException
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.linagora.tmail.james.jmap.ticket

import org.apache.james.core.Username
import org.apache.james.jmap.core.UTCDate

import java.net.InetAddress

case class Ticket(clientAddress: InetAddress,
value: TicketValue,
generatedOn: UTCDate,
validUntil: UTCDate,
username: Username)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.linagora.tmail.james.jmap.ticket

import reactor.core.scala.publisher.SMono

trait TicketStore {
def persist(ticket: Ticket): SMono[Unit]

def retrieve(value: TicketValue): SMono[Ticket]

def delete(ticketValue: TicketValue): SMono[Unit]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.linagora.tmail.james.jmap.ticket

import java.util.UUID
import scala.util.Try

object TicketValue {
def parse(string: String): Either[IllegalArgumentException, TicketValue] = Try(UUID.fromString(string))
.map(TicketValue(_))
.fold(e => Left(new IllegalArgumentException("TicketValue must be backed by a UUID", e)), Right(_))

def generate: TicketValue = TicketValue(UUID.randomUUID())
}

case class TicketValue(value: UUID)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.linagora.tmail.james.jmap.ticket

import java.net.InetAddress
import java.time.{Clock, ZonedDateTime}
import java.util.UUID

import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration
import jakarta.inject.Inject
Expand All @@ -11,23 +10,6 @@ import org.apache.james.jmap.core.UTCDate
import reactor.core.scala.publisher.SMono

import scala.collection.mutable
import scala.util.Try

object TicketValue {
def parse(string: String): Either[IllegalArgumentException, TicketValue] = Try(UUID.fromString(string))
.map(TicketValue(_))
.fold(e => Left(new IllegalArgumentException("TicketValue must be backed by a UUID", e)), Right(_))

def generate: TicketValue = TicketValue(UUID.randomUUID())
}

case class ForbiddenException() extends RuntimeException
case class TicketValue(value: UUID)
case class Ticket(clientAddress: InetAddress,
value: TicketValue,
generatedOn: UTCDate,
validUntil: UTCDate,
username: Username)

object TicketManager {
private val validity: java.time.Duration = java.time.Duration.ofMinutes(1)
Expand Down Expand Up @@ -73,14 +55,6 @@ class TicketManager @Inject() (clock: Clock, ticketStore: TicketStore, jmapExten
.flatMap(ticketStore.delete)
}

trait TicketStore {
def persist(ticket: Ticket): SMono[Unit]

def retrieve(value: TicketValue): SMono[Ticket]

def delete(ticketValue: TicketValue): SMono[Unit]
}

class MemoryTicketStore extends TicketStore {
private val map: mutable.Map[TicketValue, Ticket] = mutable.Map()

Expand Down

0 comments on commit 5b1d651

Please sign in to comment.