Skip to content

Commit 7d1a6de

Browse files
committed
Update to Java 17
1 parent e16eb6a commit 7d1a6de

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ Other noteworthy examples:
4646

4747
Remarks:
4848

49-
* Java 11 language level is kept, hence run with a late JDK 11
50-
because [caffeine 3.x](https://github.com/ben-manes/caffeine/releases) requires it as well
51-
as [ZipCryptoEcho](src/main/scala/alpakka/file/ZipCryptoEcho.scala). To speed things
49+
* Java 17 language level is kept, hence run with a late JDK 17 or higher. To speed things
5250
up [graalvm-jdk-21](https://www.graalvm.org/downloads) works best.
5351
* Most examples are throttled, so you can see from the console output what is happening
5452
* Some examples deliberately throw `RuntimeException`, so you can observe recovery behaviour

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ val kafkaVersion = "3.6.1"
1515
val activemqVersion = "5.18.4"
1616
val artemisVersion = "2.33.0"
1717
val testContainersVersion = "1.19.8"
18-
val keycloakVersion = "21.1.2" // stay with 21.x because of Java 11 compatibility
18+
val keycloakVersion = "24.0.4"
1919
val sttpVersion = "3.9.0"
2020
val influxdbVersion = "6.10.0"
2121
val awsClientVersion = "2.25.32"
@@ -131,7 +131,7 @@ libraryDependencies ++= Seq(
131131
"com.crobox.clickhouse" %% "client" % "1.1.4",
132132

133133
"org.opensearch" % "opensearch-testcontainers" % "2.0.1",
134-
"com.github.dasniko" % "testcontainers-keycloak" % "2.5.0",
134+
"com.github.dasniko" % "testcontainers-keycloak" % "3.3.1",
135135
"eu.rekawek.toxiproxy" % "toxiproxy-java" % "2.1.7",
136136
"org.testcontainers" % "junit-jupiter" % testContainersVersion % Test,
137137
"org.junit.jupiter" % "junit-jupiter-engine" % "5.9.2" % Test,

src/main/resources/KeycloakClient.html

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
2-
Stolen from:
3-
https://github.com/keycloak/keycloak/tree/main/examples/js-console
2+
HTML5 client, updated according to:
3+
https://www.keycloak.org/docs/24.0.4/securing_apps
44
-->
55

66
<html>
@@ -23,7 +23,7 @@
2323
<button onclick="refreshToken(9999)">Refresh Token</button>
2424
<button onclick="refreshToken(30)">Refresh Token (if <30s validity)</button>
2525
<button onclick="loadProfile()">Get Profile</button>
26-
<button onclick="updateProfile()">Update profile</button>
26+
<button onclick="updateProfile()">(Update profile)</button>
2727
<button onclick="loadUserInfo()">Get User Info</button>
2828
<button onclick="output(keycloak.tokenParsed)">Show Token</button>
2929
<button onclick="output(keycloak.refreshTokenParsed)">Show Refresh Token</button>
@@ -68,12 +68,13 @@ <h2>Events</h2>
6868
req.send();
6969
}
7070

71-
function loadProfile() {
72-
keycloak.loadUserProfile().success(function(profile) {
71+
async function loadProfile() {
72+
try {
73+
const profile = await keycloak.loadUserProfile();
7374
output(profile);
74-
}).error(function() {
75-
output('Failed to load profile');
76-
});
75+
} catch (error) {
76+
output('Failed to load user profile');
77+
}
7778
}
7879

7980
function updateProfile() {
@@ -93,16 +94,17 @@ <h2>Events</h2>
9394
}
9495
}
9596
}
96-
97-
req.send('{"email":"myemail@foo.bar","firstName":"test","lastName":"bar"}');
97+
<!-- For now: hardcoded values -->
98+
req.send('{"email":"myemail@foo.bar","firstName":"foo","lastName":"bar","username":"test"}');
9899
}
99100

100-
function loadUserInfo() {
101-
keycloak.loadUserInfo().success(function(userInfo) {
101+
async function loadUserInfo() {
102+
try {
103+
const userInfo = await keycloak.loadUserInfo();
102104
output(userInfo);
103-
}).error(function() {
105+
} catch (error) {
104106
output('Failed to load user info');
105-
});
107+
}
106108
}
107109

108110
function refreshToken(minValidity) {

src/main/scala/akkahttp/oidc/OIDCKeycloak.scala

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.apache.pekko.http.scaladsl.server.{AuthenticationFailedRejection, Dir
1212
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
1313
import org.keycloak.TokenVerifier
1414
import org.keycloak.adapters.KeycloakDeploymentBuilder
15-
import org.keycloak.admin.client.{CreatedResponseUtil, Keycloak, KeycloakBuilder}
15+
import org.keycloak.admin.client.{CreatedResponseUtil, Keycloak}
1616
import org.keycloak.jose.jws.AlgorithmType
1717
import org.keycloak.representations.AccessToken
1818
import org.keycloak.representations.adapters.config.AdapterConfig
@@ -33,13 +33,13 @@ import scala.util.{Failure, Success}
3333

3434

3535
/**
36-
* A "one-click" Keycloak OIDC server with pekko-http frontend
36+
* A "one-click" Keycloak OIDC server with pekko-http frontend.
37+
* The pekko-http endpoint /users loads all users from the Keycloak server.
3738
*
3839
* Inspired by:
3940
* https://scalac.io/blog/user-authentication-keycloak-1
4041
*
41-
* Uses a HTML5 client:
42-
* https://github.com/keycloak/keycloak/tree/main/examples/js-console
42+
* Uses a HTML5 client: src/main/resources/KeycloakClient.html
4343
* instead of the separate React client
4444
*
4545
* Runs with:
@@ -48,8 +48,7 @@ import scala.util.{Failure, Success}
4848
*
4949
* Doc:
5050
* https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter
51-
* https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/security-directives/index.html
52-
*
51+
* https://pekko.apache.org/docs/pekko-http/1.0/routing-dsl/directives/security-directives/index.html
5352
*/
5453
object OIDCKeycloak extends App with CORSHandler with JsonSupport {
5554
val logger: Logger = LoggerFactory.getLogger(this.getClass)
@@ -59,7 +58,7 @@ object OIDCKeycloak extends App with CORSHandler with JsonSupport {
5958

6059
def runKeycloak() = {
6160
// Pin to same version as "keycloakVersion" in build.sbt
62-
val keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:21.1.2")
61+
val keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:24.0.4")
6362
// Keycloak config taken from:
6463
// https://github.com/keycloak/keycloak/blob/main/examples/js-console/example-realm.json
6564
.withRealmImportFile("keycloak_realm_config.json")
@@ -74,14 +73,8 @@ object OIDCKeycloak extends App with CORSHandler with JsonSupport {
7473
val adminClientId = "admin-cli"
7574

7675
def initAdminClient() = {
77-
val keycloakAdminClient = KeycloakBuilder.builder()
78-
.serverUrl(keycloak.getAuthServerUrl)
79-
.realm("master")
80-
.clientId(adminClientId)
81-
.username(keycloak.getAdminUsername)
82-
.password(keycloak.getAdminPassword)
83-
.build()
84-
logger.info("Connected to Keycloak server version: " + keycloakAdminClient.serverInfo().getInfo.getSystemInfo.getVersion)
76+
val keycloakAdminClient = keycloak.getKeycloakAdminClient()
77+
logger.info("Connected to Keycloak server version: {}", keycloakAdminClient.serverInfo().getInfo.getSystemInfo.getVersion)
8578
keycloakAdminClient
8679
}
8780

0 commit comments

Comments
 (0)