Skip to content

Commit 91ac2a3

Browse files
committed
refactor(examples): small improvements for oidc example
- More modern syntax in compose file. - Remove non-working links from readme. - Use consistent container names (always ending in .example.com). - Reduce output of test script.
1 parent aef754d commit 91ac2a3

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

examples/oidc/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ This is example of an OIDC setup with James.
66

77
The API Gateway for example is [Apisix](https://apisix.apache.org/), we can use Apisix for websocket gateway, horizontal scaling, etc...
88

9-
This [docker-compose](docker-compose.yml) will start the following services:
9+
This [docker compose](./compose.yaml) will start the following services:
1010

1111
- apisix: The image `linagora/apisix:3.2.0-debian-javaplugin` was created by Linagora. It based on `apisix:3.2.0-debian`, it already contain apisix plugin for
1212
SLO (Single Logout) and rewrite the `X-User` header.
13-
- Dockerfile: [here](https://github.com/linagora/tmail-backend/blob/master/demo/apisix/Dockerfile)
14-
- Project `tmail-apisix-plugin-runner`: [here](https://github.com/linagora/tmail-backend/tree/master/demo/apisix/tmail-apisix-plugin-runner)
1513
- Apisix being the OIDC gateway against James by exposing two endpoints:
1614
- `POST /jmap` for JMAP requests against James with normal authentication
1715
- `POST /oidc/jmap` for JMAP request against James with a JWT token issued by the LemonLDAP
@@ -161,21 +159,21 @@ Use websocket with endpoint `ws://apisix.example.com:9080/oidc/jmap/ws` and the
161159

162160
We would use Thunderbird version 91.4.1 as a mail client (above versions should work).
163161
* Open `/thunderbird/omni.ja` in your host, find and modify `OAuth2Providers.jsm`:
164-
* Add James hostname in kHostnames: `["localhost", ["james.local", "email"]],`
162+
* Add James hostname in kHostnames: `["localhost", ["james.example.com", "email"]],`
165163
* Register using `james-thunderbird` Keycloak client in kIssuers:
166164
```
167165
[
168-
"james.local",
166+
"james.example.com",
169167
[
170168
"james-thunderbird", //client_id from keycloak
171169
"Xw9ht1veTu0Tk5sMMy03PdzY3AiFvssw", // client_secret from keycloak
172-
"http://keycloak.local:8080/auth/realms/oidc/protocol/openid-connect/auth",
173-
"http://keycloak.local:8080/auth/realms/oidc/protocol/openid-connect/token",
170+
"http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/auth",
171+
"http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/token",
174172
],
175173
]
176174
```
177175

178-
* Adding a line `127.0.0.1 keycloak.local` to your `/etc/hosts` so Thunderbird can resolve the address of keycloak.
176+
* Adding a line `127.0.0.1 sso.example.com` to your `/etc/hosts` so Thunderbird can resolve the address of keycloak.
179177
* Run Thunderbird, configure it using `james-user@localhost` account against these IMAP/SMTP settings:
180178
* IMAP: server: localhost, port: 143, connection security: No, authentication method: OAUTH2
181179
![](_media/imap-setting.png)

examples/oidc/apisix/conf/apisix.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ upstreams:
219219
-
220220
id: jmap_upstream
221221
nodes:
222-
"james:80": 1
222+
"james.example.com:80": 1
223223
type: roundrobin
224224

225225
plugin_configs:
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
apisix:
53
container_name: apisix.example.com
@@ -8,63 +6,62 @@ services:
86
- ./apisix/conf/apisix.yaml:/usr/local/apisix/conf/apisix.yaml
97
- ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml
108
environment:
11-
- X_USER_SECRET=xusersecret123
9+
X_USER_SECRET: xusersecret123
1210
networks:
1311
- james
1412
ports:
15-
- "9080:9080/tcp"
13+
- "127.0.0.1:9080:9080"
1614

1715
james:
1816
depends_on:
1917
- ldap
2018
networks:
2119
- james
2220
image: apache/james:memory-latest
23-
container_name: james
24-
hostname: james.local
25-
command:
26-
- --generate-keystore
21+
container_name: james.example.com
22+
hostname: james.example.com
23+
command: [--generate-keystore]
2724
volumes:
2825
- ./james/usersrepository.xml:/root/conf/usersrepository.xml
2926
- ./james/jmap.properties:/root/conf/jmap.properties
3027
- ./james/imapserver.xml:/root/conf/imapserver.xml
3128
- ./james/smtpserver.xml:/root/conf/smtpserver.xml
3229
- ./james/managesieveserver.xml:/root/conf/managesieveserver.xml
3330
ports:
34-
- "8000:8000"
35-
- "143:143"
36-
- "587:587"
37-
- "4190:4190"
31+
- "127.0.0.1:8000:8000"
32+
- "127.0.0.1:143:143"
33+
- "127.0.0.1:587:587"
34+
- "127.0.0.1:4190:4190"
3835
healthcheck:
3936
test: ["CMD", "curl", "-f", "http://james:8000/domains"]
4037

41-
sso.example.com:
38+
sso:
4239
depends_on:
4340
- ldap
4441
image: quay.io/keycloak/keycloak:16.1.0
4542
container_name: sso.example.com
4643
volumes:
4744
- ./keycloak/realm-oidc.json:/tmp/realm-oidc.json
4845
ports:
49-
- "8080:8080"
46+
- "127.0.0.1:8080:8080"
5047
environment:
51-
- KEYCLOAK_USER=admin
52-
- KEYCLOAK_PASSWORD=admin
53-
- KEYCLOAK_IMPORT=/tmp/realm-oidc.json
48+
KEYCLOAK_USER: admin
49+
KEYCLOAK_PASSWORD: admin
50+
KEYCLOAK_IMPORT: /tmp/realm-oidc.json
5451
networks:
5552
- james
5653

5754
ldap:
58-
container_name: ldap
55+
container_name: ldap.example.com
5956
image: osixia/openldap:1.5.0
6057
ports:
61-
- "389:389"
62-
- "636:636"
58+
- "127.0.0.1:389:389"
59+
- "127.0.0.1:636:636"
6360
command: [--copy-service]
6461
volumes:
6562
- ./ldap/populate.ldif:/container/service/slapd/assets/config/bootstrap/ldif/data.ldif
6663
environment:
67-
- LDAP_DOMAIN=localhost
64+
LDAP_DOMAIN: localhost
6865
networks:
6966
- james
7067

@@ -75,7 +72,7 @@ services:
7572
networks:
7673
- james
7774
ports:
78-
- "6379:6379"
75+
- "127.0.0.1:6379:6379"
7976

8077
networks:
81-
james:
78+
james:

examples/oidc/james/usersrepository.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<usersrepository name="LocalUsers"
2424
class="org.apache.james.user.ldap.ReadOnlyUsersLDAPRepository"
25-
ldapHost="ldap://ldap:389"
25+
ldapHost="ldap://ldap.example.com:389"
2626
principal="cn=admin,dc=localhost"
2727
credentials="admin"
2828
userBase="ou=people,dc=localhost"

examples/oidc/test.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/sh
22

3-
set -eux
3+
# You need to start the compose project before running this script!
44

5-
docker-compose up -d
5+
set -eu
6+
# Uncomment the following line to print more information.
7+
# set -x
68

79
GET_TOKEN_RESPONSE=`curl --location 'http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/token' \
810
--header 'Content-Type: application/x-www-form-urlencoded' \
@@ -14,7 +16,9 @@ GET_TOKEN_RESPONSE=`curl --location 'http://sso.example.com:8080/auth/realms/oid
1416
--data-urlencode 'password=secret' 2>/dev/null`
1517

1618
ACCESS_TOKEN=`echo $GET_TOKEN_RESPONSE 2>/dev/null |perl -pe 's/^.*"access_token"\s*:\s*"(.*?)".*$/$1/'`
19+
echo "Access token: $ACCESS_TOKEN"
1720
REFRESH_TOKEN=`echo $GET_TOKEN_RESPONSE 2>/dev/null |perl -pe 's/^.*"refresh_token"\s*:\s*"(.*?)".*$/$1/'`
21+
echo "Refresh token: $REFRESH_TOKEN"
1822

1923
echo "Got an access_token"
2024
if curl -H "Authorization: Bearer $ACCESS_TOKEN" http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/userinfo 2>/dev/null| grep james-user >/dev/null; then
@@ -23,8 +27,7 @@ else
2327
echo "ACCESS_TOKEN VERIFICATION FAILED"
2428
fi
2529

26-
echo -n "Trying James: "
27-
30+
echo -n "Trying James:"
2831
APISIX_JMAP_ENDPOINT=apisix.example.com:9080/oidc/jmap/session
2932
if curl -v -H 'Accept: application/json; jmapVersion=rfc-8621' -H "Authorization: Bearer $ACCESS_TOKEN" $APISIX_JMAP_ENDPOINT 2>/dev/null | grep uploadUrl >/dev/null; then
3033
echo "OK"
@@ -33,45 +36,45 @@ else
3336
fi
3437

3538
XOAUTH2_INITIAL_CLIENT_RESPONSE=`echo -n -e "user=james-user@localhost\x01auth=Bearer ${ACCESS_TOKEN}\x01\x01" | base64 -w 0`
39+
echo "XOAUTH2: $XOAUTH2_INITIAL_CLIENT_RESPONSE"
3640
OAUTHBEARER_INITIAL_CLIENT_RESPONSE=`echo -n -e "n,a=james-user@localhost\x01auth=Bearer ${ACCESS_TOKEN}\x01\x01" | base64 -w 0`
41+
echo "OAUTHBEARER: $OAUTHBEARER_INITIAL_CLIENT_RESPONSE"
3742

38-
set +x
39-
MANAGESIEVE_XOAUTH2_RESPONSE=`(echo "AUTHENTICATE \"XOAUTH2\" \"${XOAUTH2_INITIAL_CLIENT_RESPONSE}\""; echo "CAPABILITY"; echo "LOGOUT"; sleep 3) | telnet localhost 4190`
40-
if echo $MANAGESIEVE_XOAUTH2_RESPONSE | grep "\"OWNER\" \"james-user@localhost\"" > /dev/null; then
43+
MANAGESIEVE_XOAUTH2_RESPONSE=`(echo "AUTHENTICATE \"XOAUTH2\" \"${XOAUTH2_INITIAL_CLIENT_RESPONSE}\""; echo "CAPABILITY"; echo "LOGOUT"; sleep 3) | telnet 127.0.0.1 4190`
44+
if echo "$MANAGESIEVE_XOAUTH2_RESPONSE" | grep "\"OWNER\" \"james-user@localhost\"" > /dev/null; then
4145
echo "Success: Managesieve XOAUTH2 login"
4246
else
4347
echo "Error: Managesieve XOAUTH2 login"
4448
fi
45-
if echo $MANAGESIEVE_XOAUTH2_RESPONSE | grep "OK channel is closing" > /dev/null; then
49+
if echo "$MANAGESIEVE_XOAUTH2_RESPONSE" | grep "OK channel is closing" > /dev/null; then
4650
echo "Success: Managesieve XOAUTH2 logout"
4751
else
4852
echo "Error: Managesieve XOAUTH2 logout"
4953
fi
5054

51-
IMAP_XOAUTH2_RESPONSE=`(echo "a AUTHENTICATE XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "c LOGOUT"; sleep 3) | telnet localhost 143`
52-
if echo $IMAP_XOAUTH2_RESPONSE | grep "a OK AUTHENTICATE completed" > /dev/null; then
55+
IMAP_XOAUTH2_RESPONSE=`(echo "a AUTHENTICATE XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "c LOGOUT"; sleep 3) | telnet 127.0.0.1 143`
56+
if echo "$IMAP_XOAUTH2_RESPONSE" | grep "a OK AUTHENTICATE completed" > /dev/null; then
5357
echo "Success: IMAP XOAUTH2 login"
5458
else
5559
echo "Error: IMAP XOAUTH2 login"
5660
fi
57-
if echo $IMAP_XOAUTH2_RESPONSE | grep "c OK LOGOUT completed" > /dev/null; then
61+
if echo "$IMAP_XOAUTH2_RESPONSE" | grep "c OK LOGOUT completed" > /dev/null; then
5862
echo "Success: IMAP XOAUTH2 logout"
5963
else
6064
echo "Error: IMAP XOAUTH2 logout"
6165
fi
6266

63-
SMTP_XOAUTH2_RESPONSE=`(echo "AUTH XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "QUIT"; sleep 3) | telnet localhost 587`
64-
if echo $SMTP_XOAUTH2_RESPONSE | grep "235 Authentication successful" > /dev/null; then
67+
SMTP_XOAUTH2_RESPONSE=`(echo "AUTH XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "QUIT"; sleep 3) | telnet 127.0.0.1 587`
68+
if echo "$SMTP_XOAUTH2_RESPONSE" | grep "235 Authentication successful" > /dev/null; then
6569
echo "Success: SMTP XOAUTH2 login"
6670
else
6771
echo "Error: SMTP XOAUTH2 login"
6872
fi
69-
if echo $SMTP_XOAUTH2_RESPONSE | grep "221 2.0.0 james.local Service closing transmission channel" > /dev/null; then
73+
if echo "$SMTP_XOAUTH2_RESPONSE" | grep "221 2.0.0 james.example.com Service closing transmission channel" > /dev/null; then
7074
echo "Success: SMTP XOAUTH2 logout"
7175
else
7276
echo "Error: SMTP XOAUTH2 logout"
7377
fi
74-
set -x
7578

7679
# Logout
7780

0 commit comments

Comments
 (0)