Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an API to interact with CalDav server #1465

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ private static List<Module> chooseLinagoraServicesDiscovery(LinagoraServicesDisc
private static List<Module> chooseOpenPaasModule(OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration) {
if (openPaasModuleChooserConfiguration.enabled()) {
ImmutableList.Builder<Module> moduleBuilder = ImmutableList.<Module>builder().add(new OpenPaasModule());
if (openPaasModuleChooserConfiguration.cardDavCollectedContactEnabled()) {
moduleBuilder.add(new OpenPaasModule.CardDavModule());
if (openPaasModuleChooserConfiguration.shouldEnableDavServerInteraction()) {
moduleBuilder.add(new OpenPaasModule.DavModule());
}
if (openPaasModuleChooserConfiguration.contactsConsumerEnabled()) {
moduleBuilder.add(new OpenPaasContactsConsumerModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ private static List<Module> chooseOpenPaas(OpenPaasModuleChooserConfiguration mo
if (moduleChooserConfiguration.enabled()) {
ImmutableList.Builder<Module> moduleBuilder = ImmutableList.<Module>builder().add(new OpenPaasModule());

if (moduleChooserConfiguration.cardDavCollectedContactEnabled()) {
moduleBuilder.add(new OpenPaasModule.CardDavModule());
chibenwa marked this conversation as resolved.
Show resolved Hide resolved
if (moduleChooserConfiguration.shouldEnableDavServerInteraction()) {
moduleBuilder.add(new OpenPaasModule.DavModule());
}
if (moduleChooserConfiguration.contactsConsumerEnabled()) {
moduleBuilder.add(Modules.override(new OpenPaasContactsConsumerModule())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ object CalendarAttendeeParticipationStatus {
.map(_.getValue)
.map(CalendarAttendeeParticipationStatus(_))
}
case class CalendarAttendeeParticipationStatus(value: String) extends AnyVal
case class CalendarAttendeeParticipationStatus(value: String)
object CalendarAttendeeExpectReply {
def from(attendee: Attendee): Option[CalendarAttendeeExpectReply] =
Option(attendee.getParameter("RSVP").asInstanceOf[Parameter])
Expand Down
4 changes: 4 additions & 0 deletions tmail-backend/tmail-third-party/openpaas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jmap-extensions</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we did fight hard not to get this dependency here.

Why do we get it?

How can we remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not handled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of it. I know it can be handled, but it takes some refactoring on the jmap-extensions side. I need to get the CalDAV stuff to work to understand what changes need to be made there.

</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.linagora.tmail.api.OpenPaasRestClient;
import com.linagora.tmail.carddav.CardDavClient;
import com.linagora.tmail.configuration.OpenPaasConfiguration;
import com.linagora.tmail.dav.DavClient;

public class OpenPaasModule extends AbstractModule {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenPaasModule.class);
Expand Down Expand Up @@ -65,14 +65,14 @@ public OpenPaasRestClient provideOpenPaasRestCLient(OpenPaasConfiguration openPa
return new OpenPaasRestClient(openPaasConfiguration);
}

public static class CardDavModule extends AbstractModule {
public static class DavModule extends AbstractModule {

@Provides
@Singleton
public CardDavClient provideCardDavClient(OpenPaasConfiguration openPaasConfiguration) {
Preconditions.checkArgument(openPaasConfiguration.cardDavConfiguration().isPresent(),
"OpenPaasConfiguration should have a carddav configuration");
return new CardDavClient.OpenpaasCardDavClient(openPaasConfiguration.cardDavConfiguration().get());
public DavClient provideDavClient(OpenPaasConfiguration openPaasConfiguration) {
Preconditions.checkArgument(openPaasConfiguration.davConfiguration().isPresent(),
"OpenPaasConfiguration should have dav configuration");
return new DavClient(openPaasConfiguration.davConfiguration().get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.linagora.tmail.configuration.CardDavConfiguration;
import com.linagora.tmail.configuration.DavConfiguration;
import com.linagora.tmail.configuration.OpenPaasConfiguration;

public record OpenPaasModuleChooserConfiguration(boolean enabled,
boolean cardDavCollectedContactEnabled,
boolean shouldEnableDavServerInteraction,
boolean contactsConsumerEnabled) {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenPaasModuleChooserConfiguration.class);
public static final boolean ENABLED = true;
Expand All @@ -43,10 +43,10 @@ public static OpenPaasModuleChooserConfiguration parse(PropertiesProvider proper
try {
Configuration configuration = propertiesProvider.getConfiguration("openpaas");
boolean contactsConsumerEnabled = OpenPaasConfiguration.isConfiguredContactConsumer(configuration);
boolean cardDavCollectedContactEnabled = CardDavConfiguration.isConfigured(configuration);
boolean isDavConfigured = DavConfiguration.isConfigured(configuration);
LOGGER.info("OpenPaas module is turned on. Contacts consumer is enabled: {}, CardDav is enabled: {}",
contactsConsumerEnabled, cardDavCollectedContactEnabled);
return new OpenPaasModuleChooserConfiguration(ENABLED, cardDavCollectedContactEnabled, contactsConsumerEnabled);
contactsConsumerEnabled, isDavConfigured);
return new OpenPaasModuleChooserConfiguration(ENABLED, isDavConfigured, contactsConsumerEnabled);
} catch (FileNotFoundException e) {
LOGGER.info("OpenPaas module is turned off.");
return new OpenPaasModuleChooserConfiguration(DISABLED, !ENABLE_CARDDAV, !ENABLE_CONTACTS_CONSUMER);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@

import com.google.common.base.Preconditions;

public record CardDavConfiguration(UsernamePasswordCredentials adminCredential,
URI baseUrl,
Optional<Boolean> trustAllSslCerts,
Optional<Duration> responseTimeout) {
public record DavConfiguration(UsernamePasswordCredentials adminCredential,
URI baseUrl,
Optional<Boolean> trustAllSslCerts,
Optional<Duration> responseTimeout) {
static final boolean CLIENT_TRUST_ALL_SSL_CERTS_DISABLED = false;
static final String CARD_DAV_API_URI_PROPERTY = "carddav.api.uri";
static final String CARD_DAV_ADMIN_USER_PROPERTY = "carddav.admin.user";
static final String CARD_DAV_ADMIN_PASSWORD_PROPERTY = "carddav.admin.password";
static final String CARD_DAV_REST_CLIENT_TRUST_ALL_SSL_CERTS_PROPERTY = "carddav.rest.client.trust.all.ssl.certs";
static final String CARD_DAV_REST_CLIENT_RESPONSE_TIMEOUT_PROPERTY = "carddav.rest.client.response.timeout";
Comment on lines 36 to 40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static final String CARD_DAV_API_URI_PROPERTY = "carddav.api.uri";
static final String CARD_DAV_ADMIN_USER_PROPERTY = "carddav.admin.user";
static final String CARD_DAV_ADMIN_PASSWORD_PROPERTY = "carddav.admin.password";
static final String CARD_DAV_REST_CLIENT_TRUST_ALL_SSL_CERTS_PROPERTY = "carddav.rest.client.trust.all.ssl.certs";
static final String CARD_DAV_REST_CLIENT_RESPONSE_TIMEOUT_PROPERTY = "carddav.rest.client.response.timeout";
static final String CARD_DAV_API_URI_PROPERTY = "dav.api.uri";
static final String CARD_DAV_ADMIN_USER_PROPERTY = "dav.admin.user";
static final String CARD_DAV_ADMIN_PASSWORD_PROPERTY = "dav.admin.password";
static final String CARD_DAV_REST_CLIENT_TRUST_ALL_SSL_CERTS_PROPERTY = "dav.rest.client.trust.all.ssl.certs";
static final String CARD_DAV_REST_CLIENT_RESPONSE_TIMEOUT_PROPERTY = "dav.rest.client.response.timeout";

While we are at it?


public static Optional<CardDavConfiguration> maybeFrom(Configuration configuration) {
public static Optional<DavConfiguration> maybeFrom(Configuration configuration) {
if (isConfigured(configuration)) {
return Optional.of(from(configuration));
}
return Optional.empty();
}

public static CardDavConfiguration from(Configuration configuration) {
public static DavConfiguration from(Configuration configuration) {
String adminUser = configuration.getString(CARD_DAV_ADMIN_USER_PROPERTY, null);
String adminPassword = configuration.getString(CARD_DAV_ADMIN_PASSWORD_PROPERTY, null);

Expand All @@ -64,7 +64,7 @@ public static CardDavConfiguration from(Configuration configuration) {
Preconditions.checkArgument(durationAsMilliseconds > 0, "Response timeout should not be negative");
return Duration.ofMillis(durationAsMilliseconds);
});
return new CardDavConfiguration(adminCredential, baseUrl, trustAllSslCerts, responseTimeout);
return new DavConfiguration(adminCredential, baseUrl, trustAllSslCerts, responseTimeout);
}

public static boolean isConfigured(Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public record OpenPaasConfiguration(URI apirUri,
String adminPassword,
boolean trustAllSslCerts,
Optional<ContactConsumerConfiguration> contactConsumerConfiguration,
Optional<CardDavConfiguration> cardDavConfiguration) {
Optional<DavConfiguration> davConfiguration) {

public record ContactConsumerConfiguration(List<AmqpUri> amqpUri,
boolean quorumQueuesBypass) {
Expand All @@ -46,7 +46,7 @@ public OpenPaasConfiguration(URI apirUri, String adminUsername, String adminPass
this(apirUri, adminUsername, adminPassword, trustAllSslCerts, Optional.of(contactConsumerConfiguration), Optional.empty());
}

public OpenPaasConfiguration(URI apirUri, String adminUsername, String adminPassword, boolean trustAllSslCerts, CardDavConfiguration cardDavConfiguration) {
public OpenPaasConfiguration(URI apirUri, String adminUsername, String adminPassword, boolean trustAllSslCerts, DavConfiguration cardDavConfiguration) {
this(apirUri, adminUsername, adminPassword, trustAllSslCerts, Optional.empty(), Optional.of(cardDavConfiguration));
}

Expand All @@ -69,7 +69,7 @@ public static OpenPaasConfiguration from(Configuration configuration) {
Optional<ContactConsumerConfiguration> contactConsumerConfiguration = readRabbitMqUri(configuration)
.map(amqpUri -> new ContactConsumerConfiguration(amqpUri, readQuorumQueuesBypass(configuration)));

Optional<CardDavConfiguration> cardDavConfiguration = CardDavConfiguration.maybeFrom(configuration);
Optional<DavConfiguration> cardDavConfiguration = DavConfiguration.maybeFrom(configuration);

return new OpenPaasConfiguration(openPaasApiUri, adminUser, adminPassword, trustAllSslCerts, contactConsumerConfiguration, cardDavConfiguration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* more details. *
********************************************************************/

package com.linagora.tmail.carddav;
package com.linagora.tmail.dav;

import java.nio.charset.StandardCharsets;
import java.util.List;
Expand All @@ -25,20 +25,21 @@
import org.apache.james.core.MailAddress;

import com.google.common.hash.Hashing;
import com.linagora.tmail.dav.request.CardDavCreationObjectRequest;

import ezvcard.parameter.EmailType;

public class CardDavCreationFactory {
public class CardDavUtils {
private static final String VERSION = "4.0";
private static final EmailType EMAIL_TYPE_DEFAULT = EmailType.WORK;
private static final EmailType DEFAULT_EMAIL_TYPE = EmailType.WORK;

public static CardDavCreationObjectRequest create(Optional<String> fullName, MailAddress email) {
CardDavCreationObjectRequest.Email emailObject = new CardDavCreationObjectRequest.Email(List.of(EMAIL_TYPE_DEFAULT), email);
return new CardDavCreationObjectRequest(VERSION, createContactUid(email), fullName, Optional.empty(), emailObject);
public static CardDavCreationObjectRequest createObjectCreationRequest(Optional<String> maybeFullName, MailAddress email) {
CardDavCreationObjectRequest.Email emailObject = new CardDavCreationObjectRequest.Email(List.of(DEFAULT_EMAIL_TYPE), email);
return new CardDavCreationObjectRequest(VERSION, createContactUid(email), maybeFullName, Optional.empty(), emailObject);
}

public static CardDavCreationObjectRequest create(MailAddress email) {
return create(Optional.empty(), email);
public static CardDavCreationObjectRequest createObjectCreationRequest(MailAddress email) {
return createObjectCreationRequest(Optional.empty(), email);
}

public static String createContactUid(MailAddress email) {
Expand Down
Loading