Skip to content

Commit

Permalink
JAMES-4025 Drop JMAP draft guice binding
Browse files Browse the repository at this point in the history
  • Loading branch information
vttranlina authored and Arsnael committed Apr 15, 2024
1 parent 732f872 commit d176f77
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 439 deletions.
6 changes: 1 addition & 5 deletions server/container/guice/protocols/jmap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<artifactId>james-server-guice-jmap</artifactId>

<name>Apache James :: Server :: Guice :: JMAP</name>
<description>JMAP (draft and RFC8621) modules for Guice implementation of James server</description>
<description>JMAP RFC8621 modules for Guice implementation of James server</description>

<dependencies>
<dependency>
Expand Down Expand Up @@ -57,10 +57,6 @@
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-mailet</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-jmap-draft</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-jmap-rfc-8621</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.james.jmap;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.util.EnumSet;
Expand Down Expand Up @@ -47,10 +46,6 @@
import org.apache.james.jmap.core.SubmissionCapabilityFactory;
import org.apache.james.jmap.core.VacationResponseCapabilityFactory$;
import org.apache.james.jmap.core.WebSocketCapabilityFactory$;
import org.apache.james.jmap.draft.DraftMethodsModule;
import org.apache.james.jmap.draft.JMAPDraftCommonModule;
import org.apache.james.jmap.draft.JMAPDraftConfiguration;
import org.apache.james.jmap.draft.methods.RequestHandler;
import org.apache.james.jmap.mailet.filter.JMAPFiltering;
import org.apache.james.jmap.rfc8621.RFC8621MethodsModule;
import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
Expand Down Expand Up @@ -120,16 +115,13 @@ public class JMAPModule extends AbstractModule {

@Override
protected void configure() {
install(new JMAPDraftCommonModule());
install(new JMAPWithoutDraftCommonModule());
install(new DraftMethodsModule());
install(new RFC8621MethodsModule());
install(binder -> binder
.bind(MailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
.toInstance(DEFAULT_JMAP_PROCESSORS_CONFIGURATION_SUPPLIER));

bind(JMAPServer.class).in(Scopes.SINGLETON);
bind(RequestHandler.class).in(Scopes.SINGLETON);
bind(JsoupHtmlTextExtractor.class).in(Scopes.SINGLETON);

bind(HtmlTextExtractor.class).to(JsoupHtmlTextExtractor.class);
Expand Down Expand Up @@ -228,35 +220,19 @@ public static JMAPConfiguration parseConfiguration(PropertiesProvider properties

@Provides
@Singleton
JMAPDraftConfiguration provideDraftConfiguration(PropertiesProvider propertiesProvider, FileSystem fileSystem) throws ConfigurationException, IOException {
@Named("jmap")
JwtTokenVerifier providesJwtTokenVerifier(PropertiesProvider propertiesProvider, FileSystem fileSystem) throws ConfigurationException {
try {
Configuration configuration = propertiesProvider.getConfiguration("jmap");
return JMAPDraftConfiguration.builder()
.enabled(configuration.getBoolean("enabled", true))
.keystore(configuration.getString("tls.keystoreURL", null))
.privateKey(configuration.getString("tls.privateKey", null))
.certificates(configuration.getString("tls.certificates", null))
.keystoreType(configuration.getString("tls.keystoreType", null))
.secret(configuration.getString("tls.secret", null))
.jwtPublicKeyPem(loadPublicKey(fileSystem, ImmutableList.copyOf(configuration.getStringArray("jwt.publickeypem.url"))))
.authenticationStrategies(Optional.ofNullable(configuration.getList(String.class, "authentication.strategy.draft", null)))
.build();
List<String> loadedPublicKey = loadPublicKey(fileSystem, ImmutableList.copyOf(configuration.getStringArray("jwt.publickeypem.url")));
JwtConfiguration jwtConfiguration = new JwtConfiguration(loadedPublicKey);
return JwtTokenVerifier.create(jwtConfiguration);
} catch (FileNotFoundException e) {
LOGGER.warn("Could not find JMAP configuration file. JMAP server will not be enabled.");
return JMAPDraftConfiguration.builder()
.disable()
.build();
LOGGER.warn("Could not find JMAP configuration file. JwtTokenVerifier was initialized with empty public key ");
return JwtTokenVerifier.create(new JwtConfiguration(List.of()));
}
}

@Provides
@Singleton
@Named("jmap")
JwtTokenVerifier providesJwtTokenVerifier(JMAPDraftConfiguration jmapConfiguration) {
JwtConfiguration jwtConfiguration = new JwtConfiguration(jmapConfiguration.getJwtPublicKeyPem());
return JwtTokenVerifier.create(jwtConfiguration);
}

private List<String> loadPublicKey(FileSystem fileSystem, List<String> jwtPublickeyPemUrl) {
return jwtPublickeyPemUrl.stream()
.map(Throwing.function(url -> FileUtils.readFileToString(fileSystem.getFile(url), StandardCharsets.US_ASCII)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package org.apache.james.jmap;

import java.util.concurrent.TimeUnit;

import org.apache.james.jmap.api.access.AccessTokenRepository;
import org.apache.james.jmap.json.ObjectMapperFactory;
import org.apache.james.jmap.methods.BlobManager;
import org.apache.james.jmap.methods.BlobManagerImpl;
Expand All @@ -34,8 +37,10 @@

import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.name.Names;

public class JMAPWithoutDraftCommonModule extends AbstractModule {
private static final long DEFAULT_TOKEN_EXPIRATION_IN_MS = TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);

@Override
protected void configure() {
Expand All @@ -53,5 +58,7 @@ protected void configure() {
bind(ObjectMapperFactory.class).in(Scopes.SINGLETON);
bind(JmapResponseWriterImpl.class).in(Scopes.SINGLETON);
bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class);

bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit d176f77

Please sign in to comment.