Skip to content

Commit a419946

Browse files
authored
Merge pull request #69 from tommaso-borgato/issue-68
[issues-68] - Adding a WildFly Bootable Jar Test that interacts with an external Keycloak service to secure resources with OIDC
2 parents 511c868 + ed1b8d6 commit a419946

11 files changed

+621
-79
lines changed

testsuite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This tests validates an interoperability use case based on a WildFly/JBoss EAP/J
1111
uses the Elytron subsystem to configure an OIDC client for a remote Keycloak/Red Hat Build of Keycloak service,
1212
which is configured to allow OIDC Single-sign-on in order to secure the application resources.
1313

14-
The deployed application descriptor sets the `SSO_APP_SERVICE` environment variable to the URL of the Keycloak service.
14+
The deployed application descriptor sets the `SSO_OIDC_KEYCLOAK_URL` environment variable to the URL of the Keycloak service.
1515

1616
We have two variations of this test:
1717

testsuite/src/test/java/org/jboss/intersmash/tests/wildfly/elytron/oidc/client/keycloak/BasicKeycloakOperatorDynamicClientOidcApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class BasicKeycloakOperatorDynamicClientOidcApplication implements Keyclo
6666
/** Number of Keycloak instances to deploy. */
6767
protected static final long KEYCLOAK_INSTANCES = 1;
6868
/** Shared secret for OIDC client authentication. */
69-
protected static final String OIDC_SECURE_DEPLOYMENT_SECRET = "3up7r37cr7doidccli7ntpa33word";
69+
protected static final String SSO_OIDC_CLIENT_SECRET = "3up7r37cr7doidccli7ntpa33word";
7070

7171
/** The Keycloak instance custom resource. */
7272
protected final Keycloak keycloak;

testsuite/src/test/java/org/jboss/intersmash/tests/wildfly/elytron/oidc/client/keycloak/BasicKeycloakOperatorOidcApplication.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
import org.jboss.intersmash.application.operator.KeycloakOperatorApplication;
2121
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.Clients;
2222
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.ClientsBuilder;
23-
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.Users;
24-
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.UsersBuilder;
25-
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.users.CredentialsBuilder;
2623

2724
/**
2825
* Deploys one basic Keycloak instance with a realm with users and a client.
@@ -41,33 +38,6 @@ public BasicKeycloakOperatorOidcApplication() throws IOException {
4138
super();
4239
}
4340

44-
/**
45-
* Defines users for the Keycloak realm.
46-
*
47-
* @return users for the Keycloak realm
48-
*/
49-
protected Users[] getUsers() {
50-
return new Users[] {
51-
new UsersBuilder()
52-
.withUsername(USER_NAME_WITH_CORRECT_ROLE)
53-
.withEnabled(true)
54-
.withCredentials(new CredentialsBuilder()
55-
.withType("password")
56-
.withValue(USER_PASSWORD_WITH_CORRECT_ROLE)
57-
.build())
58-
.withRealmRoles("user")
59-
.build(),
60-
new UsersBuilder()
61-
.withUsername(USER_NAME_WITH_WRONG_ROLE)
62-
.withEnabled(true)
63-
.withCredentials(new CredentialsBuilder()
64-
.withType("password")
65-
.withValue(USER_PASSWORD_WITH_WRONG_ROLE)
66-
.build())
67-
.withRealmRoles("admin")
68-
.build() };
69-
}
70-
7141
/**
7242
* Return the list of pre-configured OIDC Clients
7343
* @return the list of pre-configured OIDC Clients
@@ -88,7 +58,7 @@ protected Clients getClients() {
8858
String.format("http://%s/", wildflyWithElytronOidcClientRoute))
8959
.withWebOrigins(
9060
String.format("http://%s/", wildflyWithElytronOidcClientRoute))
91-
.withSecret(OIDC_SECURE_DEPLOYMENT_SECRET)
61+
.withSecret(SSO_OIDC_CLIENT_SECRET)
9262
.withFullScopeAllowed(true)
9363
.build();
9464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jboss.intersmash.tests.wildfly.elytron.oidc.client.keycloak;
17+
18+
import java.io.IOException;
19+
import org.jboss.intersmash.application.openshift.OpenShiftApplication;
20+
import org.jboss.intersmash.application.operator.KeycloakOperatorApplication;
21+
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.Clients;
22+
import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.ClientsBuilder;
23+
24+
/**
25+
* Deploys one basic Keycloak instance with a realm with users and a client.
26+
* This can be re-used and extended with other realms and/or clients for different applications.
27+
*/
28+
public class BasicKeycloakOperatorOidcHttpsApplication
29+
extends BasicKeycloakOperatorDynamicClientOidcApplication
30+
implements KeycloakOperatorApplication, OpenShiftApplication {
31+
32+
/** The OIDC client identifier used for authentication with Keycloak. */
33+
public static final String SSO_OIDC_CLIENT_ID = "elytron-oidc-client-id";
34+
35+
/** The OIDC client secret used for authentication with Keycloak. */
36+
public static final String SSO_OIDC_CLIENT_SECRET = "3up7r37cr7doidccli7ntpa33word";
37+
38+
/**
39+
* Creates a new Keycloak instance which is pre-configured with an OIDC Client; that is for cases when we DON'T use
40+
* dynamic client registration.
41+
*
42+
* @throws IOException if an I/O error occurs during certificate generation
43+
*/
44+
public BasicKeycloakOperatorOidcHttpsApplication() throws IOException {
45+
super();
46+
}
47+
48+
/**
49+
* Return the list of pre-configured OIDC Clients
50+
* @return the list of pre-configured OIDC Clients
51+
*/
52+
@Override
53+
protected Clients getClients() {
54+
String route = WildflyBootableJarWithElytronOidcClientApplication.getRoute();
55+
return new ClientsBuilder()
56+
.withClientId(SSO_OIDC_CLIENT_ID)
57+
.withPublicClient(true)
58+
.withStandardFlowEnabled(true)
59+
.withEnabled(true)
60+
.withRootUrl(
61+
String.format("https://%s/", route))
62+
.withRedirectUris(
63+
String.format("https://%s/*", route))
64+
.withAdminUrl(
65+
String.format("https://%s/", route))
66+
.withWebOrigins(
67+
String.format("https://%s/", route))
68+
.withSecret(SSO_OIDC_CLIENT_SECRET)
69+
.withFullScopeAllowed(true)
70+
.build();
71+
}
72+
}

0 commit comments

Comments
 (0)