Skip to content

Commit

Permalink
ISSUE-1240 Use JMAPExtensionConfiguration to handle Webfinger config
Browse files Browse the repository at this point in the history
  • Loading branch information
quantranhong1999 authored and vttranlina committed Oct 29, 2024
1 parent c105a6d commit eb46d51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.linagora.tmail.james.common
import java.net.URL

import com.google.inject.Module
import com.linagora.tmail.james.jmap.oidc.WebFingerConfiguration
import com.linagora.tmail.james.jmap.WebFingerConfiguration
import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
import io.restassured.RestAssured.{`given`, requestSpecification}
import io.restassured.authentication.NoAuthScheme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.linagora.tmail.james.jmap

import java.net.{URI, URL}
import java.time.Duration
import java.time.temporal.ChronoUnit
import java.util.Locale
Expand Down Expand Up @@ -50,8 +51,10 @@ object JMAPExtensionConfiguration {

val emailRecoveryActionConfiguration: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration.from(configuration)

val webFingerConfiguration: WebFingerConfiguration = WebFingerConfiguration.parse(configuration)

JMAPExtensionConfiguration(publicAssetTotalSizeLimit, supportMailAddressOpt, ticketIpValidationEnable,
calendarEventReplySupportedLanguagesConfig, emailRecoveryActionConfiguration)
calendarEventReplySupportedLanguagesConfig, emailRecoveryActionConfiguration, webFingerConfiguration)
}
}

Expand All @@ -66,7 +69,8 @@ case class JMAPExtensionConfiguration(publicAssetTotalSizeLimit: PublicAssetTota
supportMailAddress: Option[MailAddress] = Option.empty,
ticketIpValidationEnable: TicketIpValidationEnable = TICKET_IP_VALIDATION_ENABLED,
calendarEventReplySupportedLanguagesConfig: CalendarEventReplySupportedLanguagesConfig = CALENDAR_EVENT_REPLY_SUPPORTED_LANGUAGES_DEFAULT,
emailRecoveryActionConfiguration: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration.DEFAULT) {
emailRecoveryActionConfiguration: EmailRecoveryActionConfiguration = EmailRecoveryActionConfiguration.DEFAULT,
webFingerConfiguration: WebFingerConfiguration = WebFingerConfiguration.DEFAULT) {
def this(publicAssetTotalSizeLimit: PublicAssetTotalSizeLimit) = {
this(publicAssetTotalSizeLimit, Option.empty)
}
Expand Down Expand Up @@ -104,4 +108,13 @@ object EmailRecoveryActionConfiguration {
}
}

case class EmailRecoveryActionConfiguration(maxEmailRecoveryPerRequest: Long, restorationHorizon: Duration)
case class EmailRecoveryActionConfiguration(maxEmailRecoveryPerRequest: Long, restorationHorizon: Duration)

object WebFingerConfiguration {
val DEFAULT: WebFingerConfiguration = WebFingerConfiguration(None)

def parse(configuration: Configuration): WebFingerConfiguration =
WebFingerConfiguration(Option(configuration.getString("oidc.provider.url", null)).map(new URI(_).toURL))
}

case class WebFingerConfiguration(openIdUrl: Option[URL])
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import java.util.stream
import com.google.inject.multibindings.Multibinder
import com.google.inject.{AbstractModule, Provides}
import com.linagora.tmail.james.jmap.oidc.WebFingerRoutes.LOGGER
import com.linagora.tmail.james.jmap.{JMAPExtensionConfiguration, WebFingerConfiguration}
import io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE
import io.netty.handler.codec.http.HttpResponseStatus.{BAD_REQUEST, INTERNAL_SERVER_ERROR}
import io.netty.handler.codec.http.{HttpMethod, HttpResponseStatus, QueryStringDecoder}
import jakarta.inject.Inject
import org.apache.commons.configuration2.Configuration
import org.apache.james.jmap.HttpConstants.JSON_CONTENT_TYPE
import org.apache.james.jmap.core.ProblemDetails
import org.apache.james.jmap.json.ResponseSerializer
import org.apache.james.jmap.{Endpoint, JMAPRoute, JMAPRoutes}
import org.apache.james.utils.PropertiesProvider
import org.slf4j.{Logger, LoggerFactory}
import play.api.libs.json.{JsString, Json, Writes}
import reactor.core.publisher.Mono
Expand All @@ -37,25 +36,17 @@ private[oidc] object Serializers {
def serialise(response: WebFingerResponse): String = Json.stringify(Json.toJson(response))
}

object WebFingerConfiguration {
def parse(configuration: Configuration): WebFingerConfiguration =
WebFingerConfiguration(Option(configuration.getString("oidc.provider.url", null)).map(new URL(_)))
}

case class WebFingerRequest(resource: URL)

case class WebFingerConfiguration(openIdUrl: Option[URL])

case class WebFingerModule() extends AbstractModule {
override def configure(): Unit = {
val routes = Multibinder.newSetBinder(binder, classOf[JMAPRoutes])
routes.addBinding().to(classOf[WebFingerRoutes])
}

@Provides
def configuration(propertiesProvider: PropertiesProvider): WebFingerConfiguration =
Try(propertiesProvider.getConfiguration("jmap"))
.fold(_ => WebFingerConfiguration(None), WebFingerConfiguration.parse)
def configuration(jmapExtensionConfiguration: JMAPExtensionConfiguration): WebFingerConfiguration =
jmapExtensionConfiguration.webFingerConfiguration
}

object WebFingerRoutes {
Expand Down

0 comments on commit eb46d51

Please sign in to comment.