Skip to content

Commit 8f312df

Browse files
committed
webadmin authorization
Signed-off-by: sami <[email protected]>
1 parent 0ee85d7 commit 8f312df

File tree

14 files changed

+241
-100
lines changed

14 files changed

+241
-100
lines changed

backends-common/redis/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.apache.james</groupId>
6+
<artifactId>james-backends-common</artifactId>
7+
<version>3.9.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>apache-james-backends-redis</artifactId>
11+
<name>Apache James :: Backends Common :: Redis</name>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>${james.groupId}</groupId>
16+
<artifactId>james-core</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>${james.groupId}</groupId>
20+
<artifactId>james-server-guice-common</artifactId>
21+
<type>test-jar</type>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>${james.groupId}</groupId>
26+
<artifactId>james-server-testing</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.google.inject</groupId>
31+
<artifactId>guice</artifactId>
32+
<scope>provided</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>eu.timepit</groupId>
36+
<artifactId>refined_${scala.base}</artifactId>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.lettuce</groupId>
41+
<artifactId>lettuce-core</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.projectreactor</groupId>
45+
<artifactId>reactor-scala-extensions_${scala.base}</artifactId>
46+
<scope>provided</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.commons</groupId>
50+
<artifactId>commons-configuration2</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.scalatest</groupId>
54+
<artifactId>scalatest_${scala.base}</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.testcontainers</groupId>
58+
<artifactId>testcontainers</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>net.alchim31.maven</groupId>
67+
<artifactId>scala-maven-plugin</artifactId>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
</project>

examples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<james.protocols.groupId>${james.groupId}.protocols</james.protocols.groupId>
5151
<maven.compiler.target>1.11</maven.compiler.target>
5252
<maven.compiler.source>1.11</maven.compiler.source>
53+
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
5354
</properties>
5455

5556
<build>

examples/pom.xml.bak

Lines changed: 0 additions & 78 deletions
This file was deleted.

server/apps/distributed-app/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ $ docker compose -f docker-composeOLD.yml up
128128
$ cd server/apps/distributed-app/
129129
130130
$ mvn clean install -DskipTests
131-
OR
131+
## OR
132132
$ mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -Dsort.keepBlankLines -Dsort.predefinedSortOrder=custom_1 -DskipTests clean install
133133
134134
$ docker compose -f docker-compose.yml up -d

server/apps/distributed-app/docker-composeOLD.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ services:
1515
image: ghcr.io/appscode/inbox-server:latest
1616
container_name: james
1717
hostname: james.local
18-
# volumes:
19-
# - $PWD/webadmin.properties:/root/conf/webadmin.properties
18+
volumes:
19+
- $PWD/jmap.properties:/root/conf/jmap.properties
2020
command:
2121
- --generate-keystore
2222
networks:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Configuration file for JMAP
2+
# Read https://james.apache.org/server/config-jmap.html for further details
3+
4+
enabled=true
5+
jmap.version.default=rfc-8621
6+
tls.keystoreURL=file://conf/keystore
7+
tls.secret=james72laBalle
8+
9+
10+
jmap.port=80
11+
url.prefix=http://localhost
12+
websocket.url.prefix=ws://localhost
13+
14+
email.send.max.size=100M
15+
max.size.attachments.per.mail=100M
16+
# only not work for RabbitMQ mail queue
17+
#delay.sends.enabled=true
18+
19+
# Alternatively TLS keys can be supplied via PEM files
20+
# tls.privateKey=file://conf/private.nopass.key
21+
# tls.certificates=file://conf/certs.self-signed.csr
22+
# An optional secret might be specified for the private key
23+
# tls.secret=james72laBalle
24+
# view.email.query.enabled=true
25+
#authentication.strategy.draft=BasicAuthenticationStrategy
26+
user.provisioning.enabled=false
27+
#
28+
# If you wish to use OAuth authentication, you should provide a valid JWT public key.
29+
# The following entry specify the link to the URL of the public key file,
30+
# which should be a PEM format file.
31+
#
32+
jwt.publickeypem.url=file://conf/rs256-4096-public.pem
33+
# Should simple Email/query be resolved against a Cassandra projection, or should we resolve them against OpenSearch?
34+
# This enables a higher resilience, but the projection needs to be correctly populated. False by default.
35+
# view.email.query.enabled=true
36+
37+
# If you want to specify authentication strategies for Jmap draft version
38+
# For custom Authentication Strategy not inside package "org.apache.james.jmap.http", you have to specify its FQDN
39+
# authentication.strategy.draft=AccessTokenAuthenticationStrategy,JWTAuthenticationStrategy,QueryParameterAccessTokenAuthenticationStrategy
40+
41+
# If you want to specify authentication strategies for Jmap rfc-8621 version
42+
# For custom Authentication Strategy not inside package "org.apache.james.jmap.http", you have to specify its FQDN
43+
44+
authentication.strategy.rfc8621=JWTAuthenticationStrategy,BasicAuthenticationStrategy
45+
46+
# Prevent server side request forgery by preventing calls to the private network ranges. Defaults to true, can be disabled for testing.
47+
webpush.prevent.server.side.request.forgery=false
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
version: '3'
2+
3+
services:
4+
5+
james:
6+
depends_on:
7+
cassandra:
8+
condition: service_healthy
9+
opensearch:
10+
condition: service_started
11+
tika:
12+
condition: service_started
13+
rabbitmq:
14+
condition: service_started
15+
s3:
16+
condition: service_started
17+
image: sami7786/distributed-james-test:webadmin-invalidation
18+
volumes:
19+
- $PWD/jmap.properties:/root/conf/jmap.properties
20+
container_name: james
21+
hostname: james.local
22+
command:
23+
- --generate-keystore
24+
networks:
25+
- james
26+
ports:
27+
- "80:80"
28+
- "25:25"
29+
- "110:110"
30+
- "143:143"
31+
- "465:465"
32+
- "587:587"
33+
- "993:993"
34+
- "8000:8000"
35+
36+
opensearch:
37+
image: opensearchproject/opensearch:2.1.0
38+
environment:
39+
- discovery.type=single-node
40+
- DISABLE_INSTALL_DEMO_CONFIG=true
41+
- DISABLE_SECURITY_PLUGIN=true
42+
networks:
43+
james:
44+
aliases:
45+
- elasticsearch
46+
47+
cassandra:
48+
image: cassandra:4.1.3
49+
ports:
50+
- "9042:9042"
51+
healthcheck:
52+
test: [ "CMD", "cqlsh", "-e", "describe keyspaces" ]
53+
interval: 3s
54+
timeout: 20s
55+
retries: 5
56+
environment:
57+
- JVM_OPTS=-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=1
58+
networks:
59+
- james
60+
61+
tika:
62+
image: apache/tika:2.8.0.0
63+
networks:
64+
- james
65+
66+
rabbitmq:
67+
image: rabbitmq:3.12.1-management
68+
ports:
69+
- "5672:5672"
70+
- "15672:15672"
71+
networks:
72+
- james
73+
74+
s3:
75+
image: registry.scality.com/cloudserver/cloudserver:8.7.25
76+
container_name: s3.docker.test
77+
environment:
78+
- SCALITY_ACCESS_KEY_ID=accessKey1
79+
- SCALITY_SECRET_ACCESS_KEY=secretKey1
80+
- S3BACKEND=mem
81+
- LOG_LEVEL=trace
82+
- REMOTE_MANAGEMENT_DISABLE=1
83+
networks:
84+
- james
85+
86+
networks:
87+
james:

server/apps/distributed-app/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,9 @@
446446
<image>eclipse-temurin:11-jre-jammy</image>
447447
</from>
448448
<to>
449-
<<<<<<< HEAD
450449
<image>ghcr.io/appscode/inbox-server</image>
451450
<tags>
452451
<tag>latest</tag>
453-
=======
454-
<image>sami7786/distributed-james-test</image>
455-
<tags>
456-
<tag>disable-user-provisioning</tag>
457-
>>>>>>> ae975b8150 (Force JMAP endpoints to check for user existence.)
458452
</tags>
459453
</to>
460454
<container>

server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.james.server.task.json.dto.AdditionalInformationDTO;
4141
import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
4242
import org.apache.james.task.TaskExecutionDetails;
43+
import org.apache.james.user.api.UsersRepository;
4344
import org.apache.james.utils.ClassName;
4445
import org.apache.james.utils.ExtensionConfiguration;
4546
import org.apache.james.utils.GuiceGenericLoader;
@@ -182,11 +183,11 @@ private Optional<String> loadPublicKey(FileSystem fileSystem, Optional<String> j
182183
@Provides
183184
@Singleton
184185
public AuthenticationFilter providesAuthenticationFilter(PropertiesProvider propertiesProvider,
185-
@Named("webadmin") JwtTokenVerifier.Factory jwtTokenVerifier) throws Exception {
186+
@Named("webadmin") JwtTokenVerifier.Factory jwtTokenVerifier, UsersRepository usersRepository) throws Exception {
186187
try {
187188
Configuration configurationFile = propertiesProvider.getConfiguration("webadmin");
188189
if (configurationFile.getBoolean("jwt.enabled", DEFAULT_JWT_DISABLED)) {
189-
return new JwtFilter(jwtTokenVerifier);
190+
return new JwtFilter(jwtTokenVerifier, usersRepository);
190191
}
191192
return new NoAuthenticationFilter();
192193
} catch (FileNotFoundException e) {

server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JMAPApiRoutes.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ import java.util.stream.Stream
2525

2626
import io.netty.handler.codec.http.HttpHeaderNames.{CONTENT_LENGTH, CONTENT_TYPE}
2727
import io.netty.handler.codec.http.HttpMethod
28-
<<<<<<< HEAD
2928
import io.netty.handler.codec.http.HttpResponseStatus.OK
3029
import javax.inject.{Inject, Named}
31-
=======
32-
import io.netty.handler.codec.http.HttpResponseStatus.{NOT_FOUND, OK}
33-
import jakarta.inject.{Inject, Named}
34-
>>>>>>> b721547002 (Add UserNotFoundException)
3530
import org.apache.james.jmap.HttpConstants.JSON_CONTENT_TYPE
3631
import org.apache.james.jmap.JMAPUrls.JMAP
3732
import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier
@@ -107,7 +102,7 @@ class JMAPApiRoutes @Inject() (@Named(InjectionKeys.RFC_8621) val authenticator:
107102
.`then`()))
108103

109104
private def handleError(throwable: Throwable, response: HttpServerResponse): SMono[Void] = throwable match {
110-
case e: UserNotFoundException => respondDetails(e.addHeaders(response), ProblemDetails(status = NOT_FOUND, detail = e.getMessage))
105+
case e: UserNotFoundException => respondDetails(e.addHeaders(response), ProblemDetails.forThrowable(throwable))
111106
case e: UnauthorizedException => respondDetails(e.addHeaders(response), ProblemDetails.forThrowable(throwable))
112107
case _ => respondDetails(response, ProblemDetails.forThrowable(throwable))
113108
}

0 commit comments

Comments
 (0)